#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 164 of file PyAthenaUtils.cxx.
169 char*
method =
const_cast<char*
>(methodName);
172 if ( 0 ==
self || 0 ==
method ) {
return StatusCode::FAILURE; }
178 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"O"),
arg );
180 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"") );
186 if ( PyLong_Check(
r ) ) {
195 if ( PyObject_HasAttrString (
r, (
char*)
"getCode") ) {
196 c = PyObject_CallMethod(
r,
197 const_cast<char*
>(
"getCode"),
198 const_cast<char*
>(
"") );
203 std::ostringstream
msg;
204 msg <<
"unexpected returned type from (python) function '"
208 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
218 if ( PyLong_Check (
c) ) {
225 std::ostringstream
msg;
226 msg <<
"unexpected returned type from (python) function '"
227 <<
method <<
"().getCode()' [got "
230 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
234 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 237 of file PyAthenaUtils.cxx.
246 <<
"==============[ " <<
PyAthena::repr(
self) <<
" ]=============="
252 const_cast<char*
>(
"__class__") );
259 bases = PyObject_CallMethod(
type,
260 const_cast<char*
>(
"mro"),
261 const_cast<char*
>(
"") );
262 if ( !bases || !PySequence_Check( bases ) ) {
268 const int nBases = PySequence_Size( bases );
269 if ( -1 == nBases ) {
275 for (
int i = 0;
i < nBases; ++
i ) {
281 unsigned long id = 0;
282 unsigned long major = 0;
283 unsigned long minor = 0;
284 if ( !fetchInterfaceId(
base,
id, major, minor ).isSuccess() ) {
289 InterfaceID pyID(
id, major, minor );
290 if ( !pyID.versionMatch( riid ) ) {
296 pyname = PyObject_GetAttrString(
base,
297 const_cast<char*
>(
"__name__") );
305 const std::string cppName =
reinterpret_cast<MyObjProxy*
>(
self)->m_class->GetName();
307 std::cout <<
"::: would like to do: *ppvInterface = static_cast<"
308 << cppBaseName <<
"*>( "
309 << cppName <<
"|m_self );"
313 const RootType toType( cppBaseName );
314 void* objProxy = TPython::CPPInstance_AsVoidPtr(
self);
315 *ppvInterface = objProxy;
316 if (fromType.Class() && toType.Class())
317 *ppvInterface = fromType.Class()->DynamicCast (toType.Class(), objProxy);
318 std::cout <<
"::: [" << cppName <<
"]: "
319 << ( (
bool)fromType ?
" OK" :
"ERR" )
322 <<
"::: [" << cppBaseName <<
"]: "
323 << ( (
bool)toType ?
" OK" :
"ERR" )
324 <<
" " << *ppvInterface
326 std::cout <<
"::: *ppvInterface: " << *ppvInterface << std::endl;
327 if ( *ppvInterface ) {
329 const_cast<char*
>(
"addRef"),
330 const_cast<char*
>(
"") );
331 if (
c && PyLong_Check(
c) ) {
332 sc = StatusCode::SUCCESS;
337 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)