ATLAS Offline Software
Loading...
Searching...
No Matches
PyAthena Namespace Reference

Classes

class  Alg
class  Aud
class  PyComponentMgr
class  Svc
class  Tool

Typedefs

typedef ::AthAlgorithm AlgBase_t
typedef ::AthService SvcBase_t
typedef ::AthAlgTool ToolBase_t

Functions

std::string repr (PyObject *o)
 returns the string representation of a python object equivalent of calling repr(o) in python
std::string str (PyObject *o)
 returns the string representation of a python object equivalent of calling str(o) in python
StatusCode callPyMethod ATLAS_NOT_THREAD_SAFE (PyObject *self, const char *method, PyObject *arg=nullptr)
 call the python method
StatusCode queryInterface ATLAS_NOT_THREAD_SAFE (PyObject *self, const InterfaceID &riid, void **ppvInterface)
 query interface binding
void pyAudit ATLAS_NOT_THREAD_SAFE (PyObject *self, const char *method, const char *evt, const char *component)
 helper function for PyAthena::Aud
void pyAudit ATLAS_NOT_THREAD_SAFE (PyObject *self, const char *method, const char *evt, const char *component, const StatusCode &sc)
 helper function for PyAthena::Aud
void throw_py_exception (bool display=true)
 helper function to capture the boilerplate code for user friendly stack trace display

Typedef Documentation

◆ AlgBase_t

Definition at line 29 of file PyAthenaAlg.h.

◆ SvcBase_t

Definition at line 30 of file PyAthenaSvc.h.

◆ ToolBase_t

Definition at line 29 of file PyAthenaTool.h.

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/4]

void pyAudit PyAthena::ATLAS_NOT_THREAD_SAFE ( PyObject * self,
const char * method,
const char * evt,
const char * component )

helper function for PyAthena::Aud

◆ ATLAS_NOT_THREAD_SAFE() [2/4]

void pyAudit PyAthena::ATLAS_NOT_THREAD_SAFE ( PyObject * self,
const char * method,
const char * evt,
const char * component,
const StatusCode & sc )

helper function for PyAthena::Aud

◆ ATLAS_NOT_THREAD_SAFE() [3/4]

StatusCode callPyMethod PyAthena::ATLAS_NOT_THREAD_SAFE ( PyObject * self,
const char * method,
PyObject * arg = nullptr )

call the python method

◆ ATLAS_NOT_THREAD_SAFE() [4/4]

StatusCode queryInterface PyAthena::ATLAS_NOT_THREAD_SAFE ( PyObject * self,
const InterfaceID & riid,
void ** ppvInterface )

query interface binding

◆ repr()

std::string PyAthena::repr ( PyObject * o)

returns the string representation of a python object equivalent of calling repr(o) in python

Definition at line 109 of file PyAthenaUtils.cxx.

110{
111 // PyObject_Repr returns a new ref.
113 PyObject* py_repr = PyObject_Repr( o );
114
115 auto [cpp_repr, flag] = RootUtils::PyGetString (py_repr);
116 Py_DECREF( py_repr );
117 if (!flag) {
119 }
120 return cpp_repr;
121}
_object PyObject
void throw_py_exception(bool display=true)
helper function to capture the boilerplate code for user friendly stack trace display
std::pair< std::string, bool > PyGetString(PyObject *s)
Convert python string -> C++ string for py2 and py3.
Definition PyGetString.h:40

◆ str()

std::string PyAthena::str ( PyObject * o)

returns the string representation of a python object equivalent of calling str(o) in python

Definition at line 124 of file PyAthenaUtils.cxx.

125{
126 // PyObject_Str returns a new ref.
128 PyObject* py_str = PyObject_Str( o );
129 auto [cpp_str, flag] = RootUtils::PyGetString (py_str);
130 Py_DECREF( py_str );
131 if ( !flag ) {
133 }
134 return cpp_str;
135}

◆ throw_py_exception()

void PyAthena::throw_py_exception ( bool display = true)

helper function to capture the boilerplate code for user friendly stack trace display

Definition at line 138 of file PyAthenaUtils.cxx.

139{
140 if (display) {
142 // fetch error
143 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0;
144 PyErr_Fetch (&pytype, &pyvalue, &pytrace);
145 Py_XINCREF (pytype);
146 Py_XINCREF (pyvalue);
147 Py_XINCREF (pytrace);
148 // restore...
149 PyErr_Restore (pytype, pyvalue, pytrace);
150 // and print
151 PyErr_Print();
152 {
153 // With py3, need to explicitly flush the python stderr
154 // for the error to be visible.
155 PyObject* f = PySys_GetObject (const_cast<char*>("stderr"));
156 PyObject* fstr = PyUnicode_FromString ("flush");
157 PyObject* x = PyObject_CallMethodObjArgs (f, fstr, NULL);
158 Py_XDECREF (x);
159 Py_XDECREF (fstr);
160 Py_XDECREF (f);
161 }
162 }
163#ifdef ATLAS_HAVE_CPYCPPYY
164 throw CPyCppyy::PyException();
165#else
166 throw std::runtime_error ("Python exception");
167#endif // ATLAS_HAVE_CPYCPPYY
168}
#define x