1#ifndef RITSUKO_CVLS_VALIDATE_HPP
2#define RITSUKO_CVLS_VALIDATE_HPP
11#include "sanisizer/sanisizer.hpp"
40template<
typename Offset_,
typename Length_>
43 assert(data.getSpace().getSimpleExtentNdims() == 0);
47 data.read(&val, dtype);
50 throw std::runtime_error(
"compressed VLS array pointer at '" +
hdf5::get_name(data) +
"' is out of range of the heap");
67template<
typename Offset_,
typename Length_>
70 assert(data.getSpace().getSimpleExtentNdims() == 1);
72 const auto& plist = data.getCreatePlist();
73 hsize_t block_size = 0;
74 if (plist.getLayout() == H5D_CHUNKED) {
75 plist.getChunk(1, &block_size);
79 block_size = sanisizer::min(full_length, 10000);
82 H5::DataSpace mspace(1, &block_size), dspace(1, &full_length);
83 auto buffer = sanisizer::create<std::vector<Pointer<Offset_, Length_> > >(block_size);
87 while (i < full_length) {
88 const auto available = sanisizer::min(full_length - i, block_size);
89 constexpr hsize_t zero = 0;
90 mspace.selectHyperslab(H5S_SELECT_SET, &available, &zero);
91 dspace.selectHyperslab(H5S_SELECT_SET, &available, &i);
93 data.read(buffer.data(), dtype, mspace, dspace);
94 for (I<
decltype(available)> j = 0; j < available; ++j) {
95 const auto& val = buffer[j];
97 throw std::runtime_error(
"compressed VLS array pointers at '" +
hdf5::get_name(data) +
"' are out of range of the heap");
119template<
typename Offset_,
typename Length_>
120void validate_nd_pointers(
const H5::DataSet& data,
const std::vector<hsize_t>& dimensions, hsize_t heap_length) {
122 assert(data.getSpace().getSimpleExtentNdims() > 0);
125 const auto ndim = dimensions.size();
126 assert(sanisizer::is_equal(ndim, data.getSpace().getSimpleExtentNdims()));
128 std::vector<hsize_t> chunk_dims;
129 const auto& plist = data.getCreatePlist();
130 if (plist.getLayout() == H5D_CHUNKED) {
131 chunk_dims.resize(ndim);
132 plist.getChunk(ndim, chunk_dims.data());
138 H5::DataSpace fspace(ndim, dimensions.data());
140 auto buffer = sanisizer::create<std::vector<Pointer<Offset_, Length_> > >(mspace.getSimpleExtentNpoints());
144 const auto& curcount = iter.
counts();
145 mspace.setExtentSimple(ndim, curcount.data());
146 fspace.selectHyperslab(H5S_SELECT_SET, curcount.data(), iter.
starts().data());
148 data.read(buffer.data(), dtype, mspace, fspace);
149 const auto available = mspace.getSimpleExtentNpoints();
150 for (I<
decltype(available)> i = 0; i < available; ++i) {
151 const auto& val = buffer[i];
153 throw std::runtime_error(
"compressed VLS array pointers at '" +
hdf5::get_name(data) +
"' are out of range of the heap");
167 if (data.getTypeClass() != H5T_INTEGER) {
168 throw std::runtime_error(
"expected an integer datatype for the compressed VLS heap at '" +
hdf5::get_name(data) +
"'");
171 throw std::runtime_error(
"expected 8-bit unsigned integers for the compressed VLS heap at '" +
hdf5::get_name(data) +
"'");
173 if (data.getSpace().getSimpleExtentNdims() != 1) {
174 throw std::runtime_error(
"expected a 1-dimensional dataset for the compressed VLS heap at '" +
hdf5::get_name(data) +
"'");
Iterate through a dataspace by chunk.
Compound datatype of the compresed VLS heap pointer.
Get the name of a HDF5 object.
Mock chunk sizes for a contiguous HDF5 dataset.
void validate_1d_pointers(const H5::DataSet &data, hsize_t full_length, hsize_t heap_length)
Definition validate.hpp:68
void validate_pointer_datatype(const H5::CompType &type, const std::size_t offset_precision, const std::size_t length_precision)
Definition Pointer.hpp:88
void validate_nd_pointers(const H5::DataSet &data, const std::vector< hsize_t > &dimensions, hsize_t heap_length)
Definition validate.hpp:120
void validate_scalar_pointer(const H5::DataSet &data, hsize_t heap_length)
Definition validate.hpp:41
H5::CompType define_pointer_datatype()
Definition Pointer.hpp:69
void validate_heap(const H5::DataSet &data)
Definition validate.hpp:166
bool is_Pointer_out_of_range(const Pointer< Offset_, Length_ > &ptr, const hsize_t heap_length)
Definition Pointer.hpp:148
std::vector< hsize_t > mock_contiguous_chunks(const std::vector< hsize_t > &dimensions, hsize_t chunk_size)
Definition mock_contiguous_chunks.hpp:30
std::string get_name(const Object_ &obj)
Definition get_name.hpp:29
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:21
Pointer into the compressed VLS heap.
Definition Pointer.hpp:35
Iterate through an high-dimensional dataspace by chunk.
Definition IterateChunks.hpp:28
const std::vector< hsize_t > & chunk_dimensions() const
Definition IterateChunks.hpp:122
bool advance()
Definition IterateChunks.hpp:66
const std::vector< hsize_t > & starts() const
Definition IterateChunks.hpp:95
const std::vector< hsize_t > & counts() const
Definition IterateChunks.hpp:106