ritsuko
Helper utilities for ArtifactDB C++ code
Loading...
Searching...
No Matches
pick_nd_block_dimensions.hpp
Go to the documentation of this file.
1#ifndef RITSUKO_PICK_ND_BLOCK_DIMENSIONS_HPP
2#define RITSUKO_PICK_ND_BLOCK_DIMENSIONS_HPP
3
4#include "H5Cpp.h"
5
11namespace ritsuko {
12
13namespace hdf5 {
14
26inline std::vector<hsize_t> pick_nd_block_dimensions(const H5::DSetCreatPropList& cplist, const std::vector<hsize_t>& dimensions, hsize_t buffer_size = 10000) {
27 size_t ndims = dimensions.size();
28 std::vector<hsize_t> chunk_extent(ndims, 1);
29 if (cplist.getLayout() == H5D_CHUNKED) {
30 cplist.getChunk(chunk_extent.size(), chunk_extent.data());
31 }
32
33 // Scaling up the block size as much as possible. We start from the
34 // fastest-changing dimension (i.e., the last one in HDF5) and increase it,
35 // and then we move onto the next-fastest dimension, and so on until the
36 // buffer size is exhausted.
37 auto block_extent = chunk_extent;
38 hsize_t block_size = 1;
39 for (hsize_t d = 0; d < ndims; ++d) {
40 block_extent[d] = std::min(block_extent[d], dimensions[d]); // should be a no-op, but we do this just in case.
41 block_size *= block_extent[d];
42 }
43
44 if (block_size) {
45 for (hsize_t i = ndims; i > 0; --i) {
46 int multiple = buffer_size / block_size;
47 if (multiple <= 1) {
48 break;
49 }
50 auto d = i - 1;
51 block_size /= block_extent[d];
52 block_extent[d] = std::min(dimensions[d], block_extent[d] * multiple);
53 block_size *= block_extent[d];
54 }
55 } else {
56 std::fill(block_extent.begin(), block_extent.end(), 0);
57 }
58
59 return block_extent;
60}
61
62}
63
64}
65
66#endif
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