ATLAS Offline Software
Loading...
Searching...
No Matches
test-hdf5-writer.cxx File Reference
#include "HDF5Utils/Writer.h"
#include <type_traits>
Include dependency graph for test-hdf5-writer.cxx:

Go to the source code of this file.

Classes

struct  out_t

Macros

#define ADD(NAME)

Typedefs

using consumer_t = H5Utils::Consumers<const out_t&>

Functions

consumer_t getConsumers ()
std::vector< out_t > getOutputs (int offset, size_t length, float factor)
template<size_t N>
auto nestOutputs (int offset, size_t length)
template<>
auto nestOutputs< 1 > (int offset, size_t length)
void fill (H5::Group &out_file, size_t iterations)
int main (int nargs, char *argv[])

Macro Definition Documentation

◆ ADD

#define ADD ( NAME)
Value:
consumers.add(#NAME, [](const out_t& o){ return o.NAME;}, 0)

Typedef Documentation

◆ consumer_t

Definition at line 27 of file test-hdf5-writer.cxx.

Function Documentation

◆ fill()

void fill ( H5::Group & out_file,
size_t iterations )

Definition at line 102 of file test-hdf5-writer.cxx.

102 {
103
104 const int deflate = 7;
105
106 // scalar output
107 using scalar_writer_t = H5Utils::Writer<0, consumer_t::input_type>;
108 scalar_writer_t::configuration_type scalar_config{};
109 scalar_config.name = "scalar";
110 scalar_config.deflate = deflate;
111 consumer_t consumers = getConsumers();
112 // the moved-from writer holds buffered rows and is destroyed while
113 // the new one still writes to the dataset
114 scalar_writer_t scalar = [&] {
115 scalar_writer_t source(out_file, consumers, scalar_config);
116 source.fill(getOutputs(1, 1, 0.5).at(0));
117 return scalar_writer_t(std::move(source));
118 }();
119 for (size_t n = 1; n < iterations; n++) {
120 scalar.fill(getOutputs(1 + n, 1, 0.5).at(0));
121 }
122
123 // 1d output
125 d1_t::configuration_type d1_config{};
126 d1_config.name = "1d";
127 d1_config.extent = {10};
128 d1_config.chunks = {5};
129 d1_config.deflate = deflate;
130 d1_t d1(out_file, consumers, d1_config);
131 for (size_t n = 0; n < iterations; n++) {
132 d1.fill(getOutputs(n, 10, 0.5));
133 }
134
135 // 4d output
137 d4_t::configuration_type d4_config;
138 d4_config.name = "4d";
139 d4_config.extent = {2,3,4,5};
140 d4_config.chunks = {1,2,1,2};
141 d4_config.deflate = deflate;
142 d4_t d4(out_file, consumers, d4_config);
143 for (size_t n = 0; n < iterations; n++) {
144 auto vals = nestOutputs<4>(n, 2);
145 // store some specific value to make sure we have the indexing
146 // right
147 vals.at(1).at(2).at(3).at(4).stype = 86;
148 d4.fill(std::move(vals));
149 }
150}
Writer.
Definition Writer.h:352
mapped_type at(key_type key) const
Look up an element in the map.
const int deflate
Definition defaults.h:10
H5Utils::Consumers< const out_t & > consumer_t
consumer_t getConsumers()
auto nestOutputs(int offset, size_t length)
std::vector< out_t > getOutputs(int offset, size_t length, float factor)

◆ getConsumers()

consumer_t getConsumers ( )

Definition at line 34 of file test-hdf5-writer.cxx.

34 {
35 consumer_t consumers;
36#define ADD(NAME) consumers.add(#NAME, [](const out_t& o){ return o.NAME;}, 0)
37 ADD(ctype);
38 ADD(stype);
39 ADD(itype);
40 ADD(ltype);
41 ADD(lltype);
42 ADD(uctype);
43 ADD(ustype);
44 ADD(uitype);
45 ADD(ultype);
46 ADD(ulltype);
47 ADD(ftype);
48 ADD(dtype);
49 ADD(btype);
50#undef ADD
52 consumers.add("half" , [](const out_t& o) { return o.ftype; }, 0, half);
53 consumers.add("dhalf", [](const out_t& o) { return o.dtype; }, 0, half);
54 return consumers;
55}
void add(const std::string &name, const std::function< T(I)> &, const T &default_value=T(), Compression=Compression::STANDARD)
This should be the only method you need in this class.
Definition Writer.h:166
#define ADD(NAME)

◆ getOutputs()

std::vector< out_t > getOutputs ( int offset,
size_t length,
float factor )

Definition at line 60 of file test-hdf5-writer.cxx.

60 {
61 std::vector<out_t> outvec;
62 for (size_t n = 0; n < length; n++) {
63 out_t out;
64 long long int shifted = n + offset;
65 double factored = shifted*factor;
66 out.dtype = factored;
67 out.ftype = factored;
68 out.ctype = shifted;
69 out.stype = shifted;
70 out.itype = shifted;
71 out.ltype = shifted;
72 out.lltype = shifted;
73 out.uctype = shifted;
74 out.ustype = shifted;
75 out.uitype = shifted;
76 out.ultype = shifted;
77 out.ulltype = shifted;
78 out.btype = n % 2;
79 outvec.push_back(out);
80 }
81 return outvec;
82}
double length(const pvec &v)

◆ main()

int main ( int nargs,
char * argv[] )

Definition at line 152 of file test-hdf5-writer.cxx.

152 {
153 H5::H5File out_file("output.h5", H5F_ACC_TRUNC);
154 size_t iterations = 1;
155 if (nargs > 2) {
156 return 1;
157 }
158 if (nargs > 1) iterations = std::atoi(argv[1]);
159 //coverity[TAINTED_SCALAR]
160 fill(out_file, iterations);
161 return 0;
162}
void fill(H5::Group &out_file, size_t iterations)

◆ nestOutputs()

template<size_t N>
auto nestOutputs ( int offset,
size_t length )

Definition at line 85 of file test-hdf5-writer.cxx.

85 {
86 using ret_t = decltype(
87 nestOutputs<N-1>(std::declval<int>(),std::declval<size_t>()));
88 std::vector<ret_t> ret;
89 for (size_t n = 0; n < length; n++) {
90 ret.push_back(nestOutputs<N-1>(n + offset, length + 1));
91 }
92 return ret;
93}
constexpr std::size_t N

◆ nestOutputs< 1 >()

template<>
auto nestOutputs< 1 > ( int offset,
size_t length )

Definition at line 95 of file test-hdf5-writer.cxx.

95 {
96 return getOutputs(offset, length, 0.5);
97}