QMCPACK
hdf_pete.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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_HDF_PETE_TRAITS_H
14 #define QMCPLUSPLUS_HDF_PETE_TRAITS_H
15 
16 #include "hdf_dataproxy.h"
17 #include "OhmmsPETE/OhmmsVector.h"
18 #include "OhmmsPETE/OhmmsMatrix.h"
19 #include "OhmmsPETE/OhmmsArray.h"
20 
21 namespace qmcplusplus
22 {
23 /** specialization for Vector<T>
24  *
25  * Used with any T with a proper h5_space_type, e.g., intrinsic, TinyVector<T,D>, Tensor<T,D>
26  */
27 template<typename T>
28 struct h5data_proxy<Vector<T>> : public h5_space_type<T, 1>
29 {
31  using FileSpace::dims;
34 
35  inline h5data_proxy(const data_type& a) { dims[0] = a.size(); }
36 
37  inline bool read(data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
38  {
39  if (!checkShapeConsistency<T>(grp, aname, FileSpace::rank, dims))
40  ref.resize(dims[0]);
41  return h5d_read(grp, aname, get_address(ref.data()), xfer_plist);
42  }
43 
44  inline bool write(const data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT) const
45  {
46  return h5d_write(grp, aname.c_str(), FileSpace::rank, dims, get_address(ref.data()), xfer_plist);
47  }
48 };
49 
50 
51 template<typename T>
52 struct h5data_proxy<Matrix<T>> : public h5_space_type<T, 2>
53 {
55  using FileSpace::dims;
58 
59  inline h5data_proxy(const data_type& a)
60  {
61  dims[0] = a.rows();
62  dims[1] = a.cols();
63  }
64 
65  inline bool read(data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
66  {
67  if (!checkShapeConsistency<T>(grp, aname, FileSpace::rank, dims))
68  ref.resize(dims[0], dims[1]);
69  return h5d_read(grp, aname, get_address(ref.data()), xfer_plist);
70  }
71 
72  inline bool write(const data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT) const
73  {
74  return h5d_write(grp, aname.c_str(), FileSpace::rank, dims, get_address(ref.data()), xfer_plist);
75  }
76 };
77 
78 
79 template<typename T, unsigned D>
80 struct h5data_proxy<Array<T, D>> : public h5_space_type<T, D>
81 {
83  using FileSpace::dims;
86 
87  inline h5data_proxy(const data_type& a)
88  {
89  for (int i = 0; i < D; ++i)
90  dims[i] = a.size(i);
91  }
92 
93  inline bool read(data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
94  {
95  if (!checkShapeConsistency<T>(grp, aname, FileSpace::rank, dims))
96  {
97  std::array<size_t, D> dims_array;
98  std::copy(std::cbegin(dims), std::cend(dims), dims_array.begin());
99  ref.resize(dims_array);
100  }
101  return h5d_read(grp, aname, get_address(ref.data()), xfer_plist);
102  }
103 
104  inline bool write(const data_type& ref, hid_t grp, const std::string& aname, hid_t xfer_plist = H5P_DEFAULT) const
105  {
106  return h5d_write(grp, aname.c_str(), FileSpace::rank, dims, get_address(ref.data()), xfer_plist);
107  }
108 };
109 
110 } // namespace qmcplusplus
111 #endif
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
Definition: hdf_pete.h:93
default struct to define a h5 dataspace, any intrinsic type T
Definition: hdf_dataspace.h:44
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Type_t * data()
Definition: OhmmsArray.h:87
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
size_type cols() const
Definition: OhmmsMatrix.h:78
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
size_type size() const
return the current size
Definition: OhmmsVector.h:162
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_pete.h:65
size_t size() const
Definition: OhmmsArray.h:57
size_type rows() const
Definition: OhmmsMatrix.h:77
static auto get_address(T *a)
return the address
Definition: hdf_dataspace.h:53
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
Definition: hdf_pete.h:44
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
Definition: hdf_pete.h:72
static constexpr hsize_t rank
rank of the multidimensional dataspace
Definition: hdf_dataspace.h:49
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
Definition: hdf_pete.h:37
bool h5d_read(hid_t grp, const std::string &aname, T *first, hid_t xfer_plist)
return true, if successful
A D-dimensional Array class based on PETE.
Definition: OhmmsArray.h:25
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
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
Definition: hdf_pete.h:104