ATLAS Offline Software
HdfTuple.h
Go to the documentation of this file.
1 // this is -*- C++ -*-
2 /*
3  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 */
5 
6 #ifndef HDF_TUPLE_HH
7 #define HDF_TUPLE_HH
8 
19 #include "H5Traits.h"
20 
21 #include "H5Cpp.h"
22 
23 #include <functional>
24 #include <vector>
25 #include <memory>
26 
27 namespace H5Utils {
28 
31 
32  namespace internal {
33 
34 
41  template <typename T>
42  data_buffer_t get_buffer_from_func(const std::function<T()>& func) {
44  H5Traits<T>::ref(buffer) = func();
45  return buffer;
46  }
47 
57  {
58  public:
59  virtual ~IVariableFiller() {}
60  virtual data_buffer_t get_buffer() const = 0;
61  virtual H5::DataType get_type() const = 0;
62  virtual std::string name() const = 0;
63  };
64 
66  template <typename T>
68  {
69  public:
70  VariableFiller(const std::string&, const std::function<T()>&);
72  H5::DataType get_type() const;
73  std::string name() const;
74  private:
75  std::function<T()> m_getter;
76  std::string m_name;
77  };
78  template <typename T>
80  const std::function<T()>& func):
81  m_getter(func),
82  m_name(name)
83  {
84  }
85  template <typename T>
87  return get_buffer_from_func<T>(m_getter);
88  }
89  template <typename T>
91  return H5Traits<T>::type;
92  }
93  template <typename T>
94  std::string VariableFiller<T>::name() const {
95  return m_name;
96  }
97 
98  }
100 
101 
102 
115  class VariableFillers:
117  public std::vector<std::shared_ptr<internal::IVariableFiller> >
118  {
119  public:
126  template <typename T>
127  void add(const std::string& name, const std::function<T()>&);
128  };
129 
130  template <typename T>
131  void VariableFillers::add(const std::string& name,
132  const std::function<T()>& fun) {
134  this->push_back(std::make_shared<VariableFiller<T> >(name, fun));
135  }
137 
138 
154  class WriterXd {
155  public:
156  WriterXd(H5::Group& group, const std::string& name,
157  VariableFillers fillers,
158  std::vector<hsize_t> dataset_dimensions,
159  hsize_t chunk_size = 2048);
160  WriterXd(const WriterXd&) = delete;
162  ~WriterXd();
164  std::vector<size_t>& indices);
165  void flush();
166  size_t index() const;
167  private:
168  hsize_t buffer_size() const;
169  H5::CompType m_type;
170  std::vector<hsize_t> m_max_length;
171  std::vector<hsize_t> m_dim_stride;
172  hsize_t m_batch_size;
173  hsize_t m_offset;
174  std::vector<internal::data_buffer_t> m_buffer;
176  H5::DataSet m_ds;
177  };
178 
179 }
180 #endif
H5Utils::WriterXd::m_buffer
std::vector< internal::data_buffer_t > m_buffer
Definition: HdfTuple.h:174
generateReferenceFile.fun
fun
Definition: generateReferenceFile.py:18
H5Utils::WriterXd::buffer_size
hsize_t buffer_size() const
Definition: HdfTuple.cxx:144
H5Utils::internal::VariableFiller::get_buffer
internal::data_buffer_t get_buffer() const
Definition: HdfTuple.h:86
H5Utils::WriterXd::WriterXd
WriterXd(const WriterXd &)=delete
H5Utils::internal::H5Traits
We have lots of code to get around HDF5's rather weak typing.
Definition: H5Traits.h:54
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
H5Utils::WriterXd::index
size_t index() const
Definition: HdfTuple.cxx:140
H5Utils::internal::VariableFiller::name
std::string name() const
Definition: HdfTuple.h:94
H5Utils::WriterXd::fillWhileIncrementing
void fillWhileIncrementing(std::vector< size_t > &indices)
Definition: HdfTuple.cxx:90
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
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
H5Traits.h
H5Utils::internal::IVariableFiller::name
virtual std::string name() const =0
H5Utils::WriterXd
WriterXd.
Definition: HdfTuple.h:154
H5Utils::internal::VariableFiller::VariableFiller
VariableFiller(const std::string &, const std::function< T()> &)
Definition: HdfTuple.h:79
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
H5Utils::internal::VariableFiller::m_getter
std::function< T()> m_getter
Definition: HdfTuple.h:75
H5Utils::WriterXd::m_fillers
VariableFillers m_fillers
Definition: HdfTuple.h:175
H5Utils::VariableFillers::add
void add(const std::string &name, const std::function< T()> &)
Variable add method.
Definition: HdfTuple.h:131
H5Utils::WriterXd::~WriterXd
~WriterXd()
Definition: HdfTuple.cxx:80
H5Utils::internal::data_buffer_t
data_buffer_t
Definition: H5Traits.h:34
H5Utils::WriterXd::m_type
H5::CompType m_type
Definition: HdfTuple.h:169
H5Utils::internal::IVariableFiller
Variable fillers.
Definition: HdfTuple.h:57
H5Utils
HDF5 Tuple Writer.
Definition: common.h:20
H5Utils::internal::VariableFiller::get_type
H5::DataType get_type() const
Definition: HdfTuple.h:90
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
H5Utils::internal::VariableFiller
implementation for variable filler
Definition: HdfTuple.h:68
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
H5Utils::internal::VariableFiller::m_name
std::string m_name
Definition: HdfTuple.h:76
H5Utils::WriterXd::operator=
WriterXd & operator=(WriterXd &)=delete
H5Utils::WriterXd::WriterXd
WriterXd(H5::Group &group, const std::string &name, VariableFillers fillers, std::vector< hsize_t > dataset_dimensions, hsize_t chunk_size=2048)
Definition: HdfTuple.cxx:51
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
ref
const boost::regex ref(r_ef)
H5Utils::WriterXd::m_offset
hsize_t m_offset
Definition: HdfTuple.h:173
H5Utils::internal::get_buffer_from_func
data_buffer_t get_buffer_from_func(const std::function< T()> &func)
Buffer element harvester.
Definition: HdfTuple.h:42
H5Utils::VariableFillers
Variable filler arrays.
Definition: HdfTuple.h:118
H5Utils::internal::IVariableFiller::get_buffer
virtual data_buffer_t get_buffer() const =0
H5Utils::internal::IVariableFiller::~IVariableFiller
virtual ~IVariableFiller()
Definition: HdfTuple.h:59
H5Utils::internal::IVariableFiller::get_type
virtual H5::DataType get_type() const =0