ATLAS Offline Software
Public Member Functions | Protected Attributes | List of all members
H5Utils::DefaultMerger Class Reference

#include <DefaultMerger.h>

Inheritance diagram for H5Utils::DefaultMerger:
Collaboration diagram for H5Utils::DefaultMerger:

Public Member Functions

 DefaultMerger (hsize_t mergeAxis=0, int chunkSize=-1, bool requireSameFormat=true, std::size_t bufferSize=-1, bool bufferInRows=false)
 Create the merger. More...
 
 ~DefaultMerger ()
 
void merge (H5::Group &target, const H5::Group &source) override
 Merge a source group into a target group. More...
 
void merge (H5::DataSet &target, const H5::DataSet &source) override
 Merge a source dataset into a target dataset. More...
 
H5::DataSet createFrom (H5::H5Location &targetLocation, const H5::DataSet &source) override
 Make a new dataset from information in a source dataset. More...
 
virtual void merge (H5::H5File &target, const H5::H5File &source)
 Merge a source file into a target file. More...
 
virtual void merge (H5::Group &target, const H5::Group &source)=0
 Merge a source group into a target group. More...
 
virtual void merge (H5::DataSet &target, const H5::DataSet &source)=0
 Merge a source dataset into a target dataset. More...
 
virtual H5::Group createFrom (H5::H5Location &targetLocation, const H5::Group &source)
 Make a new group from information in a source group. More...
 
virtual H5::DataSet createFrom (H5::H5Location &targetLocation, const H5::DataSet &source)=0
 Make a new dataset from information in a source dataset. More...
 
virtual void merge (H5::H5File &target, const H5::H5File &source)
 Merge a source file into a target file. More...
 
virtual H5::Group createFrom (H5::H5Location &targetLocation, const H5::Group &source)
 Make a new group from information in a source group. More...
 

Protected Attributes

hsize_t m_mergeAxis
 The axis to merge along. More...
 
int m_chunkSize
 The chunk size to apply. More...
 
bool m_requireSameFormat
 Whether to require the same group structure. More...
 
std::size_t m_bufferSize
 The size of the buffer. More...
 
bool m_measureBufferInRows
 Whether to measure the buffer in bytes or rows. More...
 

Detailed Description

Definition at line 21 of file DefaultMerger.h.

Constructor & Destructor Documentation

◆ DefaultMerger()

