ATLAS Offline Software
Loading...
Searching...
No Matches
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
14
18#include <AsgTools/SgEvent.h>
21#include <EventLoop/Worker.h>
23#include <TTree.h>
24#include <algorithm>
25#include <exception>
26
27//
28// method implementations
29//
30
31namespace 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}
#define endmsg
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define F(x, y, z)
Definition MD5.cxx:112
bool m_initialized
whether Algorithm::initialize has been called
void report_exception(std::exception_ptr eptr)
print out the currently evaluated exception
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
all the external components an algorithm needs before initialization (in EventLoop)
IHistogramWorker * m_histogramWorker
all the data a worker tracks for an individual algorithm
the data the EventLoop core classes are sharing with the Module implementation
Definition ModuleData.h:65
MsgStream & msg
Definition testRead.cxx:32