ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoop
Root
AlgorithmStateModule.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
9
//
10
// includes
11
//
12
13
#include <
EventLoop/AlgorithmStateModule.h
>
14
15
#include <
AnaAlgorithm/AlgorithmWorkerData.h
>
16
#include <
AnaAlgorithm/IAlgorithmWrapper.h
>
17
#include <
AsgTools/CurrentContext.h
>
18
#include <
AsgTools/SgEvent.h
>
19
#include <
EventLoop/MessageCheck.h
>
20
#include <
EventLoop/ModuleData.h
>
21
#include <
EventLoop/Worker.h
>
22
#include <
RootCoreUtils/Assert.h
>
23
#include <TTree.h>
24
#include <algorithm>
25
#include <exception>
26
27
//
28
// method implementations
29
//
30
31
namespace
EL
32
{
33
namespace
Detail
34
{
35
namespace
36
{
37
template
<
typename
F>
StatusCode
38
forAllAlgorithms (MsgStream&
msg
,
ModuleData
& data,
const
char
*funcName,
F
&& func)
39
{
40
for
(
AlgorithmData
& alg :
data
.m_algs)
41
{
42
try
43
{
44
typedef
typename
std::decay<
decltype
(
func
(alg))>::type scType__;
45
if
(!::asg::CheckHelper<scType__>::isSuccess (func (alg)))
46
{
47
msg
<< MSG::ERROR <<
"executing "
<< funcName <<
" on algorithm "
<<
alg
->getName() <<
endmsg
;
48
return
StatusCode::FAILURE;
49
}
50
}
catch
(...)
51
{
52
report_exception
(std::current_exception());
53
msg
<< MSG::ERROR <<
"executing "
<< funcName <<
" on algorithm "
<<
alg
->getName() <<
endmsg
;
54
return
StatusCode::FAILURE;
55
}
56
}
57
return
StatusCode::SUCCESS;
58
}
59
}
60
61
62
63
StatusCode
AlgorithmStateModule ::
64
onInitialize (
ModuleData
& data)
65
{
66
if
(
m_initialized
)
67
{
68
ANA_MSG_ERROR
(
"getting second initialize call"
);
69
return
StatusCode::FAILURE;
70
}
71
m_initialized
=
true
;
72
AlgorithmWorkerData
workerData;
73
workerData.
m_histogramWorker
= data.m_worker;
74
workerData.
m_treeWorker
= data.m_worker;
75
workerData.
m_filterWorker
= data.m_worker;
76
workerData.
m_wk
= data.m_worker;
77
workerData.
m_evtStore
= data.m_evtStore;
78
return
forAllAlgorithms (
msg
(), data,
"initialize"
, [&] (
AlgorithmData
& alg) {
79
return
alg->initialize (workerData);});
80
}
81
82
83
84
StatusCode
AlgorithmStateModule ::
85
onFinalize (
ModuleData
& data)
86
{
87
if
(!
m_initialized
)
88
return
StatusCode::SUCCESS;
89
if
(forAllAlgorithms (
msg
(), data,
"finalize"
, [&] (
AlgorithmData
& alg) {
90
return
alg->finalize ();}).isFailure())
91
return
StatusCode::FAILURE;
92
return
StatusCode::SUCCESS;
93
}
94
95
96
97
StatusCode
AlgorithmStateModule ::
98
onCloseInputFile (
ModuleData
& data)
99
{
100
return
forAllAlgorithms (
msg
(), data,
"endInputFile"
, [&] (
AlgorithmData
& alg) {
101
return
alg->endInputFile ();});
102
}
103
104
105
106
StatusCode
AlgorithmStateModule ::
107
onNewInputFile (
ModuleData
& data)
108
{
109
if
(!
m_initialized
)
110
{
111
ANA_MSG_ERROR
(
"algorithms have not been initialized yet"
);
112
return
StatusCode::FAILURE;
113
}
114
115
// Check that there are events on input
116
if
(!data.m_hasInputEvents)
return
StatusCode::SUCCESS;
117
118
if
(forAllAlgorithms (
msg
(), data,
"changeInput"
, [&] (
AlgorithmData
& alg) {
119
return
alg->beginInputFile ();}).isFailure())
120
return
StatusCode::FAILURE;
121
return
StatusCode::SUCCESS;
122
}
123
124
125
126
StatusCode
AlgorithmStateModule ::
127
onFileExecute (
ModuleData
& data)
128
{
129
return
forAllAlgorithms (
msg
(), data,
"fileExecute"
, [&] (
AlgorithmData
& alg) {
130
return
alg->fileExecute ();});
131
}
132
133
134
135
StatusCode
AlgorithmStateModule ::
136
onExecute (
ModuleData
& data)
137
{
138
data.m_skipEvent =
false
;
139
bool
sequenceSkip =
false
;
140
const
EventContext& ctx = Gaudi::Hive::currentContext();
141
for
(
auto
& algData : data.m_algs)
142
{
143
try
144
{
145
if
(algData.m_sequenceStart)
146
sequenceSkip =
false
;
147
else
if
(sequenceSkip)
148
{
149
algData.m_wasSkipped =
true
;
150
continue
;
151
}
152
153
algData.m_executeCount += 1;
154
if
(algData.m_algorithm->execute(ctx) == StatusCode::FAILURE)
155
{
156
ANA_MSG_ERROR
(
"while calling execute() on algorithm "
<< algData.m_algorithm->getName());
157
return
StatusCode::FAILURE;
158
}
159
160
if
(data.m_skipEvent)
161
{
162
algData.m_skipCount += 1;
163
algData.m_wasSkipped =
true
;
164
sequenceSkip =
true
;
165
data.m_skipEvent =
false
;
166
}
167
}
catch
(...)
168
{
169
Detail::report_exception
(std::current_exception());
170
ANA_MSG_ERROR
(
"while calling execute() on algorithm "
<< algData.m_algorithm->getName());
171
return
StatusCode::FAILURE;
172
}
173
}
174
175
for
(
auto
& algData : data.m_algs)
176
{
177
try
178
{
179
// This will skip `postExecute` for all algorithms that called
180
// `setFilterPassed(false)` or that were skipped because of a
181
// prior algorithm calling `setFilterPassed(false)`.
182
if
(algData.m_wasSkipped)
183
{
184
algData.m_wasSkipped =
false
;
185
continue
;
186
}
187
if
(algData.m_algorithm->postExecute() == StatusCode::FAILURE)
188
{
189
ANA_MSG_ERROR
(
"while calling postExecute() on algorithm "
<< algData.m_algorithm->getName());
190
return
StatusCode::FAILURE;
191
}
192
}
catch
(...)
193
{
194
Detail::report_exception
(std::current_exception());
195
ANA_MSG_ERROR
(
"while calling postExecute() on algorithm "
<< algData.m_algorithm->getName());
196
return
StatusCode::FAILURE;
197
}
198
}
199
200
return
StatusCode::SUCCESS;
201
}
202
}
203
}
AlgorithmStateModule.h
AlgorithmWorkerData.h
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
Assert.h
CurrentContext.h
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
IAlgorithmWrapper.h
F
#define F(x, y, z)
Definition
MD5.cxx:112
ModuleData.h
MessageCheck.h
SgEvent.h
Worker.h
EL::Detail::AlgorithmStateModule::m_initialized
bool m_initialized
whether Algorithm::initialize has been called
Definition
AlgorithmStateModule.h:61
CaloCondBlobAlgs_fillNoiseFromASCII.data
data
Definition
CaloCondBlobAlgs_fillNoiseFromASCII.py:94
EL::Detail
Definition
AsgComponentFactories.h:20
EL::Detail::report_exception
void report_exception(std::exception_ptr eptr)
print out the currently evaluated exception
Definition
PhysicsAnalysis/D3PDTools/EventLoop/Root/MessageCheck.cxx:27
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition
AsgComponentFactories.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
L1CaloPhase1Monitoring.func
func
Definition
L1CaloPhase1Monitoring.py:216
RegSelToolConfig.alg
alg
Definition
RegSelToolConfig.py:330
EL::AlgorithmWorkerData
all the external components an algorithm needs before initialization (in EventLoop)
Definition
AlgorithmWorkerData.h:34
EL::AlgorithmWorkerData::m_filterWorker
IFilterWorker * m_filterWorker
Definition
AlgorithmWorkerData.h:38
EL::AlgorithmWorkerData::m_treeWorker
ITreeWorker * m_treeWorker
Definition
AlgorithmWorkerData.h:37
EL::AlgorithmWorkerData::m_evtStore
asg::SgEvent * m_evtStore
Definition
AlgorithmWorkerData.h:35
EL::AlgorithmWorkerData::m_wk
IWorker * m_wk
Definition
AlgorithmWorkerData.h:39
EL::AlgorithmWorkerData::m_histogramWorker
IHistogramWorker * m_histogramWorker
Definition
AlgorithmWorkerData.h:36
EL::Detail::AlgorithmData
all the data a worker tracks for an individual algorithm
Definition
AlgorithmData.h:28
EL::Detail::ModuleData
the data the EventLoop core classes are sharing with the Module implementation
Definition
ModuleData.h:65
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0