ATLAS Offline Software
Loading...
Searching...
No Matches
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
18
19#include "H5Traits.h"
20
21#include "H5Cpp.h"
22
23#include <functional>
24#include <vector>
25#include <memory>
26
27namespace 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) {
43 data_buffer_t buffer;
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),
83 {
84 }
85 template <typename T>
89 template <typename T>
90 H5::DataType VariableFiller<T>::get_type() const {
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
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 }
136
137
138
153
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;
173 hsize_t m_offset;
174 std::vector<internal::data_buffer_t> m_buffer;
176 H5::DataSet m_ds;
177 };
178
179}
180#endif
Variable filler arrays.
Definition HdfTuple.h:118
void add(const std::string &name, const std::function< T()> &)
Variable add method.
Definition HdfTuple.h:131
void fillWhileIncrementing(std::vector< size_t > &indices)
Definition HdfTuple.cxx:90
H5::CompType m_type
Definition HdfTuple.h:169
VariableFillers m_fillers
Definition HdfTuple.h:175
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
std::vector< hsize_t > m_dim_stride
Definition HdfTuple.h:171
hsize_t buffer_size() const
Definition HdfTuple.cxx:144
std::vector< hsize_t > m_max_length
Definition HdfTuple.h:170
WriterXd & operator=(WriterXd &)=delete
H5::DataSet m_ds
Definition HdfTuple.h:176
size_t index() const
Definition HdfTuple.cxx:140
std::vector< internal::data_buffer_t > m_buffer
Definition HdfTuple.h:174
hsize_t m_batch_size
Definition HdfTuple.h:172
WriterXd(const WriterXd &)=delete
virtual H5::DataType get_type() const =0
virtual data_buffer_t get_buffer() const =0
virtual std::string name() const =0
implementation for variable filler
Definition HdfTuple.h:68
std::function< T()> m_getter
Definition HdfTuple.h:75
internal::data_buffer_t get_buffer() const
Definition HdfTuple.h:86
std::string name() const
Definition HdfTuple.h:94
VariableFiller(const std::string &, const std::function< T()> &)
Definition HdfTuple.h:79
H5::DataType get_type() const
Definition HdfTuple.h:90
clssses to add type traits for H5
Definition common.h:21
data_buffer_t get_buffer_from_func(const std::function< T()> &func)
Buffer element harvester.
Definition HdfTuple.h:42
HDF5 Tuple Writer.
Definition common.h:20
We have lots of code to get around HDF5's rather weak typing.
Definition H5Traits.h:54