ATLAS Offline Software
PyAthenaEventLoopMgr.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 
6 
7 import GaudiPython.Bindings as PyGaudi
8 
9 
10 
12 class PyAthenaEventLoopMgr( PyGaudi.iService ):
13 
14  def __init__( self ):
15  PyGaudi.iService.__init__( self, 'PyAthenaEventLoopMgr' )
16 
17  def _installServices( self, cppself ):
18  # install the interfaces onto oneself; the order is (as per the
19  # cpp side multiple inheritence:
20  # IEventSeek
21  # IService => from here ...
22  # INamedInterface
23  # IInterface
24  # IProperty => ... up to here from the iService base class
25  # IStateful
26  # IEventProcessor
27  #
28  # The expectation from the C++ side it that an IEventSeek is received. Note
29  # that this code can not call into the application manager, as this is run
30  # during initialize, making the IService PyAthenaEventLoopMgr unavailable.
31  #
32  # Note that this is all a poor man's way of not needing to have dictionaries
33  # for all base classes of the C++ PyAthenaEventLoopMgr.
34 
35  import cppyy
36 
37  # need to set all the following through the __dict__ b/c of iPropert.__setattr__
38 
39  # the expect IEventSeek
40  self.__dict__[ '_evtSeek' ] = cppyy.bind_object( cppself, cppyy.gbl.IEventSeek )
41 
42  # the IService needed for iService._isvc and likewise iProperty._ip
43  self.__dict__[ '_isvc' ] = PyGaudi.InterfaceCast( cppyy.gbl.IService )( self._evtSeek )
44  self.__dict__[ '_ip' ] = PyGaudi.InterfaceCast( cppyy.gbl.IProperty )( self._evtSeek )
45 
46  # IStateful and IEventProcessor
47  self.__dict__[ '_state' ] = PyGaudi.InterfaceCast( cppyy.gbl.IStateful )( self._evtSeek )
48  self.__dict__[ '_evtpro' ] = PyGaudi.InterfaceCast( cppyy.gbl.IEventProcessor )( self._evtSeek )
49 
50  def __getattr__( self, attr ):
51  # note the lookup order: should be as per the C++ side
52  for obj in [ self._evtSeek, self._state, self._evtpro ]:
53  try:
54  return getattr( obj, attr )
55  except Exception:
56  pass
57 
58  # let properties be tried last
59  return super( PyAthenaEventLoopMgr, self ).__getattr__( attr )
60 
61  def executeAlgorithms( self, cppcontext ):
62 
63  from AthenaPython.PyAthena import py_svc
64  from AthenaPython.PyAthenaComps import StatusCode
65  appmgr = py_svc('ApplicationMgr',iface="IProperty")
66  algmgr = py_svc('ApplicationMgr',iface='IAlgManager')
67 
68  import cppyy
69  ctx = cppyy.bind_object(cppcontext, "EventContext")
70 
71  try:
72  for name in appmgr.getProperty("TopAlg").value():
73  ialg=algmgr.algorithm(name).get()
74  ialg.execState(ctx).reset()
75  result = ialg.sysExecute(ctx)
76  if result.isFailure():
77  from AthenaCommon.Logging import log as msg
78  msg.error( "Execution of algorithm %s failed", name )
79  return result.getCode()
80  except KeyboardInterrupt:
81  from AthenaCommon.Logging import log as msg
82  msg.critical( "event loop stopped by user interrupt" )
83  return StatusCode.Failure
84 
85  return StatusCode.Success
python.PyAthenaEventLoopMgr.PyAthenaEventLoopMgr.executeAlgorithms
def executeAlgorithms(self, cppcontext)
Definition: PyAthenaEventLoopMgr.py:61
python.PyAthenaEventLoopMgr.PyAthenaEventLoopMgr
Definition: PyAthenaEventLoopMgr.py:12
athena.value
value
Definition: athena.py:124
python.PyAthenaEventLoopMgr.PyAthenaEventLoopMgr.__init__
def __init__(self)
Definition: PyAthenaEventLoopMgr.py:14
python.PyAthenaEventLoopMgr.PyAthenaEventLoopMgr._installServices
def _installServices(self, cppself)
Definition: PyAthenaEventLoopMgr.py:17
python.Bindings.py_svc
def py_svc(svcName, createIf=True, iface=None)
Definition: Control/AthenaPython/python/Bindings.py:98
CxxUtils::reset
constexpr std::enable_if_t< is_bitmask_v< E >, E & > reset(E &lhs, E rhs)
Convenience function to clear bits in a class enum bitmask.
Definition: bitmask.h:251
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
python.PyAthenaEventLoopMgr.PyAthenaEventLoopMgr.__getattr__
def __getattr__(self, attr)
Definition: PyAthenaEventLoopMgr.py:50