Re: Recovering the underlying TObject from a PyObject

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


Hello,

attached some lines to reproduce the problem.

Trying this on different machines it works as expected on one but not on the other. So I suspect something strange going on on my OsX laptop (where it does not work).

Works:
Python 2.4.6
ROOT 5.22/00a
kernel 2.6.9-89.0.26.ELsmp on some kind of redhat derivative

Does not work:
Python 2.6.1
ROOT 5.26/00
kernel 10.4.0 Darwin

Tim

On 9 August 2010 11:17, Tim Head <betatim_at_gmail.com> wrote:
> 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/
>

-- 
http://tim.jottit.com/

  • application/octet-stream attachment: gettobj.C
  • application/octet-stream attachment: getobj.py
Received on Mon Aug 09 2010 - 11:30:51 CEST

This archive was generated by hypermail 2.2.0 : Tue Aug 10 2010 - 17:50:01 CEST