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

Public Member Functions

 __init__ (self, name="MySvc", **kw)
 initialize (self)
 finalize (self)
virtual StatusCode reinitialize () override
virtual StatusCode start () override
virtual StatusCode stop () override
virtual StatusCode sysInitialize () override
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.
virtual void handle (const Incident &incident) override
 callback method for the IIncidentSvc

Public Attributes

 counter = kw.get('counter', 0)
 sg = PyAthena.py_svc("StoreGateSvc")
 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-service

Definition at line 54 of file PyTestsLib.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 57 of file PyTestsLib.py.

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

Member Function Documentation

◆ finalize()

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

Definition at line 70 of file PyTestsLib.py.

70 def finalize(self):
71 self.msg.info( "==> finalize..." )
72 self.msg.info( "cnt: %r",self.counter )
73 return StatusCode.Success
74

◆ handle()

void PyAthena::Svc::handle ( const Incident & incident)
overridevirtualinherited

callback method for the IIncidentSvc

Definition at line 122 of file PyAthenaSvc.cxx.

123{
124 RootUtils::PyGILStateEnsure ensure;
125 if (0 == PyObject_HasAttrString (m_self, (char*)"handle")) {
126 // python side does not implement 'handle'. Fair enough.
127 // XXX FIXME: could say something though: we have been registered as
128 // listener, so there might be some kind of inconsistency...
129 return;
130 }
131
132 PyObject *o = TPython::CPPInstance_FromVoidPtr ((void*)(&inc), "Incident");
133 if (0 == o) {
134 Py_XDECREF (o);
136 }
137
138 PyObject *res = PyObject_CallMethod (m_self,
139 (char*)"handle",
140 (char*)"O", o);
141 if (0 == res) {
142 Py_XDECREF (res);
143 Py_DECREF (o);
145 }
146
147 Py_DECREF (res);
148 Py_DECREF (o);
149 return;
150}
_object PyObject
std::pair< std::vector< unsigned int >, bool > res
PyObject * m_self
Pointer to self (from the python world)
Definition PyAthenaSvc.h:89
void throw_py_exception(bool display=true)
helper function to capture the boilerplate code for user friendly stack trace display

◆ initialize()

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

Definition at line 64 of file PyTestsLib.py.

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
void initialize()

◆ reinitialize()

StatusCode PyAthena::Svc::reinitialize ( )
overridevirtualinherited

Definition at line 64 of file PyAthenaSvc.cxx.

65{
66 ATH_MSG_INFO("Re-Initializing " << name() << "...");
67 return PyAthena::callPyMethod( m_self, "sysReinitialize" );
68}
#define ATH_MSG_INFO(x)

◆ self()

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

return associated python object.

BORROWED reference.

Definition at line 68 of file PyAthenaSvc.h.

68{ return m_self; }

◆ setPyAttr()

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

attach the C++ component to its python cousin

Definition at line 154 of file PyAthenaSvc.cxx.

155{
156 // now we tell the PyObject which C++ object it is the cousin of.
157 RootUtils::PyGILStateEnsure ensure;
158 PyObject* pyobj = TPython::CPPInstance_FromVoidPtr
159 ( (void*)this, this->typeName() );
160 if ( !pyobj ) {
161 PyErr_Clear();
162 // try PyAthena::Svc
163 pyobj = TPython::CPPInstance_FromVoidPtr ((void*)this, "PyAthena::Svc");
165 ("could not dyncast component [" << name() << "] to a python "
166 << "object of type [" << this->typeName() << "] (probably a missing "
167 << "dictionary)" << endmsg
168 << "fallback to [PyAthena::Svc]...");
169 }
170 if ( !pyobj ) {
171 PyErr_Clear();
173 ("Could not dyncast component [" << name() << "] to a pyobject of type ["
174 << this->typeName() << "]");
175 } else {
176 if ( -1 == PyObject_SetAttrString(o, "_cppHandle", pyobj) ) {
177 PyErr_Clear();
179 ("Could not attach C++ handle [" << name() << "] to its python "
180 << "cousin !");
181 if ( -1 == PyObject_SetAttrString(o, "_cppHandle", Py_None) ) {
182 PyErr_Clear();
184 ("could not attach a dummy C++ handle [" << name() << "] to its "
185 << "python cousin !");
186 }
187 } else {
188 return true;
189 }
190 }
191 return false;
192}
#define endmsg
#define ATH_MSG_WARNING(x)
const char * typeName() const override
return the std::type_info name of the underlying py-component This is used by concrete implementation...

◆ start()

StatusCode PyAthena::Svc::start ( )
overridevirtualinherited

Definition at line 78 of file PyAthenaSvc.cxx.

79{
80 return PyAthena::callPyMethod( m_self, "sysStart" );
81}

◆ stop()

StatusCode PyAthena::Svc::stop ( )
overridevirtualinherited

Definition at line 84 of file PyAthenaSvc.cxx.

85{
86 return PyAthena::callPyMethod( m_self, "sysStop" );
87}

◆ sysInitialize()

StatusCode PyAthena::Svc::sysInitialize ( )
overridevirtualinherited

Definition at line 90 of file PyAthenaSvc.cxx.

91{
92 ServiceHandle<IPyComponentMgr> pyMgr
93 ( "PyAthena::PyComponentMgr/PyComponentMgr", name() );
94 if ( !pyMgr.retrieve().isSuccess() ) {
96 ("Could not retrieve service [" << pyMgr.typeAndName() << "] !!");
97 return StatusCode::FAILURE;
98 }
99
100 // first retrieve our python object cousin...
101 m_self = pyMgr->pyObject( this );
102
103 if ( m_self == Py_None ) {
104 ATH_MSG_ERROR("Wrapped PyObject is NONE !");
105 return StatusCode::FAILURE;
106 }
107
108 // re-route to usual sysInit...
109 return SvcBase_t::sysInitialize();
110}
#define ATH_MSG_ERROR(x)

◆ typeName()

const char * PyAthena::Svc::typeName ( ) const
overrideinherited

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

Definition at line 114 of file PyAthenaSvc.cxx.

115{
116 static const std::string tname = System::typeinfoName(typeid(*this));
117 return tname.c_str();
118}

Member Data Documentation

◆ counter

python.tests.PyTestsLib.MySvc.counter = kw.get('counter', 0)

Definition at line 62 of file PyTestsLib.py.

◆ m_self

PyObject* PyAthena::Svc::m_self
protectedinherited

Pointer to self (from the python world)

Definition at line 89 of file PyAthenaSvc.h.

◆ name

python.tests.PyTestsLib.MySvc.name

Definition at line 66 of file PyTestsLib.py.

◆ sg

python.tests.PyTestsLib.MySvc.sg = PyAthena.py_svc("StoreGateSvc")

Definition at line 65 of file PyTestsLib.py.


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