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
17#include <AsgTools/SgEvent.h>
20#include <EventLoop/Worker.h>
22#include <TTree.h>
23#include <algorithm>
24#include <exception>
25
26//
27// method implementations
28//
29
30namespace EL
31{
32 namespace Detail
33 {
34 namespace
35 {
36 template<typename F> StatusCode
37 forAllAlgorithms (MsgStream& msg, ModuleData& data, const char *funcName, F&& func)
38 {
39 for (AlgorithmData& alg : data.m_algs)
40 {
41 try
42 {
43 typedef typename std::decay<decltype(func(alg))>::type scType__;
44 if (!::asg::CheckHelper<scType__>::isSuccess (func (alg)))
45 {
46 msg << MSG::ERROR << "executing " << funcName << " on algorithm " << alg->getName() << endmsg;
47 return StatusCode::FAILURE;
48 }
49 } catch (...)
50 {
51 report_exception (std::current_exception());
52 msg << MSG::ERROR << "executing " << funcName << " on algorithm " << alg->getName() << endmsg;
53 return StatusCode::FAILURE;
54 }
55 }
56 return StatusCode::SUCCESS;
57 }
58 }
59
60
61
62 StatusCode AlgorithmStateModule ::
63 onInitialize (ModuleData& data)
64 {
65 if (m_initialized)
66 {
67 ANA_MSG_ERROR ("getting second initialize call");
68 return StatusCode::FAILURE;
69 }
70 m_initialized = true;
71 AlgorithmWorkerData workerData;
72 workerData.m_histogramWorker = data.m_worker;
73 workerData.m_treeWorker = data.m_worker;
74 workerData.m_filterWorker = data.m_worker;
75 workerData.m_wk = data.m_worker;
76 workerData.m_evtStore = data.m_evtStore;
77 return forAllAlgorithms (msg(), data, "initialize", [&] (AlgorithmData& alg) {
78 return alg->initialize (workerData);});
79 }
80
81
82
83 StatusCode AlgorithmStateModule ::
84 onFinalize (ModuleData& data)
85 {
86 if (!m_initialized)
87 return StatusCode::SUCCESS;
88 if (forAllAlgorithms (msg(), data, "finalize", [&] (AlgorithmData& alg) {
89 return alg->finalize ();}).isFailure())
90 return StatusCode::FAILURE;
91 return StatusCode::SUCCESS;
92 }
93
94
95
96 StatusCode AlgorithmStateModule ::
97 onCloseInputFile (ModuleData& data)
98 {
99 return forAllAlgorithms (msg(), data, "endInputFile", [&] (AlgorithmData& alg) {
100 return alg->endInputFile ();});
101 }
102
103
104
105 StatusCode AlgorithmStateModule ::
106 onNewInputFile (ModuleData& data)
107 {
108 if (!m_initialized)
109 {
110 ANA_MSG_ERROR ("algorithms have not been initialized yet");
111 return StatusCode::FAILURE;
112 }
113
114 // Check that there are events on input
115 if (!data.m_hasInputEvents) return StatusCode::SUCCESS;
116
117 if (forAllAlgorithms (msg(), data, "changeInput", [&] (AlgorithmData& alg) {
118 return alg->beginInputFile ();}).isFailure())
119 return StatusCode::FAILURE;
120 return StatusCode::SUCCESS;
121 }
122
123
124
125 StatusCode AlgorithmStateModule ::
126 onFileExecute (ModuleData& data)
127 {
128 return forAllAlgorithms (msg(), data, "fileExecute", [&] (AlgorithmData& alg) {
129 return alg->fileExecute ();});
130 }
131
132
133
134 StatusCode AlgorithmStateModule ::
135 onExecute (ModuleData& data)
136 {
137 data.m_skipEvent = false;
138 bool sequenceSkip = false;
139 for (auto& algData : data.m_algs)
140 {
141 try
142 {
143 if (algData.m_sequenceStart)
144 sequenceSkip = false;
145 else if (sequenceSkip)
146 {
147 algData.m_wasSkipped = true;
148 continue;
149 }
150
151 algData.m_executeCount += 1;
152 if (algData.m_algorithm->execute() == StatusCode::FAILURE)
153 {
154 ANA_MSG_ERROR ("while calling execute() on algorithm " << algData.m_algorithm->getName());
155 return StatusCode::FAILURE;
156 }
157
158 if (data.m_skipEvent)
159 {
160 algData.m_skipCount += 1;
161 algData.m_wasSkipped = true;
162 sequenceSkip = true;
163 data.m_skipEvent = false;
164 }
165 } catch (...)
166 {
167 Detail::report_exception (std::current_exception());
168 ANA_MSG_ERROR ("while calling execute() on algorithm " << algData.m_algorithm->getName());
169 return StatusCode::FAILURE;
170 }
171 }
172
173 for (auto& algData : data.m_algs)
174 {
175 try
176 {
177 // This will skip `postExecute` for all algorithms that called
178 // `setFilterPassed(false)` or that were skipped because of a
179 // prior algorithm calling `setFilterPassed(false)`.
180 if (algData.m_wasSkipped)
181 {
182 algData.m_wasSkipped = false;
183 continue;
184 }
185 if (algData.m_algorithm->postExecute() == StatusCode::FAILURE)
186 {
187 ANA_MSG_ERROR ("while calling postExecute() on algorithm " << algData.m_algorithm->getName());
188 return StatusCode::FAILURE;
189 }
190 } catch (...)
191 {
192 Detail::report_exception (std::current_exception());
193 ANA_MSG_ERROR ("while calling postExecute() on algorithm " << algData.m_algorithm->getName());
194 return StatusCode::FAILURE;
195 }
196 }
197
198 return StatusCode::SUCCESS;
199 }
200 }
201}
#define endmsg
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
#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