14 #ifndef QMCPLUSPLUS_HDF_STL_INTERFACE_H 15 #define QMCPLUSPLUS_HDF_STL_INTERFACE_H 37 inline bool read(
data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
44 inline bool write(
const data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
const 51 const std::string& aname,
52 const std::vector<hsize_t>& dvec,
53 hid_t xfer_plist)
const 55 return h5d_write(grp, aname.c_str(), dvec.size(), dvec.data(),
get_address(&ref[0]), xfer_plist);
73 inline bool read(
data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
75 std::vector<char> temp_char_vec;
77 temp_char_vec.resize(
dims[0]);
80 std::transform(temp_char_vec.begin(), temp_char_vec.end(), ref.begin(), [](
auto& cval) {
return cval > 0; });
84 inline bool write(
const data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
const 86 std::vector<char> temp_char_vec(ref.size());
87 std::transform(ref.begin(), ref.end(), temp_char_vec.begin(), [](
bool bval) {
return bval ? 1 : 0; });
93 const std::string& aname,
94 const std::vector<hsize_t>& dvec,
95 hid_t xfer_plist)
const 97 std::vector<char> temp_char_vec(ref.size());
98 std::transform(ref.begin(), ref.end(), temp_char_vec.begin(), [](
bool bval) {
return bval ? 1 : 0; });
99 return h5d_write(grp, aname.c_str(), dvec.size(), dvec.data(),
get_address(temp_char_vec.data()), xfer_plist);
105 template<std::
size_t N>
112 inline bool read(
data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
114 unsigned long c = ref.to_ulong();
116 if (hc.
read(ref, grp, aname, xfer_plist))
125 inline bool write(
const data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
const 127 unsigned long c = ref.to_ulong();
129 return hc.
write(ref, grp, aname, xfer_plist);
142 inline bool read(
data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
144 hid_t dataset = H5Dopen(grp, aname.c_str(), H5P_DEFAULT);
147 hid_t datatype = H5Dget_type(dataset);
149 if (datatype == H5T_NATIVE_CHAR)
151 hid_t dataspace = H5Dget_space(dataset);
152 hid_t status = H5Sget_simple_extent_dims(dataspace, &dim_out, NULL);
157 dim_out = H5Tget_size(datatype);
160 herr_t ret = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, xfer_plist, &(ref[0]));
168 inline bool write(
const data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
const 170 hid_t str80 = H5Tcopy(H5T_C_S1);
171 H5Tset_size(str80, ref.size());
175 hid_t h1 = H5Dopen(grp, aname.c_str(), H5P_DEFAULT);
178 hid_t dataspace = H5Screate_simple(1, &dim, NULL);
179 hid_t dataset = H5Dcreate(grp, aname.c_str(), str80, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
180 ret = H5Dwrite(dataset, str80, H5S_ALL, H5S_ALL, xfer_plist, ref.data());
186 ret = H5Dwrite(h1, str80, H5S_ALL, H5S_ALL, xfer_plist, ref.data());
201 inline bool read(
data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
203 hid_t datatype = H5Tcopy(H5T_C_S1);
204 H5Tset_size(datatype, H5T_VARIABLE);
205 hid_t dataset = H5Dopen(grp, aname.c_str(), H5P_DEFAULT);
206 std::vector<char*> char_list;
211 hid_t dataspace = H5Dget_space(dataset);
212 hid_t status = H5Sget_simple_extent_dims(dataspace, &dim_out, NULL);
214 char_list.resize(dim_out);
215 ret = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, xfer_plist, char_list.data());
217 for (
int i = 0; i < dim_out; i++)
218 ref.push_back(char_list[i]);
220 H5Dvlen_reclaim(datatype, dataspace, xfer_plist, char_list.data());
230 inline bool write(
const data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
const 237 hid_t datatype = H5Tcopy(H5T_C_S1);
238 H5Tset_size(datatype, H5T_VARIABLE);
239 hsize_t dim = ref.size();
242 std::vector<const char*> char_list;
243 for (
int i = 0; i < ref.size(); i++)
244 char_list.push_back(ref[i].data());
246 hid_t h1 = H5Dopen(grp, aname.c_str(), H5P_DEFAULT);
250 hid_t dataspace = H5Screate_simple(1, &dim, NULL);
251 hid_t dataset = H5Dcreate(grp, aname.c_str(), datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
252 ret = H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, xfer_plist, char_list.data());
257 ret = H5Dwrite(h1, datatype, H5S_ALL, H5S_ALL, xfer_plist, char_list.data());
271 inline bool read(
data_type& ref, hid_t grp,
char* name, hid_t xfer_plist = H5P_DEFAULT) {
return false; }
273 inline bool write(
const data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
const 275 std::string
clone(ref.str());
277 return proxy.write(
clone, grp, aname);
std::bitset< N > data_type
std::vector< bool > data_type
default struct to define a h5 dataspace, any intrinsic type T
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
helper functions for EinsplineSetBuilder
bool write(const data_type &ref, hid_t grp, const std::string &aname, const std::vector< hsize_t > &dvec, hid_t xfer_plist) const
bool write(const data_type &ref, hid_t grp, const std::string &aname, const std::vector< hsize_t > &dvec, hid_t xfer_plist) const
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
h5data_proxy(const data_type &a)
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
h5data_proxy(const data_type &a)
h5data_proxy(const data_type &a)
Specialization for std::string.
std::vector< std::string > data_type
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
hsize_t dims[RANK > 0 ? RANK :1]
shape of the dataspace, protected for zero size array, hdf5 support scalar as rank = 0 ...
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
h5data_proxy(const data_type &a)
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
h5data_proxy(const data_type &a)
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
h5data_proxy(const data_type &a)
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
static auto get_address(T *a)
return the address
bool read(data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT)
std::ostringstream data_type
std::vector< T > data_type
static constexpr hsize_t rank
rank of the multidimensional dataspace
bool h5d_read(hid_t grp, const std::string &aname, T *first, hid_t xfer_plist)
return true, if successful
bool write(const data_type &ref, hid_t grp, const std::string &aname, hid_t xfer_plist=H5P_DEFAULT) const
bool read(data_type &ref, hid_t grp, char *name, hid_t xfer_plist=H5P_DEFAULT)
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 ...