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

WriterXd. More...

#include <HdfTuple.h>

Collaboration diagram for H5Utils::WriterXd:

Public Member Functions

 WriterXd (H5::Group &group, const std::string &name, VariableFillers fillers, std::vector< hsize_t > dataset_dimensions, hsize_t chunk_size=2048)
 
 WriterXd (const WriterXd &)=delete
 
WriterXdoperator= (WriterXd &)=delete
 
 ~WriterXd ()
 
void fillWhileIncrementing (std::vector< size_t > &indices)
 
void flush ()
 
size_t index () const
 

Private Member Functions

hsize_t buffer_size () const
 

Private Attributes

H5::CompType m_type
 
std::vector< hsize_t > m_max_length
 
std::vector< hsize_t > m_dim_stride
 
hsize_t m_batch_size
 
hsize_t m_offset
 
std::vector< internal::data_buffer_tm_buffer
 
VariableFillers m_fillers
 
H5::DataSet m_ds
 

Detailed Description

WriterXd.

Writer class

This is the other thing you interact with.

You'll have to specify the H5::Group to write the dataset to, the name of the new dataset, and the extent of the dataset.

To fill, use the fill_while_incrementing function, which will iterate over all possible values of indices within the dataset dimensions. The variable filler is called once for each index combination.

Definition at line 154 of file HdfTuple.h.

Constructor & Destructor Documentation

◆ WriterXd() [1/2]

H5Utils::WriterXd::WriterXd ( H5::Group &  group,
const std::string &  name,
VariableFillers  fillers,
std::vector< hsize_t >  dataset_dimensions,
hsize_t  chunk_size = 2048 
)

Definition at line 51 of file HdfTuple.cxx.

54  :
55  m_type(build_type(fillers)),
56  m_max_length(max_length),
57  m_dim_stride(max_length),
59  m_offset(0),
60  m_fillers(fillers)
61  {
62  if (batch_size < 1) {
63  throw std::logic_error("batch size must be > 0");
64  }
65  // create space
66  H5::DataSpace space = internal::getUnlimitedSpace(max_length);
67 
68  // create params
69  H5::DSetCreatPropList params = getChunckedDatasetParams(
70  max_length, batch_size);
71 
72  // calculate striding
73  m_dim_stride = internal::getStriding(max_length);
74 
75  // create ds
77  m_ds = group.createDataSet(name, internal::packed(m_type), space, params);
78  }

◆ WriterXd() [2/2]

H5Utils::WriterXd::WriterXd ( const WriterXd )
delete

◆ ~WriterXd()

H5Utils::WriterXd::~WriterXd ( )

Definition at line 80 of file HdfTuple.cxx.

80  {
81  try {
82  flush();
83  } catch (H5::Exception& err) {
84  internal::printDestructorError(err.getDetailMsg());
85  } catch (std::exception& err) {
87  }
88  }

Member Function Documentation

◆ buffer_size()

hsize_t H5Utils::WriterXd::buffer_size ( ) const
private

Definition at line 144 of file HdfTuple.cxx.

144  {
145  size_t n_entries = m_buffer.size() / m_fillers.size();
146  assert(n_entries % m_dim_stride.front() == 0);
147  return n_entries / m_dim_stride.front();
148  }

◆ fillWhileIncrementing()

void H5Utils::WriterXd::fillWhileIncrementing ( std::vector< size_t > &  indices)

Definition at line 90 of file HdfTuple.cxx.

90  {
91  if (buffer_size() == m_batch_size) {
92  flush();
93  }
94  indices.resize(m_max_length.size());
95 
96  // build buffer and _then_ insert it so that exceptions don't leave
97  // the buffer in a weird state
98  std::vector<internal::data_buffer_t> temp;
99 
100  std::fill(indices.begin(), indices.end(), 0);
101  for (size_t gidx = 0; gidx < m_dim_stride.front(); gidx++) {
102 
103  // we might be able to make this more efficient and less cryptic
104  for (size_t iii = 0; iii < indices.size(); iii++) {
105  indices.at(iii) = (gidx % m_dim_stride.at(iii)) /
106  m_dim_stride.at(iii+1);
107  }
108 
109  for (const auto& filler: m_fillers) {
110  temp.push_back(filler->get_buffer());
111  }
112  }
113  m_buffer.insert(m_buffer.end(), temp.begin(), temp.end());
114  }

◆ flush()

void H5Utils::WriterXd::flush ( )

Definition at line 115 of file HdfTuple.cxx.

