ATLAS Offline Software
Loading...
Searching...
No Matches
PyTestsLib.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3# @file: AthenaPython/python/tests/PyTestsLib.py
4# @purpose: a set of py-components to test various aspects of PyAthena
5# @author: Sebastien Binet <binet@cern.ch>
6
7__doc__ = """Module containing a set of py-components to test various aspects
8of PyAthena.
9"""
10__author__ = "Sebastien Binet <binet@cern.ch>"
11
12import AthenaCommon.SystemOfUnits as Units
13import AthenaPython.PyAthena as PyAthena
14from AthenaPython.PyAthena import StatusCode
15
17 """Simple test of a py-algorithm
18 """
19 def __init__(self, name = "MyAlg", **kw):
20
21 kw['name'] = name
22 super(MyAlg,self).__init__(**kw)
23
24 self.px = kw.get('px', 10.*Units.GeV)
25 self.eta = kw.get('eta', 2.5)
26 self.pt = kw.get('pt', 40.*Units.GeV)
27 self.mytool = kw.get('mytool', MyTool("%s_mytool"%self.name))
28 self.filterPassed = kw.get('filterPassed', True)
29
30 def initialize(self):
31 self.sg = PyAthena.py_svc("StoreGateSvc")
32 self.msg.info( "==> initializing [%s]...", self.name )
33 self.msg.info( "eta: %r",self.eta )
34 self.msg.info( "pt: %r",self.pt )
35 self.msg.info( "px: %r",self.px )
36 self.mytool.counter += 1
37 self.msg.info( "tool:%r %r",self.mytool.counter, self.mytool.name )
38 return StatusCode.Success
39
40 def execute(self):
41 _info = self.msg.info
42 _info( "==> execute..." )
43
45 _info("hasattr('_cppHandle'): %s", hasattr(self,'_cppHandle'))
46 self._cppHandle.setFilterPassed(self.filterPassed, self.getContext())
47 _info("has passed filter: %s", bool(self._cppHandle.filterPassed(self.getContext())))
48 return StatusCode.Success
49
50 def finalize(self):
51 self.msg.info( "==> finalize..." )
52 return StatusCode.Success
53
55 """Simple test of a py-service
56 """
57 def __init__(self, name = "MySvc", **kw):
58
59 kw['name'] = name
60 super(MySvc,self).__init__(**kw)
61
62 self.counter = kw.get('counter', 0)
63
64 def initialize(self):
65 self.sg = PyAthena.py_svc("StoreGateSvc")
66 self.msg.info( "==> initializing [%s]...", self.name )
67 self.msg.info( "cnt: %r",self.counter )
68 return StatusCode.Success
69
70 def finalize(self):
71 self.msg.info( "==> finalize..." )
72 self.msg.info( "cnt: %r",self.counter )
73 return StatusCode.Success
74
75class MyTool( PyAthena.AlgTool ):
76 """Simple test of a py-tool
77 """
78 def __init__(self, name = "MyTool", **kw):
79
80 kw['name'] = name
81 super(MyTool,self).__init__(**kw)
82
83 self.counter = kw.get('counter', 0)
84
85 def initialize(self):
86 self.sg = PyAthena.py_svc("StoreGateSvc")
87 self.msg.info( "==> initializing [%s]...", self.name )
88 self.msg.info( "cnt: %r",self.counter )
89 return StatusCode.Success
90
91 def finalize(self):
92 self.msg.info( "==> finalize..." )
93 self.msg.info( "cnt: %r",self.counter )
94 return StatusCode.Success
95
97 """Simple test of a py-auditor
98 """
99 def __init__(self, name="MyNameAud", **kw):
100
101 kw['name'] = name
102 super(MyNameAud,self).__init__(**kw)
103
104 def initialize(self):
105 self.msg.info("==> initializing [%s]...", self.name)
106 return StatusCode.Success
107
108 def finalize(self):
109 self.msg.info("==> finalizing [%s]...", self.name)
110 return StatusCode.Success
111
112 def before(self, evt_name, comp_name):
113 self.msg.info("Entering %s [%s]...", evt_name.lower(), comp_name)
114 return
115
116 def after (self, evt_name, comp_name, sc):
117 self.msg.info("Exiting %s [%s]...", evt_name.lower(), comp_name)
118 return
119
virtual void setFilterPassed(bool state, const EventContext &ctx) const
virtual StatusCode initialize() override
virtual StatusCode initialize() override
Gaudi Aud Implementation.
virtual StatusCode finalize() override
virtual StatusCode finalize() override
virtual StatusCode initialize() override
Gaudi Service Implementation.
__init__(self, name="MyAlg", **kw)
Definition PyTestsLib.py:19
before(self, evt_name, comp_name)
__init__(self, name="MyNameAud", **kw)
Definition PyTestsLib.py:99
after(self, evt_name, comp_name, sc)
__init__(self, name="MySvc", **kw)
Definition PyTestsLib.py:57
__init__(self, name="MyTool", **kw)
Definition PyTestsLib.py:78
finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition PyTestsLib.py:50
void initialize()