#include "Python.h"
#include "AthenaPython/PyAthenaUtils.h"
#include "RootUtils/PyAthenaGILStateEnsure.h"
#include "RootUtils/PyGetString.h"
#include "GaudiKernel/IInterface.h"
#include "GaudiKernel/INamedInterface.h"
#include "GaudiKernel/StatusCode.h"
#include "TPython.h"
#include "CPyCppyy/PyException.h"
#include "DataModelRoot/RootType.h"
#include "TClassRef.h"
#include <string>
#include <iostream>
#include <sstream>
Go to the source code of this file.
|
StatusCode PyAthena::callPyMethod | ATLAS_NOT_THREAD_SAFE (PyObject *self, const char *methodName, PyObject *arg) |
|
StatusCode PyAthena::queryInterface | ATLAS_NOT_THREAD_SAFE (PyObject *self, const InterfaceID &riid, void **ppvInterface) |
|
void PyAthena::pyAudit | ATLAS_NOT_THREAD_SAFE (PyObject *self, const char *method, const char *evt, const char *component) |
| helper function for PyAthena::Aud More...
|
|
void PyAthena::pyAudit | ATLAS_NOT_THREAD_SAFE (PyObject *self, const char *method, const char *evt, const char *component, const StatusCode &sc) |
| helper function for PyAthena::Aud More...
|
|
◆ ATLAS_NOT_THREAD_SAFE() [1/4]
void PyAthena::pyAudit ATLAS_NOT_THREAD_SAFE |
( |
PyObject * |
self, |
|
|
const char * |
method, |
|
|
const char * |
evt, |
|
|
const char * |
component |
|
) |
| |
◆ ATLAS_NOT_THREAD_SAFE() [2/4]
void PyAthena::pyAudit ATLAS_NOT_THREAD_SAFE |
( |
PyObject * |
self, |
|
|
const char * |
method, |
|
|
const char * |
evt, |
|
|
const char * |
component, |
|
|
const StatusCode & |
sc |
|
) |
| |
◆ ATLAS_NOT_THREAD_SAFE() [3/4]
StatusCode PyAthena::callPyMethod ATLAS_NOT_THREAD_SAFE |
( |
PyObject * |
self, |
|
|
const char * |
methodName, |
|
|
PyObject * |
arg |
|
) |
| |
Definition at line 167 of file PyAthenaUtils.cxx.
172 char*
method =
const_cast<char*
>(methodName);
175 if ( 0 ==
self || 0 ==
method ) {
return StatusCode::FAILURE; }
181 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"O"),
arg );
183 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"") );
189 #if PY_VERSION_HEX < 0x03000000
190 if ( PyInt_Check(
r ) || PyLong_Check(
r) ) {
193 if ( PyLong_Check(
r ) ) {
203 if ( PyObject_HasAttrString (
r, (
char*)
"getCode") ) {
204 c = PyObject_CallMethod(
r,
205 const_cast<char*
>(
"getCode"),
206 const_cast<char*
>(
"") );
211 std::ostringstream
msg;
212 msg <<
"unexpected returned type from (python) function '"
216 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
226 if ( PyLong_Check (
c) ) {
233 std::ostringstream
msg;
234 msg <<
"unexpected returned type from (python) function '"
235 <<
method <<
"().getCode()' [got "
238 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
242 return StatusCode::FAILURE;
◆ ATLAS_NOT_THREAD_SAFE() [4/4]
StatusCode PyAthena::queryInterface ATLAS_NOT_THREAD_SAFE |
( |
PyObject * |
self, |
|
|
const InterfaceID & |
riid, |
|
|
void ** |
ppvInterface |
|
) |
| |
Definition at line 245 of file PyAthenaUtils.cxx.
254 <<
"==============[ " <<
PyAthena::repr(
self) <<
" ]=============="
260 const_cast<char*
>(
"__class__") );
267 bases = PyObject_CallMethod(
type,
268 const_cast<char*
>(
"mro"),
269 const_cast<char*
>(
"") );
270 if ( !bases || !PySequence_Check( bases ) ) {
276 const int nBases = PySequence_Size( bases );
277 if ( -1 == nBases ) {
283 for (
int i = 0;
i < nBases; ++
i ) {
289 unsigned long id = 0;
290 unsigned long major = 0;
291 unsigned long minor = 0;
292 if ( !fetchInterfaceId(
base,
id, major, minor ).isSuccess() ) {
297 InterfaceID pyID(
id, major, minor );
298 if ( !pyID.versionMatch( riid ) ) {
304 pyname = PyObject_GetAttrString(
base,
305 const_cast<char*
>(
"__name__") );
313 const std::string cppName = ((MyObjProxy*)
self)->m_class->GetName();
315 std::cout <<
"::: would like to do: *ppvInterface = static_cast<"
316 << cppBaseName <<
"*>( "
317 << cppName <<
"|m_self );"
321 const RootType toType( cppBaseName );
322 void* objProxy = TPython::CPPInstance_AsVoidPtr(
self);
323 *ppvInterface = objProxy;
324 if (fromType.Class() && toType.Class())
325 *ppvInterface = fromType.Class()->DynamicCast (toType.Class(), objProxy);
326 std::cout <<
"::: [" << cppName <<
"]: "
327 << ( (
bool)fromType ?
" OK" :
"ERR" )
330 <<
"::: [" << cppBaseName <<
"]: "
331 << ( (
bool)toType ?
" OK" :
"ERR" )
332 <<
" " << *ppvInterface
334 std::cout <<
"::: *ppvInterface: " << *ppvInterface << std::endl;
335 if ( *ppvInterface ) {
337 const_cast<char*
>(
"addRef"),
338 const_cast<char*
>(
"") );
339 if (
c && PyLong_Check(
c) ) {
340 sc = StatusCode::SUCCESS;
345 if (
sc.isSuccess() ) {
def call(args, bufsize=0, executable=None, stdin=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, message="", logger=msg, loglevel=None, timeout=None, retry=2, timefactor=1.5, sleeptime=10)