ATLAS Offline Software
Loading...
Searching...
No Matches
python.tests.PyTestsLib.MyNameAud Class Reference
Inheritance diagram for python.tests.PyTestsLib.MyNameAud:
Collaboration diagram for python.tests.PyTestsLib.MyNameAud:

Public Member Functions

 __init__ (self, name="MyNameAud", **kw)
 initialize (self)
 finalize (self)
 before (self, evt_name, comp_name)
 after (self, evt_name, comp_name, sc)
virtual StatusCode sysInitialize () 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
virtual PyObjectself () override
 return associated python object.

Public Attributes

 name

Protected Member Functions

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

Protected Attributes

PyObjectm_self
 Pointer to self (from the python world)

Detailed Description

Simple test of a py-auditor

Definition at line 96 of file PyTestsLib.py.

Constructor & Destructor Documentation

◆ __init__()

python.tests.PyTestsLib.MyNameAud.__init__ ( self,
name = "MyNameAud",
** kw )

Definition at line 99 of file PyTestsLib.py.

99 def __init__(self, name="MyNameAud", **kw):
100
101 kw['name'] = name
102 super(MyNameAud,self).__init__(**kw)
103

Member Function Documentation

◆ after()

python.tests.PyTestsLib.MyNameAud.after ( self,
evt_name,
comp_name,
sc )

Definition at line 116 of file PyTestsLib.py.

116 def after (self, evt_name, comp_name, sc):
117 self.msg.info("Exiting %s [%s]...", evt_name.lower(), comp_name)
118 return
119

◆ before()

python.tests.PyTestsLib.MyNameAud.before ( self,
evt_name,
comp_name )

Definition at line 112 of file PyTestsLib.py.

112 def before(self, evt_name, comp_name):
113 self.msg.info("Entering %s [%s]...", evt_name.lower(), comp_name)
114 return
115

◆ finalize()

python.tests.PyTestsLib.MyNameAud.finalize ( self)

Definition at line 108 of file PyTestsLib.py.

108 def finalize(self):
109 self.msg.info("==> finalizing [%s]...", self.name)
110 return StatusCode.Success
111

◆ initialize()

python.tests.PyTestsLib.MyNameAud.initialize ( self)

Definition at line 104 of file PyTestsLib.py.

104 def initialize(self):
105 self.msg.info("==> initializing [%s]...", self.name)
106 return StatusCode.Success
107
void initialize()

◆ self()

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

return associated python object.

BORROWED reference.

Implements IPyComponent.

Definition at line 68 of file PyAthenaAud.h.

68{ return m_self; }
PyObject * m_self
Pointer to self (from the python world)
Definition PyAthenaAud.h:90

◆ setPyAttr()

bool PyAthena::Aud::setPyAttr ( PyObject * pyobj)
overrideprotectedvirtualinherited

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.
133 RootUtils::PyGILStateEnsure ensure;
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}
#define endmsg
_object PyObject
virtual const char * typeName() const override
return the std::type_info name of the underlying py-component This is used by concrete implementation...
msgSvc
Provide convenience handles for various services.
Definition StdJOSetup.py:36
MsgStream & msg
Definition testRead.cxx:32

◆ sysInitialize()

StatusCode PyAthena::Aud::sysInitialize ( )
overridevirtualinherited

Definition at line 67 of file PyAthenaAud.cxx.

68{
69 ServiceHandle<IPyComponentMgr> pyMgr
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
overridevirtualinherited

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
protectedinherited

Pointer to self (from the python world)

Definition at line 90 of file PyAthenaAud.h.

◆ name

python.tests.PyTestsLib.MyNameAud.name

Definition at line 105 of file PyTestsLib.py.


The documentation for this class was generated from the following file: