ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoop
Root
AlgorithmWrapper.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/AlgorithmWrapper.h
>
14
15
#include <
AnaAlgorithm/MessageCheck.h
>
16
#include <
AnaAlgorithm/AlgorithmWorkerData.h
>
17
#include <
EventLoop/Algorithm.h
>
18
#include <
EventLoop/IWorker.h
>
19
#include <
RootCoreUtils/Assert.h
>
20
21
#include <format>
22
#include <stdexcept>
23
24
//
25
// method implementations
26
//
27
28
namespace
EL
29
{
30
void
AlgorithmWrapper ::
31
testInvariant ()
const
32
{
33
RCU_INVARIANT
(
m_algorithm
!=
nullptr
);
34
}
35
36
37
38
AlgorithmWrapper ::
39
AlgorithmWrapper (std::unique_ptr<Algorithm>&& val_algorithm)
40
:
m_algorithm
(
std
::move (val_algorithm))
41
{
42
RCU_NEW_INVARIANT
(
this
);
43
}
44
45
46
47
std::string_view AlgorithmWrapper ::
48
getName ()
const
49
{
50
RCU_READ_INVARIANT
(
this
);
51
return
m_algorithm
->GetName();
52
}
53
54
55
56
bool
AlgorithmWrapper ::
57
hasName (
const
std::string& name)
const
58
{
59
RCU_READ_INVARIANT
(
this
);
60
return
m_algorithm
->hasName (name);
61
}
62
63
64
65
std::unique_ptr<IAlgorithmWrapper> AlgorithmWrapper ::
66
makeClone()
const
67
{
68
using namespace
msgAlgorithmConfig;
69
RCU_READ_INVARIANT
(
this
);
70
71
std::unique_ptr<Algorithm> myalgorithm
72
(
dynamic_cast<
Algorithm
*
>
(
m_algorithm
->Clone ()));
73
if
(myalgorithm ==
nullptr
)
74
throw
std::runtime_error (std::format (
"failed to clone algorithm {}"
,
m_algorithm
->GetName()));
75
return
std::make_unique<AlgorithmWrapper> (std::move (myalgorithm));
76
}
77
78
79
80
Algorithm
*AlgorithmWrapper ::
81
getLegacyAlg ()
82
{
83
RCU_READ_INVARIANT
(
this
);
84
return
m_algorithm
.get();
85
}
86
87
88
89
StatusCode
AlgorithmWrapper ::
90
initialize (
const
AlgorithmWorkerData
& workerData)
91
{
92
using namespace
msgAlgorithmConfig;
93
RCU_CHANGE_INVARIANT
(
this
);
94
95
m_algorithm
->m_wk = workerData.
m_wk
;
96
m_algorithm
->m_evtStorePtr = workerData.
m_evtStore
;
97
if
(
m_algorithm
->histInitialize().isFailure())
98
{
99
ANA_MSG_ERROR
(
"failed to call histInitialize() on algorithm: "
<<
m_algorithm
->name());
100
return
StatusCode::FAILURE;
101
}
102
return
StatusCode::SUCCESS;
103
}
104
105
106
107
StatusCode
AlgorithmWrapper ::
108
execute (
const
EventContext&
/*ctx*/
)
109
{
110
using namespace
msgAlgorithmConfig;
111
RCU_CHANGE_INVARIANT
(
this
);
112
113
if
(
m_algorithm
->execute().isFailure())
114
{
115
ANA_MSG_ERROR
(
"failed to call execute() on algorithm: "
<<
m_algorithm
->name());
116
return
StatusCode::FAILURE;
117
}
118
return
StatusCode::SUCCESS;
119
}
120
121
122
123
StatusCode
AlgorithmWrapper ::
124
postExecute ()
125
{
126
using namespace
msgAlgorithmConfig;
127
RCU_CHANGE_INVARIANT
(
this
);
128
129
if
(
m_algorithm
->postExecute().isFailure())
130
{
131
ANA_MSG_ERROR
(
"failed to call postExecute() on algorithm: "
<<
m_algorithm
->name());
132
return
StatusCode::FAILURE;
133
}
134
return
StatusCode::SUCCESS;
135
}
136
137
138
139
StatusCode
AlgorithmWrapper ::
140
finalize ()
141
{
142
using namespace
msgAlgorithmConfig;
143
RCU_CHANGE_INVARIANT
(
this
);
144
145
if
(
m_isInitialized
==
true
)
146
{
147
if
(
m_algorithm
->finalize().isFailure())
148
{
149
ANA_MSG_ERROR
(
"failed to call finalize() on algorithm: "
<<
m_algorithm
->name());
150
return
StatusCode::FAILURE;
151
}
152
}
153
if
(
m_algorithm
->histFinalize().isFailure())
154
{
155
ANA_MSG_ERROR
(
"failed to call histFinalize() on algorithm: "
<<
m_algorithm
->name());
156
return
StatusCode::FAILURE;
157
}
158
return
StatusCode::SUCCESS;
159
}
160
161
162
163
::StatusCode
AlgorithmWrapper ::
164
fileExecute ()
165
{
166
using namespace
msgAlgorithmConfig;
167
RCU_CHANGE_INVARIANT
(
this
);
168
169
if
(
m_algorithm
->fileExecute().isFailure())
170
{
171
ANA_MSG_ERROR
(
"failed to call fileExecute() on algorithm: "
<<
m_algorithm
->name());
172
return
StatusCode::FAILURE;
173
}
174
return
StatusCode::SUCCESS;
175
}
176
177
178
179
::StatusCode
AlgorithmWrapper ::
180
beginInputFile ()
181
{
182
using namespace
msgAlgorithmConfig;
183
RCU_CHANGE_INVARIANT
(
this
);
184
185
if
(
m_algorithm
->changeInput(
m_firstFile
).isFailure())
186
{
187
ANA_MSG_ERROR
(
"failed to call changeInput() on algorithm: "
<<
m_algorithm
->name());
188
return
StatusCode::FAILURE;
189
}
190
m_firstFile
=
false
;
191
if
(
m_isInitialized
==
false
&&
m_algorithm
->m_wk->hasInputEvents())
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;
209
RCU_CHANGE_INVARIANT
(
this
);
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
}
AlgorithmWorkerData.h
AlgorithmWrapper.h
Algorithm.h
Assert.h
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition
Assert.h:187
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition
Assert.h:219
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:217
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:295
IWorker.h
MessageCheck.h
EL::AlgorithmWrapper::m_isInitialized
bool m_isInitialized
whether Algorithm::initialize has been called
Definition
AlgorithmWrapper.h:77
EL::AlgorithmWrapper::m_algorithm
std::unique_ptr< Algorithm > m_algorithm
the actual algorithm
Definition
AlgorithmWrapper.h:71
EL::AlgorithmWrapper::m_firstFile
bool m_firstFile
whether this is the first file we encounter
Definition
AlgorithmWrapper.h:74
EL::Algorithm
Definition
Algorithm.h:22
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
std
STL namespace.
EL::AlgorithmWorkerData
all the external components an algorithm needs before initialization (in EventLoop)
Definition
AlgorithmWorkerData.h:34
EL::AlgorithmWorkerData::m_evtStore
asg::SgEvent * m_evtStore
Definition
AlgorithmWorkerData.h:35
EL::AlgorithmWorkerData::m_wk
IWorker * m_wk
Definition
AlgorithmWorkerData.h:39
Generated on
for ATLAS Offline Software by
1.17.0