ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
AnalysisCommon
HDF5Utils
util
test-hdf5-writer.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
HDF5Utils/Writer.h
"
6
7
//-------------------------------------------------------------------------
8
// output data structure
9
struct
out_t
10
{
11
double
dtype
;
12
float
ftype
;
13
char
ctype
;
14
short
stype
;
15
int
itype
;
16
long
ltype
;
17
long
long
lltype
;
18
unsigned
char
uctype
;
19
unsigned
short
ustype
;
20
unsigned
int
uitype
;
21
unsigned
long
ultype
;
22
unsigned
long
long
ulltype
;
23
bool
btype
;
24
};
25
using
consumer_t
=
H5Utils::Consumers<const out_t&>
;
26
27
consumer_t
getConsumers
() {
28
consumer_t
consumers;
29
#define ADD(NAME) consumers.add(#NAME, [](const out_t& o){ return o.NAME;}, 0)
30
ADD
(ctype);
31
ADD
(stype);
32
ADD
(itype);
33
ADD
(ltype);
34
ADD
(lltype);
35
ADD
(uctype);
36
ADD
(ustype);
37
ADD
(uitype);
38
ADD
(ultype);
39
ADD
(ulltype);
40
ADD
(ftype);
41
ADD
(dtype);
42
ADD
(btype);
43
#undef ADD
44
H5Utils::Compression
half =
H5Utils::Compression::HALF_PRECISION
;
45
consumers.
add
(
"half"
, [](
const
out_t
& o) {
return
o.
ftype
; }, 0, half);
46
consumers.
add
(
"dhalf"
, [](
const
out_t
& o) {
return
o.
dtype
; }, 0, half);
47
return
consumers;
48
}
49
50
//-------------------------------------------------------------------------
51
// outputs
52
53
std::vector<out_t>
getOutputs
(
int
offset,
size_t
length
,
float
factor) {
54
std::vector<out_t> outvec;
55
for
(
size_t
n = 0; n <
length
; n++) {
56
out_t
out;
57
long
long
int
shifted = n + offset;
58
double
factored = shifted*factor;
59
out.dtype = factored;
60
out.ftype = factored;
61
out.ctype = shifted;
62
out.stype = shifted;
63
out.itype = shifted;
64
out.ltype = shifted;
65
out.lltype = shifted;
66
out.uctype = shifted;
67
out.ustype = shifted;
68
out.uitype = shifted;
69
out.ultype = shifted;
70
out.ulltype = shifted;
71
out.btype = n % 2;
72
outvec.push_back(out);
73
}
74
return
outvec;
75
}
76
77
template
<
size_t
N>
78
auto
nestOutputs
(
int
offset,
size_t
length
) {
79
using
ret_t =
decltype
(
80
nestOutputs
<N-1>(std::declval<int>(),std::declval<size_t>()));
81
std::vector<ret_t> ret;
82
for
(
size_t
n = 0; n <
length
; n++) {
83
ret.push_back(
nestOutputs<N-1>
(n + offset,
length
+ 1));
84
}
85
return
ret;
86
}
87
template
<>
88
auto
nestOutputs<1>
(
int
offset,
size_t
length
) {
89
return
getOutputs
(offset,
length
, 0.5);
90
}
91
92
//-------------------------------------------------------------------------
93
// main routine
94
95
void
fill
(H5::Group& out_file,
size_t
iterations) {
96
97
const
int
deflate = 7;
98
99
// scalar output
100
using
scalar_writer_t =
H5Utils::Writer<0, consumer_t::input_type>
;
101
scalar_writer_t::configuration_type scalar_config{};
102
scalar_config.name =
"scalar"
;
103
scalar_config.deflate = deflate;
104
consumer_t
consumers =
getConsumers
();
105
scalar_writer_t scalar(out_file, consumers, scalar_config);
106
for
(
size_t
n = 0; n < iterations; n++) {
107
scalar.fill(
getOutputs
(1 + n, 1, 0.5).at(0));
108
}
109
110
// 1d output
111
using
d1_t =
H5Utils::Writer<1, consumer_t::input_type>
;
112
d1_t::configuration_type d1_config{};
113
d1_config.name =
"1d"
;
114
d1_config.extent = {10};
115
d1_config.chunks = {5};
116
d1_config.deflate = deflate;
117
d1_t d1(out_file, consumers, d1_config);
118
for
(
size_t
n = 0; n < iterations; n++) {
119
d1.fill(
getOutputs
(n, 10, 0.5));
120
}
121
122
// 4d output
123
using
d4_t =
H5Utils::Writer<4, consumer_t::input_type>
;
124
d4_t::configuration_type d4_config;
125
d4_config.name =
"4d"
;
126
d4_config.extent = {2,3,4,5};
127
d4_config.chunks = {1,2,1,2};
128
d4_config.deflate = deflate;
129
d4_t d4(out_file, consumers, d4_config);
130
for
(
size_t
n = 0; n < iterations; n++) {
131
auto
vals =
nestOutputs<4>
(n, 2);
132
// store some specific value to make sure we have the indexing
133
// right
134
vals.at(1).at(2).at(3).at(4).stype = 86;
135
d4.fill(std::move(vals));
136
}
137
}
138
//coverity[root_function]
139
int
main
(
int
nargs,
char
* argv[]) {
140
H5::H5File out_file(
"output.h5"
, H5F_ACC_TRUNC);
141
size_t
iterations = 1;
142
if
(nargs > 2) {
143
return
1;
144
}
145
if
(nargs > 1) iterations = std::atoi(argv[1]);
146
//coverity[TAINTED_SCALAR]
147
fill
(out_file, iterations);
148
return
0;
149
}
length
double length(const pvec &v)
Definition
FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
Writer.h
H5Utils::Consumers
Definition
Writer.h:130
H5Utils::Consumers::add
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:165
H5Utils::Writer
Writer.
Definition
Writer.h:351
main
int main()
Definition
hello.cxx:18
H5Utils::Compression
Compression
Definition
CompressionEnums.h:11
H5Utils::Compression::HALF_PRECISION
@ HALF_PRECISION
Definition
CompressionEnums.h:11
out_t
Definition
test-half-precision.cxx:12
out_t::itype
int itype
Definition
test-hdf5-writer.cxx:15
out_t::btype
bool btype
Definition
test-half-precision.cxx:15
out_t::ulltype
unsigned long long ulltype
Definition
test-hdf5-writer.cxx:22
out_t::lltype
long long lltype
Definition
test-hdf5-writer.cxx:17
out_t::ctype
char ctype
Definition
test-hdf5-writer.cxx:13
out_t::ltype
long ltype
Definition
test-hdf5-writer.cxx:16
out_t::ultype
unsigned long ultype
Definition
test-hdf5-writer.cxx:21
out_t::uctype
unsigned char uctype
Definition
test-hdf5-writer.cxx:18
out_t::uitype
unsigned int uitype
Definition
test-hdf5-writer.cxx:20
out_t::ftype
float ftype
Definition
test-half-precision.cxx:14
out_t::stype
short stype
Definition
test-hdf5-writer.cxx:14
out_t::dtype
double dtype
Definition
test-half-precision.cxx:13
out_t::ustype
unsigned short ustype
Definition
test-hdf5-writer.cxx:19
consumer_t
H5Utils::Consumers< const out_t & > consumer_t
Definition
test-half-precision.cxx:17
getConsumers
consumer_t getConsumers()
Definition
test-hdf5-writer.cxx:27
fill
void fill(H5::Group &out_file, size_t iterations)
Definition
test-hdf5-writer.cxx:95
ADD
#define ADD(NAME)
nestOutputs< 1 >
auto nestOutputs< 1 >(int offset, size_t length)
Definition
test-hdf5-writer.cxx:88
nestOutputs
auto nestOutputs(int offset, size_t length)
Definition
test-hdf5-writer.cxx:78
getOutputs
std::vector< out_t > getOutputs(int offset, size_t length, float factor)
Definition
test-hdf5-writer.cxx:53
Generated on
for ATLAS Offline Software by
1.17.0