1#ifndef RITSUKO_CVLS_VALIDATE_HPP
2#define RITSUKO_CVLS_VALIDATE_HPP
40template<
typename Offset_,
typename Length_>
44 }
catch (std::exception& e) {
45 throw std::runtime_error(
"failed to validate the datatype; " + std::string(e.what()));
48 assert(data.getSpace().getSimpleExtentNdims() == 0);
52 data.read(&val, dtype);
55 throw std::runtime_error(
"pointer is out of range of the heap");
84template<
typename Offset_,
typename Length_>
88 }
catch (std::exception& e) {
89 throw std::runtime_error(
"failed to validate the datatype; " + std::string(e.what()));
91 assert(data.getSpace().getSimpleExtentNdims() == 1);
93 const auto& plist = data.getCreatePlist();
94 hsize_t block_size = 0;
95 if (plist.getLayout() == H5D_CHUNKED) {
96 plist.getChunk(1, &block_size);
101 H5::DataSpace mspace(1, &block_size), dspace(1, &full_length);
106 while (i < full_length) {
107 const auto available =
sanisizer::min(full_length - i, block_size);
108 constexpr hsize_t zero = 0;
109 mspace.selectHyperslab(H5S_SELECT_SET, &available, &zero);
110 dspace.selectHyperslab(H5S_SELECT_SET, &available, &i);
112 data.read(buffer.data(), dtype, mspace, dspace);
113 for (I<
decltype(available)> j = 0; j < available; ++j) {
114 const auto& val = buffer[j];
116 throw std::runtime_error(
"pointer at position " +
itoa(i + j) +
" is out of range of the heap");
150template<
typename Offset_,
typename Length_>
154 }
catch (std::exception& e) {
155 throw std::runtime_error(
"failed to validate the datatype; " + std::string(e.what()));
157 assert(data.getSpace().getSimpleExtentNdims() > 0);
160 const auto ndim = dimensions.size();
163 std::vector<hsize_t> chunk_dims;
164 const auto& plist = data.getCreatePlist();
165 if (plist.getLayout() == H5D_CHUNKED) {
166 chunk_dims.resize(ndim);
167 plist.getChunk(ndim, chunk_dims.data());
173 H5::DataSpace fspace(ndim, dimensions.data());
179 const auto& curcount = iter.
counts();
180 const auto& curstart = iter.
starts();
181 mspace.setExtentSimple(ndim, curcount.data());
182 fspace.selectHyperslab(H5S_SELECT_SET, curcount.data(), curstart.data());
184 data.read(buffer.data(), dtype, mspace, fspace);
185 const auto available = mspace.getSimpleExtentNpoints();
186 for (I<
decltype(available)> i = 0; i < available; ++i) {
187 const auto& val = buffer[i];
189 auto posstr = hdf5::emit_coordinates_as_string(i, available, curstart, curcount);
190 throw std::runtime_error(
"pointer at position " + posstr +
" is out of range of the heap");
206 if (data.getTypeClass() != H5T_INTEGER) {
207 throw std::runtime_error(
"expected an integer datatype");
210 throw std::runtime_error(
"expected 8-bit unsigned integers");
212 auto dspace = data.getSpace();
213 if (dspace.getSimpleExtentNdims() != 1) {
214 throw std::runtime_error(
"expected a 1-dimensional dataset");
217 dspace.getSimpleExtentDims(&len);
Iterate through a dataspace by chunk.
Compound datatype of the compresed VLS heap pointer.
Convert an integer to a string.
Mock chunk sizes for a contiguous HDF5 dataset.
void validate_nd_pointers(const H5::DataSet &data, const std::vector< hsize_t > &dimensions, hsize_t heap_length, const ValidateNdPointersOptions &options)
Definition validate.hpp:151
void validate_pointer_datatype(const H5::CompType &type, const std::size_t offset_precision, const std::size_t length_precision)
Definition Pointer.hpp:89
void validate_scalar_pointer(const H5::DataSet &data, hsize_t heap_length)
Definition validate.hpp:41
void validate_1d_pointers(const H5::DataSet &data, hsize_t full_length, hsize_t heap_length, const Validate1dPointersOptions &options)
Definition validate.hpp:85
H5::CompType define_pointer_datatype()
Definition Pointer.hpp:70
bool is_Pointer_out_of_range(const Pointer< Offset_, Length_ > &ptr, const hsize_t heap_length)
Definition Pointer.hpp:142
hsize_t validate_heap(const H5::DataSet &data)
Definition validate.hpp:205
std::vector< hsize_t > mock_contiguous_chunks(const std::vector< hsize_t > &dimensions, hsize_t chunk_size)
Definition mock_contiguous_chunks.hpp:30
bool exceeds_integer_limit(const H5::IntType &itype, std::size_t precision, bool is_signed)
Definition exceeds_limit.hpp:28
Helper functions for ArtifactDB parsing and validation.
Definition Pointer.hpp:22
void itoa(Integer_ x, std::string &output)
Definition itoa.hpp:26
Container_ create(Value_ x, Args_ &&... args)
constexpr bool is_equal(Left_ left, Right_ right)
constexpr auto min(First_ first, Second_ second)
constexpr Dest_ cap(Value_ x)
Pointer into the compressed VLS heap.
Definition Pointer.hpp:36
Options for validate_1d_pointers().
Definition validate.hpp:62
hsize_t contiguous_chunk_size
Definition validate.hpp:67
Options for validate_nd_pointers().
Definition validate.hpp:127
hsize_t contiguous_chunk_size
Definition validate.hpp:132
Iterate through an high-dimensional dataspace by chunk.
Definition IterateChunks.hpp:29
const std::vector< hsize_t > & chunk_dimensions() const
Definition IterateChunks.hpp:123
bool advance()
Definition IterateChunks.hpp:67
const std::vector< hsize_t > & starts() const
Definition IterateChunks.hpp:96
const std::vector< hsize_t > & counts() const
Definition IterateChunks.hpp:107