diff --git a/Control/AthenaPython/AthenaPython/PyAthenaUtils.h b/Control/AthenaPython/AthenaPython/PyAthenaUtils.h index 9ff746dca071cf6fd2fe5f34f2eaffc1993fad49..043239c3bce75e22b0a27977cbb9ae2f35b038f6 100644 --- a/Control/AthenaPython/AthenaPython/PyAthenaUtils.h +++ b/Control/AthenaPython/AthenaPython/PyAthenaUtils.h @@ -36,7 +36,9 @@ namespace PyAthena { std::string str (PyObject* o); /// call the python method - StatusCode callPyMethod( PyObject* self , const char* method ); + StatusCode callPyMethod( PyObject* self, + const char* method, + PyObject* arg = nullptr ); /// query interface binding StatusCode queryInterface( PyObject* self, diff --git a/Control/AthenaPython/python/PyAthenaComps.py b/Control/AthenaPython/python/PyAthenaComps.py index 0bf3638e7cf74c4cf4270f629a4454d889346722..c0424db16d19dc310e85c8cc3de482965bba43fb 100644 --- a/Control/AthenaPython/python/PyAthenaComps.py +++ b/Control/AthenaPython/python/PyAthenaComps.py @@ -77,6 +77,7 @@ class Alg( CfgPyAlgorithm ): super(Alg, self).__init__(name, **kw) self._pyath_evtstore = None # handle to the evt store self._pyath_detstore = None # handle to the det store + self._ctx = None return @property @@ -107,8 +108,14 @@ class Alg( CfgPyAlgorithm ): def reinitialize(self): return StatusCode.Success - def sysExecute(self): - return self.execute() + def sysExecute(self, cppcontext): + import cppyy + self._ctx = cppyy.bind_object(cppcontext, "EventContext") + try: + ret = self.execute() + finally: + self._ctx = None + return ret def execute(self): return StatusCode.Success @@ -148,6 +155,9 @@ class Alg( CfgPyAlgorithm ): def isExecuted(self): return self._cppHandle.isExecuted() + + def getContext(self): + return self._ctx pass # PyAthena.Alg diff --git a/Control/AthenaPython/src/PyAthenaAlg.cxx b/Control/AthenaPython/src/PyAthenaAlg.cxx index c32e505fa8589abb6f6daa411cb2904c96a00022..b5c8a6e2dcb6addf4f03bafd4c499f619dd44a94 100644 --- a/Control/AthenaPython/src/PyAthenaAlg.cxx +++ b/Control/AthenaPython/src/PyAthenaAlg.cxx @@ -93,7 +93,10 @@ StatusCode Alg::execute() { // ATH_MSG_DEBUG("Executing " << name() << "..."); - return PyAthena::callPyMethod( m_self, "sysExecute" ); + PyObject* pycontext = PyCObject_FromVoidPtr ( const_cast<EventContext*>(&getContext()), nullptr); + StatusCode sc = PyAthena::callPyMethod( m_self, "sysExecute", pycontext ); + Py_DECREF (pycontext); + return sc; } void diff --git a/Control/AthenaPython/src/PyAthenaUtils.cxx b/Control/AthenaPython/src/PyAthenaUtils.cxx index b0a9815143512ed8dbad3b1bc9a35e541961b733..58ac3e935dde607e6eb798a0a47bb50b2d3b416d 100644 --- a/Control/AthenaPython/src/PyAthenaUtils.cxx +++ b/Control/AthenaPython/src/PyAthenaUtils.cxx @@ -152,7 +152,9 @@ void PyAthena::throw_py_exception (bool display) } StatusCode -PyAthena::callPyMethod( PyObject* self, const char* methodName ) +PyAthena::callPyMethod( PyObject* self, + const char* methodName, + PyObject* arg /*= nullptr*/) { // that's a bit ugly... char* method = const_cast<char*>(methodName); @@ -162,7 +164,11 @@ PyAthena::callPyMethod( PyObject* self, const char* methodName ) // call Python PyGILStateEnsure ensure; - PyObject* r = PyObject_CallMethod( self, method, const_cast<char*>("") ); + PyObject* r; + if (arg) + r = PyObject_CallMethod( self, method, const_cast<char*>("O"), arg ); + else + r = PyObject_CallMethod( self, method, const_cast<char*>("") ); if ( 0 == r ) { throw_py_exception();