ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
PyReverseProxy Struct Reference

A utility class to convert a C++ object to a PyObject. More...

#include <PyReverseProxy.h>

Collaboration diagram for PyReverseProxy:

Public Member Functions

 ~PyReverseProxy ()
 destructor More...
 
void setFunc (PyObject *func)
 setter More...
 
void getObj (void *&obj)
 
PyObjecttoPyObj (void *obj)
 

Static Public Member Functions

static PyReverseProxygetProxy (const std::string &key)
 factory method More...
 

Private Member Functions

 PyReverseProxy ()
 default constructor : never used More...
 
 PyReverseProxy (const std::string &key)
 constructor More...
 

Private Attributes

std::string m_key
 key More...
 
void * m_obj
 C++ obj. More...
 
PyObjectm_func
 python code fragment to convert C++ obj to PyObj More...
 

Static Private Attributes

static std::unordered_map< std::string, PyReverseProxy * > s_proxyMap ATLAS_THREAD_SAFE
 proxy map protected by the python GIL. More...
 

Detailed Description

A utility class to convert a C++ object to a PyObject.

Author
Tadashi Maeno

Definition at line 27 of file PyReverseProxy.h.

Constructor & Destructor Documentation

◆ ~PyReverseProxy()

PyReverseProxy::~PyReverseProxy ( )
inline

destructor

Definition at line 30 of file PyReverseProxy.h.

31  {
33  s_proxyMap.erase(m_key);
34  }

◆ PyReverseProxy() [1/2]

PyReverseProxy::PyReverseProxy ( )
inlineprivate

default constructor : never used

Definition at line 71 of file PyReverseProxy.h.

72  {}

◆ PyReverseProxy() [2/2]

PyReverseProxy::PyReverseProxy ( const std::string &  key)
inlineprivate

constructor

Definition at line 75 of file PyReverseProxy.h.

76  : m_key(key), m_obj(0), m_func(0)
77  {}

Member Function Documentation

◆ getObj()

void PyReverseProxy::getObj ( void *&  obj)
inline

Definition at line 46 of file PyReverseProxy.h.

47  {
48  obj = m_obj;
49  }

◆ getProxy()

static PyReverseProxy* PyReverseProxy::getProxy ( const std::string &  key)
inlinestatic

factory method

Definition at line 59 of file PyReverseProxy.h.

60  {
62  PyReverseProxy* & prox = s_proxyMap[key];
63  if (!prox) {
64  prox = new PyReverseProxy(key);
65  }
66  return prox;
67  }

◆ setFunc()

void PyReverseProxy::setFunc ( PyObject func)
inline

setter

Definition at line 37 of file PyReverseProxy.h.

38  {
40  Py_DECREF(m_func);
41  m_func = func;
42  Py_INCREF(m_func);
43  }

◆ toPyObj()

PyObject* PyReverseProxy::toPyObj ( void *  obj)
inline

Definition at line 51 of file PyReverseProxy.h.

52  {
54  m_obj = obj;
55  return PyObject_CallObject(m_func,NULL);
56  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::unordered_map<std::string, PyReverseProxy *> s_proxyMap PyReverseProxy::ATLAS_THREAD_SAFE
staticprivate

proxy map protected by the python GIL.

Definition at line 90 of file PyReverseProxy.h.

◆ m_func

PyObject* PyReverseProxy::m_func
private

python code fragment to convert C++ obj to PyObj

Definition at line 86 of file PyReverseProxy.h.

◆ m_key

std::string PyReverseProxy::m_key
private

key

Definition at line 80 of file PyReverseProxy.h.

◆ m_obj

void* PyReverseProxy::m_obj
private

C++ obj.

Definition at line 83 of file PyReverseProxy.h.


The documentation for this struct was generated from the following file:
PyReverseProxy::m_key
std::string m_key
key
Definition: PyReverseProxy.h:80
PyReverseProxy
A utility class to convert a C++ object to a PyObject.
Definition: PyReverseProxy.h:28
RootUtils::PyGILStateEnsure
Definition: PyAthenaGILStateEnsure.h:20
PyReverseProxy::PyReverseProxy
PyReverseProxy()
default constructor : never used
Definition: PyReverseProxy.h:71
PyReverseProxy::m_obj
void * m_obj
C++ obj.
Definition: PyReverseProxy.h:83
python.PyAthena.obj
obj
Definition: PyAthena.py:132
PyReverseProxy::m_func
PyObject * m_func
python code fragment to convert C++ obj to PyObj
Definition: PyReverseProxy.h:86
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37