ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
JetH5Writer
src
PrimitiveHelpers.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
#ifndef PRIMATIVE_HELPERS_H
5
#define PRIMATIVE_HELPERS_H
6
7
#include "
JetH5Writer/Primitive.h
"
8
9
#include "
HDF5Utils/Writer.h
"
10
#include "
AthContainers/AuxElement.h
"
11
#include <functional>
//std::function
12
#include <type_traits>
//std::is_pointer
13
#include <cmath>
//NAN
14
#include <stdexcept>
15
16
// helper functions
17
namespace
detail
{
18
19
bool
isCustom
(
const
Primitive&);
20
bool
isCustom
(
const
Primitive::Type
&);
21
22
// build accessor
23
template
<
typename
T,
typename
I,
typename
A,
typename
S=T>
24
std::function<T(
I
)>
get
(
const
std::string & source,
A
ass
, T def) {
25
SG::AuxElement::ConstAccessor<S> acc(source);
26
using
rettype =
decltype
(
ass
(std::declval<I>()));
27
if
constexpr
(std::is_pointer<rettype>::value) {
28
return
[acc,
ass
, def](
I
in) -> T {
29
const
auto
* associated =
ass
(in);
30
if
(!associated)
return
def;
31
return
acc(*associated);
32
};
33
}
else
{
34
return
[acc,
ass
](
I
in) -> T {
return
acc(
ass
(in)); };
35
}
36
}
37
38
template
<
typename
T>
39
auto
defaultAccessor
= [](
typename
T::input_type in){
return
in; };
40
template
<
typename
T>
41
using
defaultAccessor_t
=
decltype
(
defaultAccessor<T>
);
42
43
using
uchar
=
unsigned
char;
44
using
uint
=
unsigned
int;
45
using
ushort
=
unsigned
short;
46
using
ull
=
unsigned
long
long;
47
using
ul
=
unsigned
long;
48
using
ll
=
long
long;
49
50
template
<
typename
T,
typename
A=defaultAccessor_t<T>>
51
void
addInput
(T& c,
const
Primitive
& input,
A
a
=
defaultAccessor<T>
) {
52
using
I
=
typename
T::input_type;
53
using
Tp
=
Primitive::Type
;
54
std::string s = input.source;
55
std::string t = input.target.empty() ? input.source : input.target;
56
const
auto
h
=
H5Utils::Compression::HALF_PRECISION
;
57
const
char
cz = char(0);
58
const
char
cm
= char(-1);
59
const
char
sm = short(-1);
60
switch
(input.type) {
61
case
Tp::PRECISION_CUSTOM:
// intentional fall-through
62
case
Tp::CUSTOM:
throw
std::logic_error(
"custom type unsupported"
);
63
case
Tp::UCHAR: c.add(t,
get<uchar,I,A>
(s,
a
,cz), cz);
return
;
64
case
Tp::CHAR: c.add(t,
get<char,I,A>
(s,
a
,
cm
),
cm
);
return
;
65
case
Tp::USHORT: c.add(t,
get<ushort,I,A>
(s,
a
,cz), cz);
return
;
66
case
Tp::SHORT: c.add(t,
get<short,I,A>
(s,
a
,sm), sm);
return
;
67
case
Tp::UINT: c.add(t,
get<uint,I,A>
(s,
a
,0), 0);
return
;
68
case
Tp::INT: c.add(t,
get<int,I,A>
(s,
a
,-1), -1);
return
;
69
case
Tp::ULONG: c.add(t,
get<ul,I,A>
(s,
a
,0), 0);
return
;
70
case
Tp::LONG: c.add(t,
get<long,I,A>
(s,
a
,-1), -1);
return
;
71
case
Tp::ULL: c.add(t,
get<ull,I,A>
(s,
a
,0), 0);
return
;
72
case
Tp::LL: c.add(t,
get<ll,I,A>
(s,
a
,-1), -1);
return
;
73
case
Tp::HALF: c.add(t,
get<float,I,A>
(s,
a
,NAN), NAN,
h
);
return
;
74
case
Tp::FLOAT: c.add(t,
get<float,I,A>
(s,
a
,NAN), NAN);
return
;
75
case
Tp::DOUBLE: c.add(t,
get<double,I,A>
(s,
a
,NAN), NAN);
return
;
76
case
Tp::UINT2UCHAR: c.add(t,
get<uchar,I,A,uint>
(s,
a
,0), 0);
return
;
77
case
Tp::INT2CHAR: c.add(t,
get<char,I,A,int>
(s,
a
,
cm
),
cm
);
return
;
78
case
Tp::UINT2USHORT: c.add(t,
get<ushort,I,A,uint>
(s,
a
,0), 0);
return
;
79
case
Tp::INT2SHORT: c.add(t,
get<short,I,A,int>
(s,
a
,sm), sm);
return
;
80
case
Tp::UL2ULL: c.add(t,
get<ull,I,A,ul>
(s,
a
,0),0);
return
;
81
}
82
}
83
}
84
85
#endif
AuxElement.h
Base class for elements of a container that can have aux data.
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
Tp
static Double_t Tp(Double_t *t, Double_t *par)
Definition
LArPhysWaveHECTool.cxx:354
I
#define I(x, y, z)
Definition
MD5.cxx:116
Primitive.h
cm
const double cm
Definition
Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
Writer.h
h
Header file for AthHistogramAlgorithm.
ass
make the histogram assessment part of the config
Definition
hcg.cxx:629
H5Utils::Compression::HALF_PRECISION
@ HALF_PRECISION
Definition
CompressionEnums.h:11
detail
Definition
extract_histogram_tag.cxx:14
detail::ul
unsigned long ul
Definition
PrimitiveHelpers.h:47
detail::addInput
void addInput(T &c, const Primitive &input, A a=defaultAccessor< T >)
Definition
PrimitiveHelpers.h:51
detail::uchar
unsigned char uchar
Definition
PrimitiveHelpers.h:43
detail::ull
unsigned long long ull
Definition
PrimitiveHelpers.h:46
detail::get
std::function< T(I)> get(const std::string &source, A ass, T def)
Definition
PrimitiveHelpers.h:24
detail::uint
unsigned int uint
Definition
PrimitiveHelpers.h:44
detail::isCustom
bool isCustom(const Primitive &p)
Definition
PrimitiveHelpers.cxx:10
detail::ll
long long ll
Definition
PrimitiveHelpers.h:48
detail::ushort
unsigned short ushort
Definition
PrimitiveHelpers.h:45
detail::defaultAccessor_t
decltype(defaultAccessor< T >) defaultAccessor_t
Definition
PrimitiveHelpers.h:41
detail::defaultAccessor
auto defaultAccessor
Definition
PrimitiveHelpers.h:39
A
hold the test vectors and ease the comparison
Primitive
Definition
Primitive.h:10
Primitive::Type
Type
Definition
Primitive.h:11
Generated on
for ATLAS Offline Software by
1.17.0