QMCPACK
hdf_dataproxy.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2019 QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
9 // Luke Shulenburger, lshulen@sandia.gov, Sandia National Laboratories
10 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 #ifndef QMCPLUSPLUS_HDF_H5_DATAPROXY_H
17 #define QMCPLUSPLUS_HDF_H5_DATAPROXY_H
18 
19 #include "hdf_wrapper_functions.h"
20 #include "hdf_dataspace.h"
21 
22 namespace qmcplusplus
23 {
24 
25 /** generic h5data_proxy<T> for scalar basic datatypes defined in hdf_dataspace.h
26  * Note if the dataset to be written has const specifier, T should not carry const.
27  */
28 template<typename T>
29 struct h5data_proxy : public h5_space_type<T, 0>
30 {
31  using data_type = T;
33  using FileSpace::dims;
35 
36  inline h5data_proxy(const data_type& a) {}
37 
38  inline bool read(data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
39  {
40  return h5d_read(grp, aname, get_address(&ref), xfer_plist);
41  }
42 
43  inline bool check_existence(hid_t grp, const std::string& aname) { return h5d_check_existence(grp, aname); }
44 
45  inline bool check_type(hid_t grp, const std::string& aname) { return h5d_check_type<data_type>(grp, aname); }
46 
47  inline bool write(const data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT) const
48  {
49  return h5d_write(grp, aname.c_str(), FileSpace::rank, dims, get_address(&ref), xfer_plist);
50  }
51 };
52 
53 /** specialization for bool, convert to int
54  */
55 template<>
56 struct h5data_proxy<bool> : public h5_space_type<int, 0>
57 {
58  using data_type = bool;
60  using FileSpace::dims;
62 
63  inline h5data_proxy(const data_type& a) {}
64 
65  inline bool read(data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
66  {
67  int copy = static_cast<int>(ref);
68  bool okay = h5d_read(grp, aname, get_address(&copy), xfer_plist);
69  ref = static_cast<bool>(copy);
70  return okay;
71  }
72 
73  inline bool write(const data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT) const
74  {
75  int copy = static_cast<int>(ref);
76  return h5d_write(grp, aname.c_str(), FileSpace::rank, dims, get_address(&copy), xfer_plist);
77  }
78 };
79 
80 } // namespace qmcplusplus
81 #endif
define h5_space_type to handle basic datatype for hdf5
default struct to define a h5 dataspace, any intrinsic type T
Definition: hdf_dataspace.h:44
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
Definition: hdf_dataproxy.h:73
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
Definition: hdf_dataproxy.h:47
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
hsize_t dims[RANK > 0 ? RANK :1]
shape of the dataspace, protected for zero size array, hdf5 support scalar as rank = 0 ...
Definition: hdf_dataspace.h:47
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
Definition: hdf_dataproxy.h:65
bool check_type(hid_t grp, const std::string &aname)
Definition: hdf_dataproxy.h:45
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
Definition: hdf_dataproxy.h:38
free template functions wrapping HDF5 calls.
static auto get_address(T *a)
return the address
Definition: hdf_dataspace.h:53
h5data_proxy(const data_type &a)
Definition: hdf_dataproxy.h:63
bool check_existence(hid_t grp, const std::string &aname)
Definition: hdf_dataproxy.h:43
static constexpr hsize_t rank
rank of the multidimensional dataspace
Definition: hdf_dataspace.h:49
h5data_proxy(const data_type &a)
Definition: hdf_dataproxy.h:36
bool h5d_check_existence(hid_t grp, const std::string &aname)
bool h5d_read(hid_t grp, const std::string &aname, T *first, hid_t xfer_plist)
return true, if successful
bool h5d_write(hid_t grp, const std::string &aname, hsize_t ndims, const hsize_t *dims, const T *first, hid_t xfer_plist)
generic h5data_proxy<T> for scalar basic datatypes defined in hdf_dataspace.h Note if the dataset to ...
Definition: hdf_dataproxy.h:29