ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
PyAthena::Aud Class Reference

#include <PyAthenaAud.h>

Inheritance diagram for PyAthena::Aud:
Collaboration diagram for PyAthena::Aud:

Public Member Functions

 Aud (const std::string &name, ISvcLocator *svcLocator)
 Constructor with parameters: More...
 
virtual ~Aud ()
 Destructor: More...
 
virtual StatusCode initialize () override
 Gaudi Aud Implementation. More...
 
virtual StatusCode sysInitialize () override
 
virtual StatusCode finalize () override
 
virtual const char * typeName () const override
 return the std::type_info name of the underlying py-component This is used by concrete implementations to connect a python component to its C++ counter-part More...
 
virtual void before (const std::string &evt, const std::string &name, const EventContext &ctx) override
 Auditor interface More...
 
virtual void after (const std::string &evt, const std::string &name, const EventContext &ctx, const StatusCode &sc) override
 
virtual PyObjectself () override
 return associated python object. More...
 
 DeclareInterfaceID (IPyComponent, 1, 0)
 

Protected Member Functions

virtual bool setPyAttr (PyObject *pyobj) override
 attach the C++ component to its python cousin More...
 

Protected Attributes

PyObjectm_self
 Pointer to self (from the python world) More...
 

Private Member Functions

 Aud ()
 Default constructor: More...
 

Detailed Description

Definition at line 30 of file PyAthenaAud.h.

Constructor & Destructor Documentation

◆ Aud() [1/2]

PyAthena::Aud::Aud ( const std::string &  name,
ISvcLocator *  svcLocator 
)

Constructor with parameters:

Definition at line 42 of file PyAthenaAud.cxx.

42  :
43  Gaudi::Auditor( name, svcLocator ),
44  m_self ( nullptr )
45 {}

◆ ~Aud()

PyAthena::Aud::~Aud ( )
virtual

Destructor:

Definition at line 49 of file PyAthenaAud.cxx.

50 {
51  if ( m_self ) {
53  Py_DECREF( m_self );
54  m_self = nullptr;
55  }
56 }

◆ Aud() [2/2]

PyAthena::Aud::Aud ( )
private

Default constructor:

Member Function Documentation

◆ after()

void PyAthena::Aud::after ( const std::string &  evt,
const std::string &  name,
const EventContext &  ctx,
const StatusCode &  sc 
)
overridevirtual

Definition at line 117 of file PyAthenaAud.cxx.

119 {
120  std::string evtname = evt;
121  std::transform(evt.begin(), evt.end(), evtname.begin(), ::tolower);
122  PyAthena::pyAudit (m_self, "after", evtname.c_str(), name.c_str(), sc);
123 }

◆ before()

void PyAthena::Aud::before ( const std::string &  evt,
const std::string &  name,
const EventContext &  ctx 
)
overridevirtual

Auditor interface

Definition at line 108 of file PyAthenaAud.cxx.

110 {
111  std::string evtname = evt;
112  std::transform(evt.begin(), evt.end(), evtname.begin(), ::tolower);
113  PyAthena::pyAudit (m_self, "before", evtname.c_str(), name.c_str());
114 }

◆ DeclareInterfaceID()

IPyComponent::DeclareInterfaceID ( IPyComponent  ,
,
 
)
inherited

◆ finalize()

StatusCode PyAthena::Aud::finalize ( )
overridevirtual

Definition at line 87 of file PyAthenaAud.cxx.

88 {
89  return PyAthena::callPyMethod( m_self, "sysFinalize" );
90 }

◆ initialize()

StatusCode PyAthena::Aud::initialize ( )
overridevirtual

Gaudi Aud Implementation.

Definition at line 61 of file PyAthenaAud.cxx.

62 {
63  return PyAthena::callPyMethod( m_self, "sysInitialize" );
64 }

◆ self()

virtual PyObject* PyAthena::Aud::self ( )
inlineoverridevirtual

return associated python object.

BORROWED reference.

Implements IPyComponent.

Definition at line 68 of file PyAthenaAud.h.

68 { return m_self; }

◆ setPyAttr()

