ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaPython
python
PyAthenaComps.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3
# @file: PyAthenaComps.py
4
# @purpose: a set of Python classes for PyAthena
5
# @author: Sebastien Binet <binet@cern.ch>
6
7
__doc__ =
"""Module containing a set of Python base classes for PyAthena"""
8
__author__ =
"Sebastien Binet <binet@cern.ch>"
9
10
11
__all__ = [
'StatusCode'
,
12
'Alg'
,
13
'Svc'
,
14
'AlgTool'
,
15
'Aud'
,
16
'algs'
,
17
'services'
,
18
]
19
20
21
from
AthenaCommon.Configurable
import
*
# noqa: F401, F403
22
from
AthenaPython.Configurables
import
(CfgPyAlgorithm,
23
CfgPyService,
24
CfgPyAlgTool,
25
CfgPyAud)
26
27
28
import
weakref
29
class
WeakRefHolder
(object):
30
"""A convenient class to access py-components by name
31
"""
32
pass
33
def
__wk_setattr__
(self, k, v):
34
self.__setattr__(k, weakref.ref(v))
35
36
services =
WeakRefHolder
()
37
services.__doc__ =
"""The list of PyAthena::Svc which have been instantiated"""
38
services.__setattr__ = __wk_setattr__
39
40
algs =
WeakRefHolder
()
41
algs.__doc__ =
"""The list of PyAthena::Alg which have been instantiated"""
42
algs.__setattr__ = __wk_setattr__
43
44
del __wk_setattr__
45
46
47
def
_get_prop_value
(pycomp, propname):
48
if
propname
in
pycomp.properties()
and
pycomp.properties()[propname] != pycomp.propertyNoValue:
49
return
pycomp.properties()[propname]
50
else
:
51
return
pycomp.getDefaultProperty(propname)
52
53
54
55
class
StatusCode
:
56
Recoverable = 2
57
Success = 1
58
Failure = 0
59
60
61
class
Alg
( CfgPyAlgorithm ):
62
"""
63
Base class from which all concrete algorithm classes should
64
be derived.
65
66
In order for a concrete algorithm class to do anything
67
useful the methods initialize(), execute() and finalize()
68
should be overridden.
69
"""
70
def
__init__
(self, name = None, **kw):
71
if
name
is
None
: name = kw.get(
'name'
, self.__class__.__name__)
72
kw.setdefault(
'OutputLevel'
, 3)
#INFO
73
74
super(Alg, self).
__init__
(name, **kw)
75
self.
_pyath_evtstore
=
None
# handle to the evt store
76
self.
_pyath_detstore
=
None
# handle to the det store
77
self.
_pyath_condstore
=
None
# handle to the cond store
78
self.
_ctx
=
None
79
self.
__component_type__
=
"Algorithm"
80
self.
name
=name
81
return
82
83
@property
84
def
evtStore
(self):
85
if
not
self.
_pyath_evtstore
:
86
import
AthenaPython.PyAthena
as
PyAthena
87
self.
_pyath_evtstore
= PyAthena.py_svc(
'StoreGateSvc/StoreGateSvc'
)
88
return
self.
_pyath_evtstore
89
90
@property
91
def
detStore
(self):
92
if
not
self.
_pyath_detstore
:
93
import
AthenaPython.PyAthena
as
PyAthena
94
self.
_pyath_detstore
= PyAthena.py_svc(
'StoreGateSvc/DetectorStore'
)
95
return
self.
_pyath_detstore
96
97
@property
98
def
condStore
(self):
99
if
not
self.
_pyath_condstore
:
100
import
AthenaPython.PyAthena
as
PyAthena
101
self.
_pyath_condstore
= PyAthena.py_svc(
'StoreGateSvc/ConditionStore'
)
102
return
self.
_pyath_condstore
103
104
def
sysInitialize
(self):
105
if
hasattr(self,
'OutputLevel'
):
106
self.msg.setLevel(self.
OutputLevel
)
107
else
:
108
self.msg.setLevel(
_get_prop_value
(self,
'OutputLevel'
))
109
return
self.
initialize
()
110
111
def
initialize
(self):
112
return
StatusCode.Success
113
114
def
sysReinitialize
(self):
115
if
hasattr(self,
'OutputLevel'
):
116
self.msg.setLevel(self.
OutputLevel
)
117
else
:
118
self.msg.setLevel(
_get_prop_value
(self,
'OutputLevel'
))
119
return
self.
reinitialize
()
120
121
def
reinitialize
(self):
122
return
StatusCode.Success
123
124
def
sysExecute
(self, cppcontext):
125
import
cppyy
126
self.
_ctx
= cppyy.bind_object(cppcontext,
"EventContext"
)
127
try
:
128
ret = self.
execute
()
129
finally
:
130
self.
_ctx
=
None
131
return
ret
132
133
def
execute
(self):
134
return
StatusCode.Success
135
136
def
sysFinalize
(self):
137
return
self.
finalize
()
138
139
def
finalize
(self):
140
return
StatusCode.Success
141
142
def
sysStart
(self):
143
return
self.
start
()
144
145
def
start
(self):
146
return
StatusCode.Success
147
148
def
sysStop
(self):
149
return
self.
stop
()
150
151
def
stop
(self):
152
return
StatusCode.Success
153
154
def
filterPassed
(self):
155
"""Did this algorithm pass or fail its filter criterion for the last event?"""
156
return
self._cppHandle.
filterPassed
(self.
_ctx
)
157
158
def
setFilterPassed
(self, state):
159
"""Set the filter passed flag to the specified state"""
160
return
self._cppHandle.
setFilterPassed
(state, self.
_ctx
)
161
162
def
resetExecuted
(self):
163
self.
setExecuted
(
False
)
164
return
StatusCode.Success
165
166
def
setExecuted
(self,state):
167
return
self._cppHandle.
setExecuted
(state)
168
169
def
isExecuted
(self):
170
return
self._cppHandle.
isExecuted
()
171
172
def
getContext
(self):
173
return
self.
_ctx
174
175
pass
# PyAthena.Alg
176
177
178
class
Svc
( CfgPyService ):
179
"""Base class for all services
180
"""
181
def
__init__
(self, name = None, **kw):
182
kw.setdefault(
'OutputLevel'
, 3)
#INFO
183
if
name
is
None
: name = kw.get(
'name'
, self.__class__.__name__)
184
185
super(Svc, self).
__init__
(name, **kw)
186
self.
__component_type__
=
"Service"
187
return
188
189
def
sysInitialize
(self):
190
if
hasattr(self,
'OutputLevel'
):
191
self.msg.setLevel(self.
OutputLevel
)
192
else
:
193
self.msg.setLevel(
_get_prop_value
(self,
'OutputLevel'
))
194
return
self.
initialize
()
195
196
def
initialize
(self):
197
return
StatusCode.Success
198
199
def
sysReinitialize
(self):
200
if
hasattr(self,
'OutputLevel'
):
201
self.msg.setLevel(self.
OutputLevel
)
202
else
:
203
self.msg.setLevel(
_get_prop_value
(self,
'OutputLevel'
))
204
return
self.
reinitialize
()
205
206
def
reinitialize
(self):
207
return
StatusCode.Success
208
209
def
sysFinalize
(self):
210
return
self.
finalize
()
211
212
def
finalize
(self):
213
return
StatusCode.Success
214
215
def
sysStart
(self):
216
return
self.
start
()
217
218
def
start
(self):
219
return
StatusCode.Success
220
221
def
sysStop
(self):
222
return
self.
stop
()
223
224
def
stop
(self):
225
return
StatusCode.Success
226
227
pass
# PyAthena.Svc
228
229
230
class
AlgTool
( CfgPyAlgTool ):
231
"""
232
Base class from which all concrete algtool classes should be derived.
233
"""
234
235
def
__init__
(self, name=None, parent=None, **kw):
236
kw.setdefault(
'OutputLevel'
, 3)
#INFO
237
if
name
is
None
: name = kw.get(
'name'
, self.__class__.__name__)
238
if
parent
is
not
None
:
239
if
isinstance(parent, str): name =
"%s.%s"
% (parent,name)
240
else
: name =
"%s.%s"
% (parent.name(),name)
241
242
super(AlgTool, self).
__init__
(name, **kw)
243
self.
_pyath_evtstore
=
None
# handle to the evt store
244
self.
_pyath_detstore
=
None
# handle to the det store
245
self.
_pyath_condstore
=
None
# handle to the cond store
246
self.
__component_type__
=
"AlgTool"
247
return
248
249
@property
250
def
evtStore
(self):
251
if
not
self.
_pyath_evtstore
:
252
import
AthenaPython.PyAthena
as
PyAthena
253
self.
_pyath_evtstore
= PyAthena.py_svc(
'StoreGateSvc/StoreGateSvc'
)
254
return
self.
_pyath_evtstore
255
256
@property
257
def
detStore
(self):
258
if
not
self.
_pyath_detstore
:
259
import
AthenaPython.PyAthena
as
PyAthena
260
self.
_pyath_detstore
= PyAthena.py_svc(
'StoreGateSvc/DetectorStore'
)
261
return
self.
_pyath_detstore
262
263
@property
264
def
condStore
(self):
265
if
not
self.
_pyath_condstore
:
266
import
AthenaPython.PyAthena
as
PyAthena
267
self.
_pyath_condstore
= PyAthena.py_svc(
'StoreGateSvc/ConditionStore'
)
268
return
self.
_pyath_condstore
269
270
def
sysInitialize
(self):
271
if
hasattr(self,
'OutputLevel'
):
272
self.msg.setLevel(self.
OutputLevel
)
273
else
:
274
self.msg.setLevel(
_get_prop_value
(self,
'OutputLevel'
))
275
return
self.
initialize
()
276
277
def
initialize
(self):
278
raise
NotImplementedError(
279
"You have to implement PyAthena.AlgTool.initialize() !"
280
)
281
282
def
sysReinitialize
(self):
283
if
hasattr(self,
'OutputLevel'
):
284
self.msg.setLevel(self.
OutputLevel
)
285
else
:
286
self.msg.setLevel(
_get_prop_value
(self,
'OutputLevel'
))
287
return
self.
reinitialize
()
288
289
def
reinitialize
(self):
290
self.msg.info(
"==> re-initialize..."
)
291
return
StatusCode.Success
292
293
def
sysFinalize
(self):
294
return
self.
finalize
()
295
296
def
finalize
(self):
297
raise
NotImplementedError(
298
"You have to implement PyAthena.AlgTool.finalize() !"
299
)
300
301
pass
# PyAthena.AlgTool
302
303
304
class
Aud
( CfgPyAud ):
305
"""
306
Base class from which all concrete auditor classes should be derived.
307
"""
308
def
__init__
(self, name=None, **kw):
309
kw.setdefault(
'OutputLevel'
, 3)
#INFO
310
if
name
is
None
: name = kw.get(
'name'
, self.__class__.__name__)
311
312
super(Aud, self).
__init__
(name, **kw)
313
return
314
315
def
sysInitialize
(self):
316
if
hasattr(self,
'OutputLevel'
):
317
self.msg.setLevel(self.
OutputLevel
)
318
else
:
319
self.msg.setLevel(
_get_prop_value
(self,
'OutputLevel'
))
320
return
self.
initialize
()
321
322
def
initialize
(self):
323
raise
NotImplementedError(
324
"You have to implement PyAthena.Aud.initialize() !"
325
)
326
327
def
sysFinalize
(self):
328
return
self.
finalize
()
329
330
def
finalize
(self):
331
raise
NotImplementedError(
332
"You have to implement PyAthena.Aud.finalize() !"
333
)
334
335
336
337
def
before
(self, evt_name, comp_name):
338
return
339
340
def
after
(self, evt_name, comp_name, sc):
341
return
342
343
pass
# PyAthena.Aud
python.PyAthenaComps.AlgTool
Definition
PyAthenaComps.py:230
python.PyAthenaComps.AlgTool.condStore
condStore(self)
Definition
PyAthenaComps.py:264
python.PyAthenaComps.AlgTool.sysReinitialize
sysReinitialize(self)
Definition
PyAthenaComps.py:282
python.PyAthenaComps.AlgTool.__init__
__init__(self, name=None, parent=None, **kw)
Definition
PyAthenaComps.py:235
python.PyAthenaComps.AlgTool.initialize
initialize(self)
Definition
PyAthenaComps.py:277
python.PyAthenaComps.AlgTool.finalize
finalize(self)
Definition
PyAthenaComps.py:296
python.PyAthenaComps.AlgTool.detStore
detStore(self)
Definition
PyAthenaComps.py:257
python.PyAthenaComps.AlgTool.__component_type__
str __component_type__
Definition
PyAthenaComps.py:246
python.PyAthenaComps.AlgTool._pyath_condstore
_pyath_condstore
Definition
PyAthenaComps.py:245
python.PyAthenaComps.AlgTool.OutputLevel
OutputLevel
Definition
PyAthenaComps.py:272
python.PyAthenaComps.AlgTool.sysFinalize
sysFinalize(self)
Definition
PyAthenaComps.py:293
python.PyAthenaComps.AlgTool._pyath_evtstore
_pyath_evtstore
init base class
Definition
PyAthenaComps.py:243
python.PyAthenaComps.AlgTool.reinitialize
reinitialize(self)
Definition
PyAthenaComps.py:289
python.PyAthenaComps.AlgTool.sysInitialize
sysInitialize(self)
Definition
PyAthenaComps.py:270
python.PyAthenaComps.AlgTool._pyath_detstore
_pyath_detstore
Definition
PyAthenaComps.py:244
python.PyAthenaComps.AlgTool.evtStore
evtStore(self)
Definition
PyAthenaComps.py:250
python.PyAthenaComps.Alg
Definition
PyAthenaComps.py:61
python.PyAthenaComps.Alg.condStore
condStore(self)
Definition
PyAthenaComps.py:98
python.PyAthenaComps.Alg.OutputLevel
OutputLevel
Definition
PyAthenaComps.py:106
python.PyAthenaComps.Alg.evtStore
evtStore(self)
Definition
PyAthenaComps.py:84
python.PyAthenaComps.Alg.stop
stop(self)
Definition
PyAthenaComps.py:151
python.PyAthenaComps.Alg._pyath_detstore
_pyath_detstore
Definition
PyAthenaComps.py:76
python.PyAthenaComps.Alg.finalize
finalize(self)
Definition
PyAthenaComps.py:139
python.PyAthenaComps.Alg.sysExecute
sysExecute(self, cppcontext)
Definition
PyAthenaComps.py:124
python.PyAthenaComps.Alg.start
start(self)
Definition
PyAthenaComps.py:145
python.PyAthenaComps.Alg.name
name
Definition
PyAthenaComps.py:80
python.PyAthenaComps.Alg.sysStart
sysStart(self)
Definition
PyAthenaComps.py:142
python.PyAthenaComps.Alg.setFilterPassed
setFilterPassed(self, state)
Definition
PyAthenaComps.py:158
python.PyAthenaComps.Alg._ctx
_ctx
Definition
PyAthenaComps.py:78
python.PyAthenaComps.Alg.resetExecuted
resetExecuted(self)
Definition
PyAthenaComps.py:162
python.PyAthenaComps.Alg.__init__
__init__(self, name=None, **kw)
Definition
PyAthenaComps.py:70
python.PyAthenaComps.Alg.sysReinitialize
sysReinitialize(self)
Definition
PyAthenaComps.py:114
python.PyAthenaComps.Alg.execute
execute(self)
Definition
PyAthenaComps.py:133
python.PyAthenaComps.Alg._pyath_condstore
_pyath_condstore
Definition
PyAthenaComps.py:77
python.PyAthenaComps.Alg._pyath_evtstore
_pyath_evtstore
init base class
Definition
PyAthenaComps.py:75
python.PyAthenaComps.Alg.initialize
initialize(self)
Definition
PyAthenaComps.py:111
python.PyAthenaComps.Alg.setExecuted
setExecuted(self, state)
Definition
PyAthenaComps.py:166
python.PyAthenaComps.Alg.sysInitialize
sysInitialize(self)
Definition
PyAthenaComps.py:104
python.PyAthenaComps.Alg.__component_type__
str __component_type__
Definition
PyAthenaComps.py:79
python.PyAthenaComps.Alg.reinitialize
reinitialize(self)
Definition
PyAthenaComps.py:121
python.PyAthenaComps.Alg.sysStop
sysStop(self)
Definition
PyAthenaComps.py:148
python.PyAthenaComps.Alg.sysFinalize
sysFinalize(self)
Definition
PyAthenaComps.py:136
python.PyAthenaComps.Alg.isExecuted
isExecuted(self)
Definition
PyAthenaComps.py:169
python.PyAthenaComps.Alg.getContext
getContext(self)
Definition
PyAthenaComps.py:172
python.PyAthenaComps.Alg.detStore
detStore(self)
Definition
PyAthenaComps.py:91
python.PyAthenaComps.Alg.filterPassed
filterPassed(self)
Definition
PyAthenaComps.py:154
python.PyAthenaComps.Aud
Definition
PyAthenaComps.py:304
python.PyAthenaComps.Aud.OutputLevel
OutputLevel
Definition
PyAthenaComps.py:317
python.PyAthenaComps.Aud.__init__
__init__(self, name=None, **kw)
Definition
PyAthenaComps.py:308
python.PyAthenaComps.Aud.initialize
initialize(self)
Definition
PyAthenaComps.py:322
python.PyAthenaComps.Aud.sysInitialize
sysInitialize(self)
Definition
PyAthenaComps.py:315
python.PyAthenaComps.Aud.before
before(self, evt_name, comp_name)
default no-op implementation...
Definition
PyAthenaComps.py:337
python.PyAthenaComps.Aud.sysFinalize
sysFinalize(self)
Definition
PyAthenaComps.py:327
python.PyAthenaComps.Aud.finalize
finalize(self)
Definition
PyAthenaComps.py:330
python.PyAthenaComps.Aud.after
after(self, evt_name, comp_name, sc)
Definition
PyAthenaComps.py:340
python.PyAthenaComps.StatusCode
PyAthena.StatusCode ----------------------------------------------------—.
Definition
PyAthenaComps.py:55
python.PyAthenaComps.Svc
Definition
PyAthenaComps.py:178
python.PyAthenaComps.Svc.__init__
__init__(self, name=None, **kw)
Definition
PyAthenaComps.py:181
python.PyAthenaComps.Svc.sysStart
sysStart(self)
Definition
PyAthenaComps.py:215
python.PyAthenaComps.Svc.sysFinalize
sysFinalize(self)
Definition
PyAthenaComps.py:209
python.PyAthenaComps.Svc.sysReinitialize
sysReinitialize(self)
Definition
PyAthenaComps.py:199
python.PyAthenaComps.Svc.OutputLevel
OutputLevel
Definition
PyAthenaComps.py:191
python.PyAthenaComps.Svc.finalize
finalize(self)
Definition
PyAthenaComps.py:212
python.PyAthenaComps.Svc.sysInitialize
sysInitialize(self)
Definition
PyAthenaComps.py:189
python.PyAthenaComps.Svc.stop
stop(self)
Definition
PyAthenaComps.py:224
python.PyAthenaComps.Svc.sysStop
sysStop(self)
Definition
PyAthenaComps.py:221
python.PyAthenaComps.Svc.reinitialize
reinitialize(self)
Definition
PyAthenaComps.py:206
python.PyAthenaComps.Svc.__component_type__
str __component_type__
init base class
Definition
PyAthenaComps.py:186
python.PyAthenaComps.Svc.initialize
initialize(self)
Definition
PyAthenaComps.py:196
python.PyAthenaComps.Svc.start
start(self)
Definition
PyAthenaComps.py:218
python.PyAthenaComps.WeakRefHolder
Definition
PyAthenaComps.py:29
Configurable
python.PyAthenaComps._get_prop_value
_get_prop_value(pycomp, propname)
helper methods ---------------------------------------------------------—
Definition
PyAthenaComps.py:47
python.PyAthenaComps.__wk_setattr__
__wk_setattr__(self, k, v)
Definition
PyAthenaComps.py:33
initialize
void initialize()
Definition
run_EoverP.cxx:894
Generated on
for ATLAS Offline Software by
1.17.0