H5Utils::DefaultMerger::DefaultMerger ( 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 12 of file DefaultMerger.cxx.

17  :
18  m_mergeAxis(mergeAxis),
20  m_requireSameFormat(requireSameFormat),
21  m_bufferSize(bufferSize),
22  m_measureBufferInRows(bufferInRows) {}

◆ ~DefaultMerger()

H5Utils::DefaultMerger::~DefaultMerger ( )

Definition at line 24 of file DefaultMerger.cxx.

24 {}

Member Function Documentation

◆ createFrom() [1/4]

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

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

Implements H5Utils::IH5Merger.

Definition at line 113 of file DefaultMerger.cxx.

116  {
117  return createDataSet(targetLocation, source, m_mergeAxis, m_chunkSize);
118  }

◆ createFrom() [2/4]

virtual H5::DataSet H5Utils::IH5Merger::createFrom

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

◆ createFrom() [3/4]

H5::Group H5Utils::IH5Merger::createFrom

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

The default implementation provided here just copies the source group's name then uses the merge function.

Definition at line 61 of file IH5Merger.cxx.

21  {
22  H5::Group newGroup = targetLocation.createGroup(source.getObjName() );
23  merge(newGroup, source);
24  return newGroup;
25  }

◆ createFrom() [4/4]

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

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

The default implementation provided here just copies the source group's name then uses the merge function.

Definition at line 18 of file IH5Merger.cxx.

21  {
22  H5::Group newGroup = targetLocation.createGroup(source.getObjName() );
23  merge(newGroup, source);
24  return newGroup;
25  }

◆ merge() [1/6]

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

Merge a source dataset into a target dataset.

Parameters
targetThe dataset to merge into
sourceThe dataset to merge from

Implements H5Utils::IH5Merger.

Definition at line 98 of file DefaultMerger.cxx.

101  {
102  std::size_t bufferSize = m_bufferSize;
103  if (m_measureBufferInRows) {
104  // Need to calculate the actual buffer size
105  std::size_t rowSize = getRowSize(source, m_mergeAxis);
106  if (std::size_t(-1) / m_bufferSize < rowSize)
107  std::overflow_error("Requested buffer would overflow the register!");
108  bufferSize = rowSize * m_bufferSize;
109  }
110  mergeDatasets(target, source, m_mergeAxis, bufferSize);
111  }

◆ merge() [2/6]

virtual void H5Utils::IH5Merger::merge

Merge a source dataset into a target dataset.

Parameters
targetThe dataset to merge into
sourceThe dataset to merge from

◆ merge() [3/6]

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

Merge a source group into a target group.

Parameters
targetThe group to merge into
sourceThe group to merge from

Implements H5Utils::IH5Merger.

Definition at line 26 of file DefaultMerger.cxx.

29  {
30  // Check if this group was empty before we started
31  bool isEmpty = target.getNumObjs() == 0;
32 
33  // Iterate through each child of the source group
34  for (hsize_t ii = 0; ii < source.getNumObjs(); ++ii) {
35  H5G_obj_t childType = source.getObjTypeByIdx(ii);
36  std::string childName = source.getObjnameByIdx(ii);
37  // Find the correct index in the target
38  hsize_t targetIdx = 0;
39  for (; targetIdx < target.getNumObjs(); ++targetIdx)
40  if (target.getObjnameByIdx(targetIdx) == childName)
41  break;
42  bool found = targetIdx != target.getNumObjs();
43  if (found) {
44  // Make sure these are the same type!
45  if (target.getObjTypeByIdx(targetIdx) != childType)
46  throw std::invalid_argument(
47  "Both target and source contain " + childName +
48  " but they have different types!");
49  }
50  else if (m_requireSameFormat && !isEmpty) {
51  throw std::invalid_argument(
52  "Target and source have different formats!");
53  }
54  switch (childType) {
55  case H5G_GROUP:
56  {
57  H5::Group sg = source.openGroup(childName);
58  H5::Group tg = found ?
59  target.openGroup(childName) :
60  createFrom(target, sg);
61  try {
62  merge(tg, sg);
63  }
64  catch (...) {
65  std::cerr << "Encountered an error merging child " << childName << std::endl;
66  throw;
67  }
68  }
69  break;
70  case H5G_DATASET:
71  {
72  H5::DataSet sd = source.openDataSet(childName);
73  if (sd.getSpace().getSimpleExtentNdims() == 0) {
74  std::cerr << "WARNING: skipping scalar '"
75  << childName << "'" << std::endl;
76  break;
77  }
78  H5::DataSet td = found ?
79  target.openDataSet(childName) :
81  try {
82  merge(td, sd);
83  }
84  catch (...) {
85  std::cerr << "Encountered an error merging child " << childName << std::endl;
86  throw;
87  }
88  }
89  break;
90  default:
91  break;
92  }
93  } //> end loop over children
94  // TODO - this did no check to see if target contained something source
95  // didn't, this is probably fine though.
96  } //> end function merge(group)

◆ merge() [4/6]

virtual void H5Utils::IH5Merger::merge

Merge a source group into a target group.

Parameters
targetThe group to merge into
sourceThe group to merge from

◆ merge() [5/6]

void H5Utils::IH5Merger::merge ( H5::H5File &  target,
const H5::H5File &  source 
)
virtualinherited

Merge a source file into a target file.

Parameters
targetThe file to merge into
sourceThe file to merge from

The default implementation provided here just forwards this to the group function.

Definition at line 11 of file IH5Merger.cxx.

12  {
13  merge(
14  static_cast<H5::Group&>(target),
15  static_cast<const H5::Group&>(source) );
16  }

◆ merge() [6/6]

void H5Utils::IH5Merger::merge

Merge a source file into a target file.

Parameters
targetThe file to merge into
sourceThe file to merge from

The default implementation provided here just forwards this to the group function.

Definition at line 37 of file IH5Merger.cxx.

12  {
13  merge(
14  static_cast<H5::Group&>(target),
15  static_cast<const H5::Group&>(source) );
16  }

Member Data Documentation

◆ m_bufferSize

std::size_t H5Utils::DefaultMerger::m_bufferSize
protected

The size of the buffer.

Definition at line 79 of file DefaultMerger.h.

◆ m_chunkSize

int H5Utils::DefaultMerger::m_chunkSize
protected

The chunk size to apply.

Definition at line 75 of file DefaultMerger.h.

◆ m_measureBufferInRows

bool H5Utils::DefaultMerger::m_measureBufferInRows
protected

Whether to measure the buffer in bytes or rows.

Definition at line 81 of file DefaultMerger.h.

◆ m_mergeAxis

hsize_t H5Utils::DefaultMerger::m_mergeAxis
protected

The axis to merge along.

Definition at line 73 of file DefaultMerger.h.

◆ m_requireSameFormat

bool H5Utils::DefaultMerger::m_requireSameFormat
protected

Whether to require the same group structure.

Definition at line 77 of file DefaultMerger.h.


The documentation for this class was generated from the following files:
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
H5Utils::DefaultMerger::m_mergeAxis
hsize_t m_mergeAxis
The axis to merge along.
Definition: DefaultMerger.h:73
H5Utils::DefaultMerger::m_chunkSize
int m_chunkSize
The chunk size to apply.
Definition: DefaultMerger.h:75
AthExHiveOpts.chunkSize
chunkSize
Definition: AthExHiveOpts.py:101
H5Utils::DefaultMerger::m_bufferSize
std::size_t m_bufferSize
The size of the buffer.
Definition: DefaultMerger.h:79
python.selector.AtlRunQuerySelectorLhcOlc.sd
sd
Definition: AtlRunQuerySelectorLhcOlc.py:612
H5Utils::DefaultMerger::merge
void merge(H5::Group &target, const H5::Group &source) override
Merge a source group into a target group.
Definition: DefaultMerger.cxx:26
H5Utils::DefaultMerger::m_requireSameFormat
bool m_requireSameFormat
Whether to require the same group structure.
Definition: DefaultMerger.h:77
H5Utils::DefaultMerger::m_measureBufferInRows
bool m_measureBufferInRows
Whether to measure the buffer in bytes or rows.
Definition: DefaultMerger.h:81
H5Utils::getRowSize
std::size_t getRowSize(const H5::DataSet &ds, hsize_t axis)
Calculate the size of a row of a dataset in bytes.
Definition: MergeUtils.cxx:254
H5Utils::mergeDatasets
void mergeDatasets(H5::DataSet &target, const H5::DataSet &source, hsize_t mergeAxis, std::size_t bufferSize=-1)
Merge two datasets.
Definition: MergeUtils.cxx:130
H5Utils::DefaultMerger::createFrom
H5::DataSet createFrom(H5::H5Location &targetLocation, const H5::DataSet &source) override
Make a new dataset from information in a source dataset.
Definition: DefaultMerger.cxx:113
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
H5Utils::createDataSet
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.
Definition: MergeUtils.cxx:222
H5Utils::IH5Merger::merge
virtual void merge(H5::H5File &target, const H5::H5File &source)
Merge a source file into a target file.
Definition: IH5Merger.cxx:11
COOLRates.target
target
Definition: COOLRates.py:1106