bool PyAthena::Aud::setPyAttr ( PyObject pyobj)
overrideprotectedvirtual

attach the C++ component to its python cousin

Implements IPyComponent.

Definition at line 130 of file PyAthenaAud.cxx.

131 {
132  // now we tell the PyObject which C++ object it is the cousin of.
134  PyObject* pyobj = TPython::CPPInstance_FromVoidPtr
135  ( (void*)this, this->typeName() );
136  if ( !pyobj ) {
137  PyErr_Clear();
138  // try PyAthena::Aud
139  pyobj = TPython::CPPInstance_FromVoidPtr ((void*)this, "PyAthena::Aud");
140  MsgStream msg( msgSvc(), name() );
141  msg << MSG::INFO
142  << "could not dyncast component [" << name() << "] to a python "
143  << "object of type [" << this->typeName() << "] (probably a missing "
144  << "dictionary)" << endmsg
145  << "fallback to [PyAthena::Aud]..."
146  << endmsg;
147  }
148  if ( !pyobj ) {
149  PyErr_Clear();
150  MsgStream msg( msgSvc(), name() );
151  msg << MSG::WARNING << "Could not dyncast component ["
152  << name() << "] to a pyobject of type ["
153  << this->typeName() << "]"
154  << endmsg;
155  } else {
156  if ( -1 == PyObject_SetAttrString(o, "_cppHandle", pyobj) ) {
157  PyErr_Clear();
158  MsgStream msg( msgSvc(), name() );
159  msg << MSG::WARNING
160  << "Could not attach C++ handle [" << name() << "] to its python "
161  << "cousin !"
162  << endmsg;
163  if ( -1 == PyObject_SetAttrString(o, "_cppHandle", Py_None) ) {
164  PyErr_Clear();
165  msg << MSG::WARNING
166  << "could not attach a dummy C++ handle [" << name() << "] to its "
167  << "python cousin !"
168  << endmsg;
169  }
170  } else {
171  return true;
172  }
173  }
174  return false;
175 }

◆ sysInitialize()

StatusCode PyAthena::Aud::sysInitialize ( )
overridevirtual

Definition at line 67 of file PyAthenaAud.cxx.

68 {
70  ( "PyAthena::PyComponentMgr/PyComponentMgr", name() );
71  if ( !pyMgr.retrieve().isSuccess() ) {
72  return StatusCode::FAILURE;
73  }
74 
75  // first retrieve our python object cousin...
76  m_self = pyMgr->pyObject( this );
77 
78  if ( m_self == Py_None ) {
79  return StatusCode::FAILURE;
80  }
81 
82  // re-route to usual sysInit...
83  return Gaudi::Auditor::sysInitialize();
84 }

◆ typeName()

const char * PyAthena::Aud::typeName ( ) const
overridevirtual

return the std::type_info name of the underlying py-component This is used by concrete implementations to connect a python component to its C++ counter-part

Implements IPyComponent.

Definition at line 97 of file PyAthenaAud.cxx.

98 {
99  static const std::string tname = System::typeinfoName(typeid(*this));
100  return tname.c_str();
101 }

Member Data Documentation

◆ m_self

PyObject* PyAthena::Aud::m_self
protected

Pointer to self (from the python world)

Definition at line 90 of file PyAthenaAud.h.


The documentation for this class was generated from the following files:
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
RootUtils::PyGILStateEnsure
Definition: PyAthenaGILStateEnsure.h:20
Athena::typeinfoName
std::string typeinfoName(const std::type_info &ti)
Convert a type_info to a demangled string.
Definition: AthenaKernel/src/ClassName.cxx:23
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
tolower
void tolower(std::string &s)
Definition: AthenaSummarySvc.cxx:108
PyAthena::Aud::typeName
virtual const char * typeName() const override
return the std::type_info name of the underlying py-component This is used by concrete implementation...
Definition: PyAthenaAud.cxx:97
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:15
PyAthena::Aud::m_self
PyObject * m_self
Pointer to self (from the python world)
Definition: PyAthenaAud.h:90
PyObject
_object PyObject
Definition: IPyComponent.h:26
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
ServiceHandle
Definition: ClusterMakerTool.h:37