ATLAS Offline Software
PyTestsLib.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 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
8 of PyAthena.
9 """
10 __author__ = "Sebastien Binet <binet@cern.ch>"
11 
12 import AthenaCommon.SystemOfUnits as Units
13 import AthenaPython.PyAthena as PyAthena
14 from 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)
47  _info("has passed filter: %s", bool(self._cppHandle.filterPassed()))
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 
75 class 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 
python.tests.PyTestsLib.MyTool.counter
counter
init base class
Definition: PyTestsLib.py:83
grepfile.info
info
Definition: grepfile.py:38
python.tests.PyTestsLib.MyAlg
Definition: PyTestsLib.py:16
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
SystemOfUnits
python.tests.PyTestsLib.MyTool.finalize
def finalize(self)
Definition: PyTestsLib.py:91
python.tests.PyTestsLib.MySvc.sg
sg
Definition: PyTestsLib.py:65
PyAthena::Aud::initialize
virtual StatusCode initialize() override
Gaudi Aud Implementation.
Definition: PyAthenaAud.cxx:60
python.tests.PyTestsLib.MyTool.__init__
def __init__(self, name="MyTool", **kw)
Definition: PyTestsLib.py:78
python.tests.PyTestsLib.MyNameAud
Definition: PyTestsLib.py:96
python.tests.PyTestsLib.MyNameAud.before
def before(self, evt_name, comp_name)
Definition: PyTestsLib.py:112
PyAthena::Alg::initialize
virtual StatusCode initialize() override
Definition: PyAthenaAlg.cxx:60
PyAthena::Alg::execute
virtual StatusCode execute() override
Definition: PyAthenaAlg.cxx:93
python.tests.PyTestsLib.MyNameAud.__init__
def __init__(self, name="MyNameAud", **kw)
Definition: PyTestsLib.py:99
PyAthena::Aud::finalize
virtual StatusCode finalize() override
Definition: PyAthenaAud.cxx:86
python.tests.PyTestsLib.MyTool.sg
sg
Definition: PyTestsLib.py:86
python.tests.PyTestsLib.MyAlg.px
px
init base class
Definition: PyTestsLib.py:24
python.tests.PyTestsLib.MyAlg.filterPassed
filterPassed
Definition: PyTestsLib.py:28
PyAthena::Svc
Definition: PyAthenaSvc.h:33
PyAthena::Aud
Definition: PyAthenaAud.h:32
python.tests.PyTestsLib.MyTool
Definition: PyTestsLib.py:75
python.tests.PyTestsLib.MyAlg.pt
pt
Definition: PyTestsLib.py:26
python.tests.PyTestsLib.MyNameAud.after
def after(self, evt_name, comp_name, sc)
Definition: PyTestsLib.py:116
PyAthena::Svc::finalize
virtual StatusCode finalize() override
Definition: PyAthenaSvc.cxx:71
python.tests.PyTestsLib.MyAlg.__init__
def __init__(self, name="MyAlg", **kw)
Definition: PyTestsLib.py:19
python.tests.PyTestsLib.MyAlg.sg
sg
Definition: PyTestsLib.py:31
python.tests.PyTestsLib.MyTool.initialize
def initialize(self)
Definition: PyTestsLib.py:85
python.tests.PyTestsLib.MyAlg.eta
eta
Definition: PyTestsLib.py:25
PyAthena::Svc::initialize
virtual StatusCode initialize() override
Gaudi Service Implementation.
Definition: PyAthenaSvc.cxx:57
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
PyAthena::Alg
Definition: PyAthenaAlg.h:33
python.tests.PyTestsLib.MySvc
Definition: PyTestsLib.py:54
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
python.tests.PyTestsLib.MyAlg.mytool
mytool
Definition: PyTestsLib.py:27
python.tests.PyTestsLib.MySvc.counter
counter
init base class
Definition: PyTestsLib.py:62
python.tests.PyTestsLib.MySvc.__init__
def __init__(self, name="MySvc", **kw)
Definition: PyTestsLib.py:57