1#ifndef RITSUKO_HDF5_VLS_VALIDATE_HPP
2#define RITSUKO_HDF5_VLS_VALIDATE_HPP
36template<
typename Offset_,
typename Length_>
37inline void validate_1d_array(
const H5::DataSet& handle, hsize_t full_length, hsize_t heap_length, hsize_t buffer_size) {
38 hsize_t block_size =
pick_1d_block_size(handle.getCreatePlist(), full_length, buffer_size);
39 H5::DataSpace mspace(1, &block_size), dspace(1, &full_length);
40 std::vector<Pointer<Offset_, Length_> > buffer(block_size);
43 for (hsize_t i = 0; i < full_length; i += block_size) {
44 auto available = std::min(full_length - i, block_size);
45 constexpr hsize_t zero = 0;
46 mspace.selectHyperslab(H5S_SELECT_SET, &available, &zero);
47 dspace.selectHyperslab(H5S_SELECT_SET, &available, &i);
49 handle.read(buffer.data(), dtype, mspace, dspace);
50 for (hsize_t j = 0; j < available; ++j) {
51 const auto& val = buffer[j];
52 hsize_t start = val.offset;
53 hsize_t count = val.length;
54 if (start > heap_length || start + count > heap_length) {
55 throw std::runtime_error(
"VLS array pointers at '" +
get_name(handle) +
"' are out of range of the heap");
70template<
typename Offset_,
typename Length_>
71void validate_nd_array(
const H5::DataSet& handle,
const std::vector<hsize_t>& dimensions, hsize_t heap_length, hsize_t buffer_size) {
72 std::vector<Pointer<Offset_, Length_> > buffer;
84 handle.read(buffer.data(), dtype, mspace, iter.
file_space());
85 for (
const auto& val : buffer) {
86 hsize_t start = val.offset;
87 hsize_t count = val.length;
88 if (start > heap_length || start + count > heap_length) {
89 throw std::runtime_error(
"VLS array pointers at '" +
get_name(handle) +
"' are out of range of the heap");
Iterate through an N-dimensional dataset by block.
Compound datatype for the VLS heap pointer.
Get the name of a HDF5 object.
void validate_1d_array(const H5::DataSet &handle, hsize_t full_length, hsize_t heap_length, hsize_t buffer_size)
Definition validate.hpp:37
void validate_nd_array(const H5::DataSet &handle, const std::vector< hsize_t > &dimensions, hsize_t heap_length, hsize_t buffer_size)
Definition validate.hpp:71
H5::CompType define_pointer_datatype()
Definition Pointer.hpp:60
std::string get_name(const Handle_ &handle)
Definition get_name.hpp:24
hsize_t pick_1d_block_size(const H5::DSetCreatPropList &cplist, hsize_t full_length, hsize_t buffer_size=10000)
Definition pick_1d_block_size.hpp:26
std::vector< hsize_t > pick_nd_block_dimensions(const H5::DSetCreatPropList &cplist, const std::vector< hsize_t > &dimensions, hsize_t buffer_size=10000)
Definition pick_nd_block_dimensions.hpp:26
Assorted helper functions for parsing and validation.
Definition choose_missing_placeholder.hpp:15
Pick a block size for a 1-dimensional HDF5 dataset.
Pick block dimensions for an N-dimensional HDF5 dataset.
Iterate through an N-dimensional dataset by block.
Definition IterateNdDataset.hpp:25
const H5::DataSpace & memory_space() const
Definition IterateNdDataset.hpp:132
bool finished() const
Definition IterateNdDataset.hpp:92
const H5::DataSpace & file_space() const
Definition IterateNdDataset.hpp:124
size_t current_block_size() const
Definition IterateNdDataset.hpp:101
void next()
Definition IterateNdDataset.hpp:55