ATLAS Offline Software
Loading...
Searching...
No Matches
AlgorithmStateModule.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9//
10// includes
11//
12
14
17#include <AsgTools/SgTEvent.h>
20#include <EventLoop/Worker.h>
22#include <TTree.h>
23#include <exception>
24
25//
26// method implementations
27//
28
29namespace EL
30{
31 namespace Detail
32 {
33 namespace
34 {
35 template<typename F> StatusCode
36 forAllAlgorithms (MsgStream& msg, ModuleData& data, const char *funcName, F&& func)
37 {
38 for (AlgorithmData& alg : data.m_algs)
39 {
40 try
41 {
42 typedef typename std::decay<decltype(func(alg))>::type scType__;
43 if (!::asg::CheckHelper<scType__>::isSuccess (func (alg)))
44 {
45 msg << MSG::ERROR << "executing " << funcName << " on algorithm " << alg->getName() << endmsg;
46 return StatusCode::FAILURE;
47 }
48 } catch (...)
49 {
50 report_exception (std::current_exception());
51 msg << MSG::ERROR << "executing " << funcName << " on algorithm " << alg->getName() << endmsg;
52 return StatusCode::FAILURE;
53 }
54 }
55 return StatusCode::SUCCESS;
56 }
57 }
58
59
60
61 StatusCode AlgorithmStateModule ::
62 onInitialize (ModuleData& data)
63 {
64 if (m_initialized)
65 {
66 ANA_MSG_ERROR ("getting second initialize call");
67 return StatusCode::FAILURE;
68 }
69 m_initialized = true;
70 AlgorithmWorkerData workerData;
71 workerData.m_histogramWorker = data.m_worker;
72 workerData.m_treeWorker = data.m_worker;
73 workerData.m_filterWorker = data.m_worker;
74 workerData.m_wk = data.m_worker;
75 workerData.m_evtStore = data.m_evtStore;
76 return forAllAlgorithms (msg(), data, "initialize", [&] (AlgorithmData& alg) {
77 return alg->initialize (workerData);});
78 }
79
80
81
82 StatusCode AlgorithmStateModule ::
83 onFinalize (ModuleData& data)
84 {
85 if (!m_initialized)
86 return StatusCode::SUCCESS;
87 if (forAllAlgorithms (msg(), data, "finalize", [&] (AlgorithmData& alg) {
88 return alg->finalize ();}).isFailure())
89 return StatusCode::FAILURE;
90 return StatusCode::SUCCESS;
91 }
92
93
94
95 StatusCode AlgorithmStateModule ::
96 onCloseInputFile (ModuleData& data)
97 {
98 return forAllAlgorithms (msg(), data, "endInputFile", [&] (AlgorithmData& alg) {
99 return alg->endInputFile ();});
100 }
101
102
103
104 StatusCode AlgorithmStateModule ::
105 onNewInputFile (ModuleData& data)
106 {
107 if (!m_initialized)
108 {
109 ANA_MSG_ERROR ("algorithms have not been initialized yet");
110 return StatusCode::FAILURE;
111 }
112
113 if (data.m_inputTree == nullptr ||
114 data.m_inputTree->GetEntries() == 0)
115 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 auto iter = data.m_algs.begin();
139 try
140 {
141 for (auto end = data.m_algs.end();
142 iter != end; ++ iter)
143 {
144 iter->m_executeCount += 1;
145 if (iter->m_algorithm->execute() == StatusCode::FAILURE)
146 {
147 ANA_MSG_ERROR ("while calling execute() on algorithm " << iter->m_algorithm->getName());
148 return StatusCode::FAILURE;
149 }
150
151 if (data.m_skipEvent)
152 {
153 iter->m_skipCount += 1;
154 return StatusCode::SUCCESS;
155 }
156 }
157 } catch (...)
158 {
159 Detail::report_exception (std::current_exception());
160 ANA_MSG_ERROR ("while calling execute() on algorithm " << iter->m_algorithm->getName());
161 return StatusCode::FAILURE;
162 }
163
166 try
167 {
168 for (auto jter = data.m_algs.begin(), end = iter;
169 jter != end && !data.m_skipEvent; ++ jter)
170 {
171 if (jter->m_algorithm->postExecute() == StatusCode::FAILURE)
172 {
173 ANA_MSG_ERROR ("while calling postExecute() on algorithm " << iter->m_algorithm->getName());
174 return StatusCode::FAILURE;
175 }
176 }
177 } catch (...)
178 {
179 Detail::report_exception (std::current_exception());
180 ANA_MSG_ERROR ("while calling postExecute() on algorithm " << iter->m_algorithm->getName());
181 return StatusCode::FAILURE;
182 }
183
184 return StatusCode::SUCCESS;
185 }
186 }
187}
#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:64
MsgStream & msg
Definition testRead.cxx:32