17 bool requireSameFormat,
18 std::size_t bufferSize,
31 const H5::Group& source)
34 bool isEmpty = target.getNumObjs() == 0;
37 for (hsize_t ii = 0; ii < source.getNumObjs(); ++ii) {
38 H5G_obj_t childType = source.getObjTypeByIdx(ii);
39 std::string childName = source.getObjnameByIdx(ii);
41 hsize_t targetIdx = 0;
42 for (; targetIdx < target.getNumObjs(); ++targetIdx)
43 if (target.getObjnameByIdx(targetIdx) == childName)
45 bool found = targetIdx != target.getNumObjs();
48 if (target.getObjTypeByIdx(targetIdx) != childType)
49 throw std::invalid_argument(
50 "Both target and source contain " + childName +
51 " but they have different types!");
54 throw std::invalid_argument(
55 "Target and source have different formats!");
60 H5::Group sg = source.openGroup(childName);
63 if (sg.attrExists(
"uhi_schema")) {
67 H5::Group tg = found ?
68 target.openGroup(childName) :
74 std::cerr <<
"Encountered an error merging child " << childName << std::endl;
81 H5::DataSet sd = source.openDataSet(childName);
82 if (sd.getSpace().getSimpleExtentNdims() == 0) {
83 std::cerr <<
"WARNING: skipping scalar '"
84 << childName <<
"'" << std::endl;
87 H5::DataSet td = found ?
88 target.openDataSet(childName) :
94 std::cerr <<
"Encountered an error merging child " << childName << std::endl;
109 const H5::DataSet& source)
116 std::overflow_error(
"Requested buffer would overflow the register!");
123 H5::H5Location& targetLocation,
124 const H5::Group& source)
126 H5::Group newGroup = targetLocation.createGroup(source.getObjName());
127 merge(newGroup, source);
132 H5::H5Location& targetLocation,
133 const H5::DataSet& source)
Merger(hsize_t mergeAxis=0, int chunkSize=-1, bool requireSameFormat=true, std::size_t bufferSize=-1, bool bufferInRows=false)
Create the merger.
int m_chunkSize
The chunk size to apply.
bool m_measureBufferInRows
Whether to measure the buffer in bytes or rows.
std::unique_ptr< H5Utils::hist::HistogramMerger > m_histMerger
Accumulator for UHI histogram groups.
void flush(H5::Group &dst)
Write all accumulated histogram data to the output.
void merge(H5::Group &target, const H5::Group &source)
Merge a source group into a target group.
hsize_t m_mergeAxis
The axis to merge along.
std::size_t m_bufferSize
The size of the buffer.
H5::Group createFrom(H5::H5Location &targetLocation, const H5::Group &source)
Make a new group from information in a source group.
bool m_requireSameFormat
Whether to require the same group structure.
std::size_t getRowSize(const H5::DataSet &ds, hsize_t axis)
Calculate the size of a row of a dataset in bytes.
H5::DataSet createDataSet(H5::H5Location &targetLocation, const H5::DataSet &source, hsize_t mergeAxis, int chunkSize=-1, int mergeExtent=-1)
Make a new dataset using the properties of another.
void mergeDatasets(H5::DataSet &target, const H5::DataSet &source, hsize_t mergeAxis, std::size_t bufferSize=-1)
Merge two datasets.