ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
SelectionHelpers
Root
ISelectionAccessor.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
//
9
// includes
10
//
11
12
#include <
AsgMessaging/StatusCode.h
>
13
#include <
SelectionHelpers/SelectionReadAccessorBits.h
>
14
#include <
SelectionHelpers/SelectionReadAccessorChar.h
>
15
#include <
SelectionHelpers/SelectionWriteAccessorBits.h
>
16
#include <
SelectionHelpers/SelectionWriteAccessorChar.h
>
17
#include <
SelectionHelpers/SelectionWriteAccessorSys.h
>
18
#include <
SelectionHelpers/SelectionAccessorList.h
>
19
#include <
SelectionHelpers/SelectionReadAccessorNull.h
>
20
#include <
SelectionHelpers/SelectionAccessorReadSys.h
>
21
#include <
SelectionHelpers/SelectionExprParser.h
>
22
#include <
SelectionHelpers/SelectionReadAccessorInvert.h
>
23
#include <
SelectionHelpers/SelectionWriteAccessorInvert.h
>
24
#include <exception>
25
26
//
27
// method implementations
28
//
29
30
namespace
CP
31
{
32
namespace
33
{
34
std::vector<std::string>
35
splitString
(
const
std::string& input,
const
std::string& separator)
36
{
37
std::vector<std::string>
result
;
38
std::string::size_type
start
= 0,
split
= 0;
39
while
((
split
=
input
.find (separator, start)) != std::string::npos)
40
{
41
result
.emplace_back (
input
.substr (start,
split
- start));
42
start
=
split
+ separator.size();
43
}
44
result
.emplace_back (
input
.substr (start));
45
return
result
;
46
}
47
48
}
49
50
51
52
StatusCode
53
makeSelectionReadAccessor
(
const
std::string& expr,
54
std::unique_ptr<ISelectionReadAccessor>& accessor,
55
bool
defaultToChar)
56
{
57
using namespace
msgSelectionHelpers;
58
59
if
(expr.empty())
60
{
61
accessor = std::make_unique<SelectionReadAccessorNull> (
true
);
62
return
StatusCode::SUCCESS;
63
}
64
65
try
{
66
SelectionExprParser
parser(expr, defaultToChar);
67
ANA_CHECK
(parser.build(accessor));
68
}
catch
(
const
std::exception&
e
) {
69
ANA_MSG_FATAL
(
"Failure to parse expression: '"
<< expr <<
"': "
<<
e
.what());
70
return
StatusCode::FAILURE;
71
}
72
73
return
StatusCode::SUCCESS;
74
}
75
76
77
namespace
78
{
79
struct
SplitData final
80
{
81
std::string var;
82
bool
asChar =
false
;
83
bool
asBits =
false
;
84
bool
invert =
false
;
85
86
StatusCode
fill
(
const
std::string&
name
,
bool
defaultToChar)
87
{
88
using namespace
msgSelectionHelpers;
89
90
for
(
const
std::string& option :
splitString
(
name
,
","
))
91
{
92
if
(var.empty())
93
{
94
// this is a bit of a hack, it will pick up the first
95
// component as the decoration name
96
var = option;
97
}
else
if
(option ==
"as_char"
)
98
{
99
// using ",as_char" as a postfix to indicate char decorations
100
// (and ",as_bits" as a postfix to indicate bitset
101
// decorations). I chose that suffix as it should make it
102
// easier to read in configuration files and allows for future
103
// extensions if needed.
104
asChar =
true
;
105
}
else
if
(option ==
"as_bits"
)
106
{
107
asBits =
true
;
108
}
else
if
(option ==
"invert"
)
109
{
110
invert =
true
;
111
}
else
112
{
113
ANA_MSG_ERROR
(
"invalid option "
<< option <<
"for selection decoration"
);
114
return
StatusCode::FAILURE;
115
}
116
}
117
118
if
(asChar && asBits)
119
{
120
ANA_MSG_ERROR
(
"can't specify both 'as_bits' and 'as_char' for the same selection decoration, pick one!!!"
);
121
return
StatusCode::FAILURE;
122
}
123
124
if
(!asChar && !asBits)
125
{
126
if
(defaultToChar)
127
asChar =
true
;
128
else
129
asBits =
true
;
130
}
131
return
StatusCode::SUCCESS;
132
}
133
};
134
}
135
136
137
StatusCode
138
makeSelectionReadAccessorVar
(
const
std::string&
name
,
139
std::unique_ptr<ISelectionReadAccessor>& accessor,
140
bool
defaultToChar)
141
{
142
using namespace
msgSelectionHelpers;
143
144
if
(
name
.find (
"%SYS%"
) != std::string::npos)
145
{
146
accessor = std::make_unique<SelectionAccessorReadSys>(
name
);
147
return
StatusCode::SUCCESS;
148
}
149
150
SplitData splitData;
151
ANA_CHECK
(splitData.fill (
name
, defaultToChar));
152
153
if
(splitData.asChar)
154
accessor = std::make_unique<SelectionReadAccessorChar> (splitData.var);
155
else
156
accessor = std::make_unique<SelectionReadAccessorBits> (splitData.var);
157
158
if
(splitData.invert)
159
{
160
accessor = std::make_unique<SelectionReadAccessorInvert>
161
(std::move (accessor));
162
}
163
164
return
StatusCode::SUCCESS;
165
}
166
167
168
StatusCode
169
makeSelectionWriteAccessor
(
const
std::string&
name
,
170
std::unique_ptr<ISelectionWriteAccessor>& accessor,
171
bool
defaultToChar)
172
{
173
using namespace
msgSelectionHelpers;
174
175
if
(
name
.find (
"%SYS%"
) != std::string::npos)
176
{
177
accessor = std::make_unique<SelectionWriteAccessorSys>(
name
);
178
return
StatusCode::SUCCESS;
179
}
180
181
SplitData splitData;
182
ANA_CHECK
(splitData.fill (
name
, defaultToChar));
183
184
if
(splitData.asChar)
185
accessor = std::make_unique<SelectionWriteAccessorChar> (splitData.var);
186
else
187
accessor = std::make_unique<SelectionWriteAccessorBits> (splitData.var);
188
189
if
(splitData.invert)
190
{
191
accessor = std::make_unique<SelectionWriteAccessorInvert>
192
(std::move (accessor));
193
}
194
195
return
StatusCode::SUCCESS;
196
}
197
}
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
ANA_MSG_FATAL
#define ANA_MSG_FATAL(xmsg)
Macro printing fatal messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:296
StatusCode.h
splitString
std::vector< std::string > splitString(const std::string &in, std::string_view delim)
Definition
LArQuickHistMerge.cxx:429
SelectionAccessorList.h
SelectionAccessorReadSys.h
SelectionExprParser.h
SelectionReadAccessorBits.h
SelectionReadAccessorChar.h
SelectionReadAccessorInvert.h
SelectionReadAccessorNull.h
SelectionWriteAccessorBits.h
SelectionWriteAccessorChar.h
SelectionWriteAccessorInvert.h
SelectionWriteAccessorSys.h
CP::SelectionExprParser
Public interface for the expression parsing facility.
Definition
SelectionExprParser.h:80
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
CP::makeSelectionWriteAccessor
StatusCode makeSelectionWriteAccessor(const std::string &name, std::unique_ptr< ISelectionWriteAccessor > &accessor, bool defaultToChar)
Produces a simple ISelectionWriteAccessor accessing the given decoration.
Definition
ISelectionAccessor.cxx:169
CP::makeSelectionReadAccessorVar
StatusCode makeSelectionReadAccessorVar(const std::string &name, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
Produces a simple ISelectionReadAccessor accessing the given decoration.
Definition
ISelectionAccessor.cxx:138
CP::makeSelectionReadAccessor
StatusCode makeSelectionReadAccessor(const std::string &expr, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
make the ISelectionReadAccessor for the given name
Definition
ISelectionAccessor.cxx:53
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
WriteLumiToCool.input
dict input
Definition
WriteLumiToCool.py:174
get_generator_info.result
result
Definition
get_generator_info.py:21
mergePhysValFiles.start
start
Definition
DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:13
xAOD::name
name
Definition
TriggerMenuJson_v1.cxx:29
xAOD::e
setPy e
Definition
CompositeParticle_v1.cxx:166
fill
void fill(H5::Group &out_file, size_t iterations)
Definition
test-half-precision.cxx:64
Generated on
for ATLAS Offline Software by
1.17.0