115  {
116  if (buffer_size() == 0) return;
117  // extend the ds
118  std::vector<hsize_t> slab_dims{buffer_size()};
119  slab_dims.insert(slab_dims.end(), m_max_length.begin(), m_max_length.end());
120  std::vector<hsize_t> total_dims{buffer_size() + m_offset};
121  total_dims.insert(total_dims.end(), m_max_length.begin(), m_max_length.end());
122  m_ds.extend(total_dims.data());
123 
124  // setup dataspaces
125  H5::DataSpace file_space = m_ds.getSpace();
126  H5::DataSpace mem_space(slab_dims.size(), slab_dims.data());
127  std::vector<hsize_t> offset_dims{m_offset};
128  offset_dims.resize(slab_dims.size(), 0);
129  file_space.selectHyperslab(H5S_SELECT_SET,
130  slab_dims.data(), offset_dims.data());
131 
132  // write out
133  assert(static_cast<size_t>(file_space.getSelectNpoints())
134  == m_buffer.size() / m_fillers.size());
135  m_ds.write(m_buffer.data(), m_type, mem_space, file_space);
136  m_offset += buffer_size();
137  m_buffer.clear();
138  }

◆ index()

size_t H5Utils::WriterXd::index ( ) const

Definition at line 140 of file HdfTuple.cxx.

140  {
141  return m_offset + buffer_size();
142  }

◆ operator=()

WriterXd& H5Utils::WriterXd::operator= ( WriterXd )
delete

Member Data Documentation

◆ m_batch_size

hsize_t H5Utils::WriterXd::m_batch_size
private

Definition at line 172 of file HdfTuple.h.

◆ m_buffer

std::vector<internal::data_buffer_t> H5Utils::WriterXd::m_buffer
private

Definition at line 174 of file HdfTuple.h.

◆ m_dim_stride

std::vector<hsize_t> H5Utils::WriterXd::m_dim_stride
private

Definition at line 171 of file HdfTuple.h.

◆ m_ds

H5::DataSet H5Utils::WriterXd::m_ds
private

Definition at line 176 of file HdfTuple.h.

◆ m_fillers

VariableFillers H5Utils::WriterXd::m_fillers
private

Definition at line 175 of file HdfTuple.h.

◆ m_max_length

std::vector<hsize_t> H5Utils::WriterXd::m_max_length
private

Definition at line 170 of file HdfTuple.h.

◆ m_offset

hsize_t H5Utils::WriterXd::m_offset
private

Definition at line 173 of file HdfTuple.h.

◆ m_type

H5::CompType H5Utils::WriterXd::m_type
private

Definition at line 169 of file HdfTuple.h.


The documentation for this class was generated from the following files:
H5Utils::WriterXd::m_buffer
std::vector< internal::data_buffer_t > m_buffer
Definition: HdfTuple.h:174
H5Utils::WriterXd::buffer_size
hsize_t buffer_size() const
Definition: HdfTuple.cxx:144
H5Utils::internal::getChunckedDatasetParams
H5::DSetCreatPropList getChunckedDatasetParams(const WriterConfiguration< N > &)
H5Utils::internal::getUnlimitedSpace
H5::DataSpace getUnlimitedSpace(const std::vector< hsize_t > &max_length)
Definition: common.cxx:31
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
H5Utils::WriterXd::m_batch_size
hsize_t m_batch_size
Definition: HdfTuple.h:172
H5Utils::defaults::batch_size
const hsize_t batch_size
Definition: defaults.h:9
H5Utils::internal::printDestructorError
void printDestructorError(const std::string &msg)
Definition: common.cxx:24
H5Utils::internal::packed
H5::CompType packed(H5::CompType in)
Definition: common.cxx:16
H5Utils::WriterXd::m_fillers
VariableFillers m_fillers
Definition: HdfTuple.h:175
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
H5Utils::WriterXd::m_type
H5::CompType m_type
Definition: HdfTuple.h:169
calibdata.exception
exception
Definition: calibdata.py:496
H5Utils::WriterXd::m_ds
H5::DataSet m_ds
Definition: HdfTuple.h:176
H5Utils::WriterXd::m_max_length
std::vector< hsize_t > m_max_length
Definition: HdfTuple.h:170
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
H5Utils::internal::throwIfExists
void throwIfExists(const std::string &name, const H5::Group &in_group)
Definition: common.cxx:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
H5Utils::internal::getStriding
std::vector< hsize_t > getStriding(std::vector< hsize_t > max_length)
Definition: common.cxx:38
H5Utils::WriterXd::m_dim_stride
std::vector< hsize_t > m_dim_stride
Definition: HdfTuple.h:171
H5Utils::WriterXd::flush
void flush()
Definition: HdfTuple.cxx:115
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
H5Utils::WriterXd::m_offset
hsize_t m_offset
Definition: HdfTuple.h:173
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226