14 #ifndef QMCPLUSPLUS_HDF5_ARCHIVE_H 15 #define QMCPLUSPLUS_HDF5_ARCHIVE_H 101 template<
class Comm = Communicate*>
106 throw std::runtime_error(
"HDF5 library warnings and errors not suppressed from output.\n");
113 throw std::runtime_error(
"HDF5 library warnings and errors not suppressed from output.\n");
133 bool create(
const std::filesystem::path& fname,
unsigned flags = H5F_ACC_TRUNC);
140 bool open(
const std::filesystem::path& fname,
unsigned flags = H5F_ACC_RDWR);
149 H5Fflush(
file_id, H5F_SCOPE_LOCAL);
159 bool is_group(
const std::string& aname);
172 return e.check_existence(p, aname);
187 return e.check_type(p, aname);
204 void push(
const std::string& gname,
bool createit =
true);
215 herr_t err = H5Gclose(g);
217 throw std::runtime_error(
"H5Gclose failed with error.");
231 bool getShape(
const std::string& aname, std::vector<int>& sizes_out)
236 return getDataShape<T>(p, aname, sizes_out);
249 throw std::runtime_error(
"Only write data in parallel or by master but not every rank!");
259 void write(T& data,
const std::string& aname)
263 throw std::runtime_error(
"HDF5 write failure in hdf_archive::write " + aname);
273 template<
typename T,
typename IT, std::
size_t RANK>
276 std::array<hsize_t, RANK> globals, counts, offsets;
277 for (
int dim = 0; dim < RANK; dim++)
279 globals[dim] =
static_cast<hsize_t
>(shape[dim]);
280 counts[dim] =
static_cast<hsize_t
>(shape[dim]);
292 template<typename T, typename = std::enable_if_t<!std::is_const<T>::value>>
305 template<typename T, typename = std::enable_if_t<!std::is_const<T>::value>>
306 void read(T& data,
const std::string& aname)
310 throw std::runtime_error(
"HDF5 read failure in hdf_archive::read " + aname);
320 template<typename T, typename IT, std::size_t RANK, typename = std::enable_if_t<!std::is_const<T>::value>>
321 void readSlabReshaped(T& data,
const std::array<IT, RANK>& shape,
const std::string& aname)
323 std::array<hsize_t, RANK> globals, counts, offsets;
324 for (
int dim = 0; dim < RANK; dim++)
326 globals[dim] =
static_cast<hsize_t
>(shape[dim]);
327 counts[dim] =
static_cast<hsize_t
>(shape[dim]);
344 template<typename T, typename IT, std::size_t RANK, typename = std::enable_if_t<!std::is_const<T>::value>>
347 std::array<hsize_t, RANK> globals, counts, offsets;
348 for (
int dim = 0; dim < RANK; dim++)
351 if (readSpec[dim] < 0)
359 offsets[dim] =
static_cast<hsize_t
>(readSpec[dim]);
367 inline void unlink(
const std::string& aname)
372 herr_t status = H5Ldelete(p, aname.c_str(), H5P_DEFAULT);
define h5_space_type to handle basic datatype for hdf5
bool closed()
return true if the file is closed
void write(T &data, const std::string &aname)
write the data to the group aname and check status runtime error is issued on I/O error ...
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
helper functions for EinsplineSetBuilder
hid_t top() const
return the top of the group stack
hid_t getFileID() const
return file_id. should be only be used for connecting to old codes when porting
bool open_groups()
check if any groups are open group stack will have entries if so
hid_t lcpl_id
Link creation property list identifier.
class to use file space hyperslab with a serialized container
void unlink(const std::string &aname)
void close()
close all the open groups and file
bool is_master() const
return true if master in parallel i/o
std::stack< hid_t > group_id
FILO to handle H5Group.
std::string possible_filename_
Name of file that hdf_archive thinks is open.
void readSlabReshaped(T &data, const std::array< IT, RANK > &shape, const std::string &aname)
read file dataset with a specific shape into a container and check status
std::bitset< 4 > Mode
bitset of the io mode Mode[IS_PARALLEL] : true, if parallel Mode[IS_MASTER] : true, if the node is master Mode[NOIO] : true, if I/O is not performed
bool is_dataset_of_type(const std::string &aname)
check if aname is a dataset of type T
bool is_parallel() const
return true if parallel i/o
Wrapping information on parallelism.
void readSlabSelection(T &data, const std::array< IT, RANK > &readSpec, const std::string &aname)
read a portion of the data from the group aname and check status runtime error is issued on I/O error...
hdf_archive(Comm c, bool request_pio=false)
constructor
bool getShape(const std::string &aname, std::vector< int > &sizes_out)
read the shape of multidimensional filespace from the group aname this function can be used to query ...
void writeSlabReshaped(T &data, const std::array< IT, RANK > &shape, const std::string &aname)
write the container data with a specific shape and check status
hdf_error_suppression hide_hdf_errors
Suppress HDF5 warning and error messages.
bool is_dataset(const std::string &aname)
check if aname is a dataset
static const hid_t is_closed
void push(const std::string &gname, bool createit=true)
push a group to the group stack
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
std::string group_path_as_string() const
Return a string representation of the current group stack.
hid_t xfer_plist
transfer property
bool is_group(const std::string &aname)
check if aname is a group
void read(T &data, const std::string &aname)
read the data from the group aname and check status runtime error is issued on I/O error ...
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
static bool enabled
status of hdf_error_suppression. An instance of this class changes enabled to true.
std::vector< std::string > group_names
Track group names corresponding to group_id.
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
generic h5data_proxy<T> for scalar basic datatypes defined in hdf_dataspace.h Note if the dataset to ...