ATLAS Offline Software
Loading...
Searching...
No Matches
H5Utils::Merger Class Reference

#include <Merger.h>

Collaboration diagram for H5Utils::Merger:

Public Member Functions

 Merger (hsize_t mergeAxis=0, int chunkSize=-1, bool requireSameFormat=true, std::size_t bufferSize=-1, bool bufferInRows=false)
 Create the merger.
 ~Merger ()
void merge (H5::Group &target, const H5::Group &source)
 Merge a source group into a target group.
void merge (H5::DataSet &target, const H5::DataSet &source)
 Merge a source dataset into a target dataset.
H5::Group createFrom (H5::H5Location &targetLocation, const H5::Group &source)
 Make a new group from information in a source group.
H5::DataSet createFrom (H5::H5Location &targetLocation, const H5::DataSet &source)
 Make a new dataset from information in a source dataset.
void flush (H5::Group &dst)
 Write all accumulated histogram data to the output.

Protected Attributes

hsize_t m_mergeAxis
 The axis to merge along.
int m_chunkSize
 The chunk size to apply.
bool m_requireSameFormat
 Whether to require the same group structure.
std::size_t m_bufferSize
 The size of the buffer.
bool m_measureBufferInRows
 Whether to measure the buffer in bytes or rows.
std::unique_ptr< H5Utils::hist::HistogramMergerm_histMerger
 Accumulator for UHI histogram groups.

Detailed Description

Definition at line 24 of file Merger.h.

Constructor & Destructor Documentation

◆ Merger()

H5Utils::Merger::Merger ( hsize_t mergeAxis = 0,
int chunkSize = -1,
bool requireSameFormat = true,
std::size_t bufferSize = -1,
bool bufferInRows = false )

Create the merger.

Parameters
mergeAxisThe axis to merge along
chunkSizeThe chunk size to apply. If negative then the value found in the input datasets will be used.
requireSameFormatRequire all input files to have the same groups and datasets.
bufferSizeThe maximum size of the buffer to use while merging datasets
bufferInRowsWhether the buffer size is specified in rows or bytes

Definition at line 14 of file Merger.cxx.

19 :
20 m_mergeAxis(mergeAxis),
21 m_chunkSize(chunkSize),
22 m_requireSameFormat(requireSameFormat),
23 m_bufferSize(bufferSize),
24 m_measureBufferInRows(bufferInRows),
25 m_histMerger(std::make_unique<H5Utils::hist::HistogramMerger>()) {}
int m_chunkSize
The chunk size to apply.
Definition Merger.h:89
bool m_measureBufferInRows
Whether to measure the buffer in bytes or rows.
Definition Merger.h:95
std::unique_ptr< H5Utils::hist::HistogramMerger > m_histMerger
Accumulator for UHI histogram groups.
Definition Merger.h:97
hsize_t m_mergeAxis
The axis to merge along.
Definition Merger.h:87
std::size_t m_bufferSize
The size of the buffer.
Definition Merger.h:93
bool m_requireSameFormat
Whether to require the same group structure.
Definition Merger.h:91

◆ ~Merger()

H5Utils::Merger::~Merger ( )

Definition at line 27 of file Merger.cxx.

27{}

Member Function Documentation

◆ createFrom() [1/2]

H5::DataSet H5Utils::Merger::createFrom ( H5::H5Location & targetLocation,
const H5::DataSet & source )

Make a new dataset from information in a source dataset.

Parameters
targetLocationWhere the new dataset will be created
sourceThe dataset to use to create the new dataset

Definition at line 131 of file Merger.cxx.

134 {
135 return createDataSet(targetLocation, source, m_mergeAxis, m_chunkSize);
136 }
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.

◆ createFrom() [2/2]

H5::Group H5Utils::Merger::createFrom ( H5::H5Location & targetLocation,
const H5::Group & source )

Make a new group from information in a source group.

Parameters
targetLocationWhere the new group will be created
sourceThe group to use to create the new group

Definition at line 122 of file Merger.cxx.

125 {
126 H5::Group newGroup = targetLocation.createGroup(source.getObjName());
127 merge(newGroup, source);
128 return newGroup;
129 }
void merge(H5::Group &target, const H5::Group &source)
Merge a source group into a target group.
Definition Merger.cxx:29

◆ flush()

void H5Utils::Merger::flush ( H5::Group & dst)

Write all accumulated histogram data to the output.

Parameters
dstThe root group of the output file.

Definition at line 138 of file Merger.cxx.

139 {
140 m_histMerger->write(dst);
141 }

◆ merge() [1/2]

void H5Utils::Merger::merge ( H5::DataSet & target,
const H5::DataSet & source )

Merge a source dataset into a target dataset.

