13 #ifndef QMCPLUSPLUS_HDF_HYPERSLAB_IO_H 14 #define QMCPLUSPLUS_HDF_HYPERSLAB_IO_H 34 template<
typename CT,
unsigned RANK>
67 const std::array<IT, RANK>& dims_in,
68 const std::array<IT, RANK>& selected_in,
69 const std::array<IT, RANK>& offsets_in)
72 static_assert(std::is_unsigned<IT>::value,
"only accept unsigned integer types like size_t");
77 slab_offset[i] =
static_cast<hsize_t
>(offsets_in[i]);
95 throw std::runtime_error(
"Zero size detected in some dimensions of filespace\n");
97 throw std::runtime_error(
"Zero size detected in some dimensions of selected filespace\n");
101 throw std::runtime_error(
"offset outsdie the bound of filespace");
104 std::ostringstream err_msg;
105 err_msg <<
"dim " << dim <<
" offset " <<
slab_offset[dim] <<
" + selected_space size " 107 throw std::runtime_error(err_msg.str());
116 hsize_t total_size =
slab_rank > 0 ? 1 : 0;
117 for (
int dim = 0; dim <
slab_rank; dim++)
129 template<
typename IT>
134 throw std::runtime_error(
"User specified and filespace dimensions mismatch!\n");
136 for (
int dim = 0; dim <
slab_rank; dim++)
142 std::ostringstream err_msg;
143 err_msg <<
"dim " << dim <<
" user specified size " <<
file_space.
dims[dim] <<
" filespace size " 144 << sizes_file[dim] <<
" mismatched!" << std::endl;
145 throw std::runtime_error(err_msg.str());
154 template<
typename CT,
unsigned RANK>
161 inline bool read(
data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
163 std::vector<hsize_t> sizes_file;
164 getDataShape<typename data_type::element_type>(grp, aname, sizes_file);
175 inline bool write(
const data_type& ref, hid_t grp,
const std::string& aname, hid_t xfer_plist = H5P_DEFAULT)
const 179 throw std::runtime_error(
"Not large enough container capacity!\n");
define h5_space_type to handle basic datatype for hdf5
helper functions for EinsplineSetBuilder
void checkUserRankSizes() const
checks if file_space, elected_space and offset are self-consistent
class to use file space hyperslab with a serialized container
bool checkContainerCapacity() const
check if the container is large enough for the selected space and resize if requested ...
typename container_traits< CT >::element_type element_type
std::array< hsize_t, SpaceType::rank > slab_offset
offset of the hyperslab
typename CT::value_type element_type
the data type of elements
void adaptShape(const std::vector< IT > &sizes_file)
adjust file_space and selected_space shapes based on sizes_file
hsize_t dims[RANK > 0 ? RANK :1]
shape of the dataspace, protected for zero size array, hdf5 support scalar as rank = 0 ...
h5data_proxy(const data_type &a)
hyperslab_proxy(CT &a, const std::array< IT, RANK > &dims_in, const std::array< IT, RANK > &selected_in, const std::array< IT, RANK > &offsets_in)
constructor
CT & ref_
container reference
static auto get_address(element_type *a)
return the address
SpaceType selected_space
local dimension of the hyperslab
SpaceType file_space
global dimension of the hyperslab
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 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 h5d_write(hid_t grp, const std::string &aname, hsize_t ndims, const hsize_t *dims, const T *first, hid_t xfer_plist)
static const unsigned int slab_rank
user rank of a hyperslab
generic h5data_proxy<T> for scalar basic datatypes defined in hdf_dataspace.h Note if the dataset to ...
hsize_t size(int i) const
return the size of the i-th dimension of global space