1 #ifndef artdaq_demo_hdf5_HDF5_highFive_highFiveDatasetHelper_hh
2 #define artdaq_demo_hdf5_HDF5_highFive_highFiveDatasetHelper_hh 1
4 #include "artdaq-demo-hdf5/HDF5/highFive/HighFive/include/highfive/H5DataSet.hpp"
25 , current_size_(dataset.getDimensions()[0])
26 , chunk_size_(chunk_size)
42 if (current_row_ >= current_size_) resize();
44 dataset_.select({current_row_, 0}, {1, 1}).
write(data);
54 void write(T
const& data,
size_t width)
56 if (current_row_ >= current_size_) resize();
58 dataset_.select({current_row_, 0}, {1, width}).
write(data);
68 std::vector<T>
read(
size_t row)
70 if (row >= current_size_)
72 TLOG_ERROR(
"HighFiveDatasetHelper") <<
"Requested row " << row <<
" is outside the bounds of this dataset! dataset sz=" << current_size_;
73 return std::vector<T>();
76 std::vector<T> readBuf;
77 dataset_.select({row, 0}, {1, dataset_.getDimensions()[1]}).
read(readBuf);
89 auto res = read<T>(row);
90 if (res.size())
return res[0];
109 TLOG(TLVL_TRACE) <<
"HighFiveDatasetHelper::resize: Growing dataset by one chunk";
111 if (current_size_ % chunk_size_ == 0)
113 dataset_.resize({current_size_ + chunk_size_, dataset_.getDimensions()[1]});
114 current_size_ += chunk_size_;
118 auto size_add = chunk_size_ - (current_size_ % chunk_size_);
119 if (size_add / static_cast<double>(chunk_size_) < 0.5)
121 size_add += chunk_size_;
124 dataset_.resize({current_size_ + size_add, dataset_.getDimensions()[1]});
125 current_size_ += size_add;
130 HighFive::DataSet dataset_;
132 size_t current_size_;
138 #endif //artdaq_demo_hdf5_HDF5_highFive_highFiveDatasetHelper_hh
T readOne(size_t row)
Read a single value from the column.
void write(T const &data)
Write a value to the column, resizing if necessary.
std::vector< T > read(size_t row)
Read a set of value from a row of the column.
void write(T const &data, size_t width)
Write a value to the column, resizing if necessary.
HighFiveDatasetHelper(HighFive::DataSet const &dataset, size_t chunk_size=128)
HighFiveDatasetHelper Constructor.
size_t getDatasetSize()
Get the number of rows in the column.
size_t getRowSize()
Get the number of entries in each row.
Helper class for HighFiveNtupleDataset.