Parameters
targetThe dataset to merge into
sourceThe dataset to merge from

Definition at line 107 of file Merger.cxx.

110 {
111 std::size_t bufferSize = m_bufferSize;
113 // Need to calculate the actual buffer size
114 std::size_t rowSize = getRowSize(source, m_mergeAxis);
115 if (std::size_t(-1) / m_bufferSize < rowSize)
116 std::overflow_error("Requested buffer would overflow the register!");
117 bufferSize = rowSize * m_bufferSize;
118 }
119 mergeDatasets(target, source, m_mergeAxis, bufferSize);
120 }
std::size_t getRowSize(const H5::DataSet &ds, hsize_t axis)
Calculate the size of a row of a dataset in bytes.
void mergeDatasets(H5::DataSet &target, const H5::DataSet &source, hsize_t mergeAxis, std::size_t bufferSize=-1)
Merge two datasets.

◆ merge() [2/2]

void H5Utils::Merger::merge ( H5::Group & target,
const H5::Group & source )

Merge a source group into a target group.

Parameters
targetThe group to merge into
sourceThe group to merge from

Definition at line 29 of file Merger.cxx.

32 {
33 // Check if this group was empty before we started
34 bool isEmpty = target.getNumObjs() == 0;
35
36 // Iterate through each child of the source group
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);
40 // Find the correct index in the target
41 hsize_t targetIdx = 0;
42 for (; targetIdx < target.getNumObjs(); ++targetIdx)
43 if (target.getObjnameByIdx(targetIdx) == childName)
44 break;
45 bool found = targetIdx != target.getNumObjs();
46 if (found) {
47 // Make sure these are the same type!
48 if (target.getObjTypeByIdx(targetIdx) != childType)
49 throw std::invalid_argument(
50 "Both target and source contain " + childName +
51 " but they have different types!");
52 }
53 else if (m_requireSameFormat && !isEmpty) {
54 throw std::invalid_argument(
55 "Target and source have different formats!");
56 }
57 switch (childType) {
58 case H5G_GROUP:
59 {
60 H5::Group sg = source.openGroup(childName);
61 // UHI histogram groups are accumulated separately and written
62 // once all source files have been processed.
63 if (sg.attrExists("uhi_schema")) {
64 m_histMerger->add(sg.getObjName(), sg);
65 continue;
66 }
67 H5::Group tg = found ?
68 target.openGroup(childName) :
69 createFrom(target, sg);
70 try {
71 merge(tg, sg);
72 }
73 catch (...) {
74 std::cerr << "Encountered an error merging child " << childName << std::endl;
75 throw;
76 }
77 }
78 break;
79 case H5G_DATASET:
80 {
81 H5::DataSet sd = source.openDataSet(childName);
82 if (sd.getSpace().getSimpleExtentNdims() == 0) {
83 std::cerr << "WARNING: skipping scalar '"
84 << childName << "'" << std::endl;
85 break;
86 }
87 H5::DataSet td = found ?
88 target.openDataSet(childName) :
89 createFrom(target, sd);
90 try {
91 merge(td, sd);
92 }
93 catch (...) {
94 std::cerr << "Encountered an error merging child " << childName << std::endl;
95 throw;
96 }
97 }
98 break;
99 default:
100 break;
101 }
102 } //> end loop over children
103 // TODO - this did no check to see if target contained something source
104 // didn't, this is probably fine though.
105 } //> end function merge(group)
H5::Group createFrom(H5::H5Location &targetLocation, const H5::Group &source)
Make a new group from information in a source group.
Definition Merger.cxx:122

Member Data Documentation

◆ m_bufferSize

std::size_t H5Utils::Merger::m_bufferSize
protected

The size of the buffer.

Definition at line 93 of file Merger.h.

◆ m_chunkSize

int H5Utils::Merger::m_chunkSize
protected

The chunk size to apply.

Definition at line 89 of file Merger.h.

◆ m_histMerger

std::unique_ptr<H5Utils::hist::HistogramMerger> H5Utils::Merger::m_histMerger
protected

Accumulator for UHI histogram groups.

Definition at line 97 of file Merger.h.

◆ m_measureBufferInRows

bool H5Utils::Merger::m_measureBufferInRows
protected

Whether to measure the buffer in bytes or rows.

Definition at line 95 of file Merger.h.

◆ m_mergeAxis

hsize_t H5Utils::Merger::m_mergeAxis
protected

The axis to merge along.

Definition at line 87 of file Merger.h.

◆ m_requireSameFormat

bool H5Utils::Merger::m_requireSameFormat
protected

Whether to require the same group structure.

Definition at line 91 of file Merger.h.


The documentation for this class was generated from the following files: