ATLAS Offline Software
Loading...
Searching...
No Matches
AlgorithmWrapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9//
10// includes
11//
12
14
17#include <EventLoop/Algorithm.h>
18#include <EventLoop/IWorker.h>
21#include <TTree.h>
22
23//
24// method implementations
25//
26
27namespace EL
28{
29 void AlgorithmWrapper ::
30 testInvariant () const
31 {
32 }
33
34
35
36 AlgorithmWrapper ::
37 AlgorithmWrapper (std::unique_ptr<Algorithm>&& val_algorithm)
38 : m_algorithm (std::move (val_algorithm))
39 {
40 RCU_NEW_INVARIANT (this);
41 }
42
43
44
45 std::string_view AlgorithmWrapper ::
46 getName () const
47 {
48 RCU_READ_INVARIANT (this);
49 return m_algorithm->GetName();
50 }
51
52
53
54 bool AlgorithmWrapper ::
55 hasName (const std::string& name) const
56 {
57 RCU_READ_INVARIANT (this);
58 return m_algorithm->hasName (name);
59 }
60
61
62
63 std::unique_ptr<IAlgorithmWrapper> AlgorithmWrapper ::
64 makeClone() const
65 {
66 using namespace msgAlgorithmConfig;
67 RCU_READ_INVARIANT (this);
68
69 std::unique_ptr<Algorithm> myalgorithm
70 (dynamic_cast<Algorithm*>(m_algorithm->Clone ()));
71 if (myalgorithm == nullptr)
72 RCU_THROW_MSG ("failed to clone algorithm " + std::string (m_algorithm->GetName()));
73 return std::make_unique<AlgorithmWrapper> (std::move (myalgorithm));
74 }
75
76
77
78 Algorithm *AlgorithmWrapper ::
79 getLegacyAlg ()
80 {
81 RCU_READ_INVARIANT (this);
82 return m_algorithm.get();
83 }
84
85
86
87 StatusCode AlgorithmWrapper ::
88 initialize (const AlgorithmWorkerData& workerData)
89 {
90 using namespace msgAlgorithmConfig;
92
93 m_algorithm->m_wk = workerData.m_wk;
94 m_algorithm->m_evtStorePtr = workerData.m_evtStore;
95 if (m_algorithm->histInitialize().isFailure())
96 {
97 ANA_MSG_ERROR ("failed to call histInitialize() on algorithm: " << m_algorithm->name());
98 return StatusCode::FAILURE;
99 }
100 return StatusCode::SUCCESS;
101 }
102
103
104
105 StatusCode AlgorithmWrapper ::
106 execute ()
107 {
108 using namespace msgAlgorithmConfig;
110
111 if (m_algorithm->execute().isFailure())
112 {
113 ANA_MSG_ERROR ("failed to call execute() on algorithm: " << m_algorithm->name());
114 return StatusCode::FAILURE;
115 }
116 return StatusCode::SUCCESS;
117 }
118
119
120
121 StatusCode AlgorithmWrapper ::
122 postExecute ()
123 {
124 using namespace msgAlgorithmConfig;
126
127 if (m_algorithm->postExecute().isFailure())
128 {
129 ANA_MSG_ERROR ("failed to call postExecute() on algorithm: " << m_algorithm->name());
130 return StatusCode::FAILURE;
131 }
132 return StatusCode::SUCCESS;
133 }
134
135
136
137 StatusCode AlgorithmWrapper ::
138 finalize ()
139 {
140 using namespace msgAlgorithmConfig;
142
143 if (m_isInitialized == true)
144 {
145 if (m_algorithm->finalize().isFailure())
146 {
147 ANA_MSG_ERROR ("failed to call finalize() on algorithm: " << m_algorithm->name());
148 return StatusCode::FAILURE;
149 }
150 }
151 if (m_algorithm->histFinalize().isFailure())
152 {
153 ANA_MSG_ERROR ("failed to call histFinalize() on algorithm: " << m_algorithm->name());
154 return StatusCode::FAILURE;
155 }
156 return StatusCode::SUCCESS;
157 }
158
159
160
161 ::StatusCode AlgorithmWrapper ::
162 fileExecute ()
163 {
164 using namespace msgAlgorithmConfig;
166
167 if (m_algorithm->fileExecute().isFailure())
168 {
169 ANA_MSG_ERROR ("failed to call fileExecute() on algorithm: " << m_algorithm->name());
170 return StatusCode::FAILURE;
171 }
172 return StatusCode::SUCCESS;
173 }
174
175
176
177 ::StatusCode AlgorithmWrapper ::
178 beginInputFile ()
179 {
180 using namespace msgAlgorithmConfig;
182
183 if (m_algorithm->changeInput(m_firstFile).isFailure())
184 {
185 ANA_MSG_ERROR ("failed to call changeInput() on algorithm: " << m_algorithm->name());
186 return StatusCode::FAILURE;
187 }
188 m_firstFile = false;
189 if (m_isInitialized == false &&
190 m_algorithm->m_wk->tree() != nullptr &&
191 m_algorithm->m_wk->tree()->GetEntries() > 0)
192 {
193 if (m_algorithm->initialize().isFailure())
194 {
195 ANA_MSG_ERROR ("failed to call initialize() on algorithm: " << m_algorithm->name());
196 return StatusCode::FAILURE;
197 }
198 m_isInitialized = true;
199 }
200 return StatusCode::SUCCESS;
201 }
202
203
204
205 ::StatusCode AlgorithmWrapper ::
206 endInputFile ()
207 {
208 using namespace msgAlgorithmConfig;
210
211 if (m_algorithm->endOfFile().isFailure())
212 {
213 ANA_MSG_ERROR ("failed to call endOfFile() on algorithm: " << m_algorithm->name());
214 return StatusCode::FAILURE;
215 }
216 return StatusCode::SUCCESS;
217 }
218}
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
bool m_isInitialized
whether Algorithm::initialize has been called
std::unique_ptr< Algorithm > m_algorithm
the actual algorithm
bool m_firstFile
whether this is the first file we encounter
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
STL namespace.
all the external components an algorithm needs before initialization (in EventLoop)