From PyROOT to C++: how?


I want to rewrite a part of my python+ROOT script in C++. I created the “” script, and I wrote a dummy C++ code for my function. So when I make a python call


it goes to the C++ code:

static PyObject *
myfunc(PyObject *self, PyObject *args)
PyObject *o;
if( !PyArg_ParseTuple(args, “O”, &o) )
return NULL;

std::printf("We are here... So what?\n");

// TObject *oo = ?????? (how to get back the ROOT object?)

return Py_BuildValue("");


and it prints the message which I want… So far so good. But if my original ‘o’ object was created as:

o = ROOT.TTree(....)

how can I get it back to my C++ code:

TTree *_o = ????????

Thank you very much in advance!


just checked in code for this purpose last week, which would be used along these lines:

TTree* tree = (TTree*)TPython::ObjectProxy_AsVoidPtr( self ); if ( tree ) tree->.... ;
There’s no easy way to do this, however, with any of the current releases (other than using a struct with the same memory layout as the ObjectProxy type; the void* pointer to the ROOT object is the first after PyObject_HEAD).