#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 168 of file PyAthenaUtils.cxx.
173 char*
method =
const_cast<char*
>(methodName);
176 if ( 0 ==
self || 0 ==
method ) {
return StatusCode::FAILURE; }
182 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"O"),
arg );
184 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"") );
190 #if PY_VERSION_HEX < 0x03000000
191 if ( PyInt_Check(
r ) || PyLong_Check(
r) ) {
194 if ( PyLong_Check(
r ) ) {
204 if ( PyObject_HasAttrString (
r, (
char*)
"getCode") ) {
205 c = PyObject_CallMethod(
r,
206 const_cast<char*
>(
"getCode"),
207 const_cast<char*
>(
"") );
212 std::ostringstream
msg;
213 msg <<
"unexpected returned type from (python) function '"
217 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
227 if ( PyLong_Check (
c) ) {
234 std::ostringstream
msg;
235 msg <<
"unexpected returned type from (python) function '"
236 <<
method <<
"().getCode()' [got "
239 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
243 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 246 of file PyAthenaUtils.cxx.
255 <<
"==============[ " <<
PyAthena::repr(
self) <<
" ]=============="
261 const_cast<char*
>(
"__class__") );
268 bases = PyObject_CallMethod(
type,
269 const_cast<char*
>(
"mro"),
270 const_cast<char*
>(
"") );
271 if ( !bases || !PySequence_Check( bases ) ) {
277 const int nBases = PySequence_Size( bases );
278 if ( -1 == nBases ) {
284 for (
int i = 0;
i < nBases; ++
i ) {
290 unsigned long id = 0;
291 unsigned long major = 0;
292 unsigned long minor = 0;
293 if ( !fetchInterfaceId(
base,
id, major, minor ).isSuccess() ) {
298 InterfaceID pyID(
id, major, minor );
299 if ( !pyID.versionMatch( riid ) ) {
305 pyname = PyObject_GetAttrString(
base,
306 const_cast<char*
>(
"__name__") );
314 const std::string cppName = ((MyObjProxy*)
self)->m_class->GetName();
316 std::cout <<
"::: would like to do: *ppvInterface = static_cast<"
317 << cppBaseName <<
"*>( "
318 << cppName <<
"|m_self );"
322 const RootType toType( cppBaseName );
323 void* objProxy = TPython::CPPInstance_AsVoidPtr(
self);
324 *ppvInterface = objProxy;
325 if (fromType.Class() && toType.Class())
326 *ppvInterface = fromType.Class()->DynamicCast (toType.Class(), objProxy);
327 std::cout <<
"::: [" << cppName <<
"]: "
328 << ( (
bool)fromType ?
" OK" :
"ERR" )
331 <<
"::: [" << cppBaseName <<
"]: "
332 << ( (
bool)toType ?
" OK" :
"ERR" )
333 <<
" " << *ppvInterface
335 std::cout <<
"::: *ppvInterface: " << *ppvInterface << std::endl;
336 if ( *ppvInterface ) {
338 const_cast<char*
>(
"addRef"),
339 const_cast<char*
>(
"") );
340 if (
c && PyLong_Check(
c) ) {
341 sc = StatusCode::SUCCESS;
346 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)