ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
CommonTools
ExpressionEvaluation
src
GenAccessor.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
#ifndef _ExpressionEvaluation_GenAccessor_h_
5
#define _ExpressionEvaluation_GenAccessor_h_
6
7
#include "
StoreGate/ReadHandleKey.h
"
8
#include "
StoreGate/ReadHandle.h
"
9
#include "
ExpressionEvaluation/IProxyLoader.h
"
10
11
#include "
BaseAccessor.h
"
12
13
#include <vector>
14
15
namespace
ExpressionParsing
{
16
19
class
ScalarHelper
{
20
public
:
21
template
<
class
T_Dest,
class
T_Cont,
class
T_Helper>
22
static
void
fillVector
(T_Helper &helper,
SG::ReadHandle<T_Cont>
&handle, std::vector<T_Dest> &result) {
23
result.reserve(1);
24
auto
val = helper.get( *handle );
25
// @TODO or throw an exception if the type conversion is not loss-less?
26
assert( val ==
static_cast<
decltype(val)
>
(
static_cast<
T_Dest
>
(val)));
27
result.push_back(
static_cast<
T_Dest
>
(val));
28
}
29
30
template
<
class
T_Dest,
class
T_Cont,
class
T_Helper>
31
static
T_Dest
getScalar
(T_Helper &helper,
SG::ReadHandle<T_Cont>
&handle,
const
T_Dest &dummy) {
32
(void) dummy;
33
auto
val = helper.get( *handle );
34
// @TODO or throw an exception if the type conversion is not loss-less?
35
assert( val ==
static_cast<
decltype(val)
>
(
static_cast<
T_Dest
>
(val)));
36
return
static_cast<
T_Dest
>
( val );
37
}
38
};
39
42
class
VectorHelper
{
43
public
:
44
template
<
class
T_Dest,
class
T_Cont,
class
T_Helper>
45
static
void
fillVector
(T_Helper &helper,
SG::ReadHandle<T_Cont>
&handle, std::vector<T_Dest> &result) {
46
std::size_t n_elements=helper.size(*handle);
47
// helper.checkSize(n_elements);
48
result.reserve(n_elements);
49
for
(std::size_t idx =0; idx <n_elements; ++idx) {
50
auto
val = helper.get(*handle, idx);
51
// @TODO or throw an exception if the type conversion is not loss-less?
52
assert( val ==
static_cast<
decltype(val)
>
(
static_cast<
T_Dest
>
(val)));
53
result.push_back(
static_cast<
T_Dest
>
( val ) );
54
}
55
}
56
template
<
class
T_Dest,
class
T_Cont,
class
T_Helper>
57
static
T_Dest
getScalar
(T_Helper &helper,
SG::ReadHandle<T_Cont>
&handle,
const
T_Dest &dummy) {
58
(void) dummy;
59
if
(
getContainerSize
(*handle) != 1) {
60
BaseAccessor::throwVectorContainsNotOneElement
(handle.key(),
getContainerSize
(*handle));
61
}
62
auto
val = helper.get(*handle, 0);
63
// @TODO or throw an exception if the type conversion is not loss-less?
64
assert( val ==
static_cast<
decltype(val)
>
(
static_cast<
T_Dest
>
(val)));
65
return
static_cast<
T_Dest
>
(val);
66
}
67
};
68
73
template
<
class
T_Cont,
class
T_HelperKit,
class
T_ScalarVectorHelper>
74
class
GenAccessor
:
public
BaseAccessor
{
75
public
:
76
GenAccessor
(
const
SG::ReadHandleKey<T_Cont>
&key, T_HelperKit &&helper_kit,
IAccessor::VariableType
variable_type)
77
:
BaseAccessor
(variable_type),
78
m_key
(&key),
79
m_helperKit
(
std
::move(helper_kit))
80
{}
81
82
virtual
int
loadInt
(
const
EventContext& ctx, [[maybe_unused]]
const
std::string &var_name)
const override
{
83
return
this->
loadScalar<int>
(ctx);
84
}
85
virtual
double
loadDouble
(
const
EventContext& ctx, [[maybe_unused]]
const
std::string &var_name)
const override
{
86
return
this->
loadScalar<double>
(ctx);
87
}
88
virtual
std::vector<int>
loadVecInt
(
const
EventContext& ctx, [[maybe_unused]]
const
std::string &var_name)
const override
{
89
return
this->
loadVector<int>
(ctx);
90
}
91
virtual
std::vector<double>
loadVec
(
const
EventContext& ctx, [[maybe_unused]]
const
std::string &var_name)
const override
{
92
return
this->
loadVector<double>
(ctx);
93
}
94
protected
:
95
template
<
class
T_Dest>
96
std::vector<T_Dest>
loadVector
(
const
EventContext& ctx)
const
{
97
SG::ReadHandle<T_Cont>
handle(*this->
m_key
, ctx);
98
if
(!handle.isValid()) {
99
this->
throwInvalidHandle
(this->
m_key
->key());
100
}
101
std::vector<T_Dest> result;
102
if
(
getContainerSize
(*handle)>0) {
103
auto
helper(
m_helperKit
.create(ctx, handle));
104
T_ScalarVectorHelper::fillVector(helper, handle,result);
105
}
106
return
result;
107
}
108
109
template
<
class
T_Dest>
110
T_Dest
loadScalar
(
const
EventContext& ctx)
const
{
111
SG::ReadHandle<T_Cont>
handle(*this->
m_key
, ctx);
112
if
(!handle.isValid()) {
113
this->
throwInvalidHandle
(this->
m_key
->key());
114
}
115
auto
helper(
m_helperKit
.create(ctx, handle));
116
T_Dest dummy {};
117
return
T_ScalarVectorHelper::getScalar(helper, handle, dummy);
118
}
119
120
const
SG::ReadHandleKey<T_Cont>
*
m_key
;
//< key to access the xAOD container
121
T_HelperKit
m_helperKit
;
//< auxiliary class to create an access helper
122
};
123
}
124
#endif
BaseAccessor.h
IProxyLoader.h
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
ReadHandle.h
Handle class for reading from StoreGate.
ExpressionParsing::BaseAccessor::throwVectorContainsNotOneElement
static void throwVectorContainsNotOneElement(const std::string &key, std::size_t n_elements)
Definition
BaseAccessor.h:25
ExpressionParsing::BaseAccessor::BaseAccessor
BaseAccessor(IAccessor::VariableType variable_type)
Definition
BaseAccessor.h:18
ExpressionParsing::BaseAccessor::throwInvalidHandle
static void throwInvalidHandle(const std::string &key)
Definition
BaseAccessor.h:20
ExpressionParsing::GenAccessor::GenAccessor
GenAccessor(const SG::ReadHandleKey< T_Cont > &key, T_HelperKit &&helper_kit, IAccessor::VariableType variable_type)
Definition
GenAccessor.h:76
ExpressionParsing::GenAccessor::loadVec
virtual std::vector< double > loadVec(const EventContext &ctx, const std::string &var_name) const override
Definition
GenAccessor.h:91
ExpressionParsing::GenAccessor::m_key
const SG::ReadHandleKey< T_Cont > * m_key
Definition
GenAccessor.h:120
ExpressionParsing::GenAccessor::loadInt
virtual int loadInt(const EventContext &ctx, const std::string &var_name) const override
Definition
GenAccessor.h:82
ExpressionParsing::GenAccessor::loadVecInt
virtual std::vector< int > loadVecInt(const EventContext &ctx, const std::string &var_name) const override
Definition
GenAccessor.h:88
ExpressionParsing::GenAccessor::loadVector
std::vector< T_Dest > loadVector(const EventContext &ctx) const
Definition
GenAccessor.h:96
ExpressionParsing::GenAccessor::m_helperKit
T_HelperKit m_helperKit
Definition
GenAccessor.h:121
ExpressionParsing::GenAccessor::loadScalar
T_Dest loadScalar(const EventContext &ctx) const
Definition
GenAccessor.h:110
ExpressionParsing::GenAccessor::loadDouble
virtual double loadDouble(const EventContext &ctx, const std::string &var_name) const override
Definition
GenAccessor.h:85
ExpressionParsing::IAccessor::VariableType
VariableType
Definition
IAccessor.h:19
ExpressionParsing::ScalarHelper
Auxiliary class to handle scalar like containers (AuxElement).
Definition
GenAccessor.h:19
ExpressionParsing::ScalarHelper::fillVector
static void fillVector(T_Helper &helper, SG::ReadHandle< T_Cont > &handle, std::vector< T_Dest > &result)
Definition
GenAccessor.h:22
ExpressionParsing::ScalarHelper::getScalar
static T_Dest getScalar(T_Helper &helper, SG::ReadHandle< T_Cont > &handle, const T_Dest &dummy)
Definition
GenAccessor.h:31
ExpressionParsing::VectorHelper
Auxiliary class to handle vector like containers (AuxVectorBase).
Definition
GenAccessor.h:42
ExpressionParsing::VectorHelper::fillVector
static void fillVector(T_Helper &helper, SG::ReadHandle< T_Cont > &handle, std::vector< T_Dest > &result)
Definition
GenAccessor.h:45
ExpressionParsing::VectorHelper::getScalar
static T_Dest getScalar(T_Helper &helper, SG::ReadHandle< T_Cont > &handle, const T_Dest &dummy)
Definition
GenAccessor.h:57
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition
StoreGate/StoreGate/ReadHandleKey.h:40
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
ExpressionParsing
Namespace holding all the expression evaluation code.
Definition
ExpressionParser.h:26
ExpressionParsing::getContainerSize
std::size_t getContainerSize(const T &cont)
Definition
PhysicsAnalysis/CommonTools/ExpressionEvaluation/src/Utils.h:73
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0