Recovering the underlying TObject from a PyObject

From: Tim Head <betatim_at_gmail.com>
Date: Mon, 9 Aug 2010 11:17:29 +0200


Hello PyROOTs,

I want to write a function in C(++) which access a attribute of a python object and then do things with it. I happen to know that the object is a TTree, so I would like to convert the PyObject* I get from PyObject_GetAttr() to a TTree*. I thought the tool for the job was something like:

// Access the "tree" attribute of the self object
PyObject* pytree = PyObject_GetAttr(self, "tree");
// Turn it into a TTree*

TTree* tree = (TTree*)TPython::ObjectProxy_AsVoidPtr(pytree);

However with this tree will always be 0, pytree also seems to fail ObjectProxy_Check().

The reason I want to have a TTree* is because then I can write tree->GetEntries() etc instead of having to do the roundabout thing of using PyObject_CallMethod().

Maybe someone can enlighten me how to do this properly ;)

For completeness this is with Python 2.6.1 and ROOT 5.26/00

Tim

-- 
http://tim.jottit.com/
Received on Mon Aug 09 2010 - 11:17:41 CEST

This archive was generated by hypermail 2.2.0 : Mon Aug 09 2010 - 11:50:01 CEST