ATLAS Offline Software
Static Public Member Functions | List of all members
RootUtils::PyROOTPickle Class Reference

#include <PyROOTPickle.h>

Collaboration diagram for RootUtils::PyROOTPickle:

Static Public Member Functions

static void Initialize (PyObject *libpyroot_pymodule, PyObject *objectproxy_pytype)
 Install the pickling of ObjectProxy's functionality. More...
 

Detailed Description

Definition at line 47 of file PyROOTPickle.h.

Member Function Documentation

◆ Initialize()

void RootUtils::PyROOTPickle::Initialize ( PyObject libpyroot_pymodule,
PyObject cppinstance_pytype 
)
static

Install the pickling of ObjectProxy's functionality.

Install the pickling of CPPInstance's functionality.

Parameters
libpyroot_pymoduleThe libPyROOT python module
objectproxy_pytypeThe ObjectProxy python type
libpyroot_pymoduleThe libPyROOT python module
CPPInstance_pytypeThe CPPInstance python type

Definition at line 112 of file PyROOTPickle.cxx.

113 {
114  Py_INCREF( libpyroot_pymodule );
115  PyTypeObject* pytype = (PyTypeObject*)cppinstance_pytype;
116 
117  // Don't change this name to CPPInstance since it's saved in pickles.
118  static PyMethodDef s_pdefExp = { (char*)"_ObjectProxy__expand__",
119  (PyCFunction)CPPInstanceExpand, METH_VARARGS, (char*)"internal function" };
120 
121  PyObject* pymname = PyUnicode_FromString( PyModule_GetName( libpyroot_pymodule ) );
122  gExpand = PyCFunction_NewEx( &s_pdefExp, NULL, pymname );
123  Py_DECREF( pymname );
124  Bool_t isOk = PyObject_SetAttrString( libpyroot_pymodule, s_pdefExp.ml_name, gExpand ) == 0;
125  Py_DECREF( gExpand ); // is moderately risky, but Weakref not allowed (?)
126 
127  if ( ! isOk ) {
128  Py_DECREF( libpyroot_pymodule );
129  PyErr_SetString( PyExc_TypeError, "could not add expand function to libPyROOT" );
130  return;
131  }
132 
133  static PyMethodDef s_pdefRed = { (char*)"__reduce__",
134  (PyCFunction)CPPInstanceReduce, METH_NOARGS, (char*)"internal function" };
135 
136  PyObject* descr = PyDescr_NewMethod( pytype, &s_pdefRed );
137  isOk = PyDict_SetItemString( pytype->tp_dict, s_pdefRed.ml_name, descr) == 0;
138  Py_DECREF( descr );
139  if ( ! isOk ) {
140  Py_DECREF( libpyroot_pymodule );
141  PyErr_SetString( PyExc_TypeError, "could not add __reduce__ function to CPPInstance" );
142  return;
143  }
144 
145  Py_DECREF( libpyroot_pymodule );
146 }

The documentation for this class was generated from the following files:
RootUtils::CPPInstanceReduce
PyObject * CPPInstanceReduce(PyObject *self, PyObject *)
PyROOT object proxy pickle support.
Definition: PyROOTPickle.cxx:36
python.TransformConfig.descr
descr
print "%s.properties()" % self.__name__
Definition: TransformConfig.py:360
RootUtils::CPPInstanceExpand
PyObject * CPPInstanceExpand(PyObject *, PyObject *args)
Helper for (un)pickling of CPPInstance's.
Definition: PyROOTPickle.cxx:86
PyObject
_object PyObject
Definition: IPyComponent.h:26