Re: pyroot question about TTrees containing TObjects

From: Erkcan Ozcan <erkcan.ozcan_at_cern.ch>
Date: Fri, 20 Jan 2012 21:39:48 +0000


Hi Wim,

Thanks for the quick response.

On 20 Jan 2012, at 22:57, <wlavrijsen_at_lbl.gov<mailto:wlavrijsen_at_lbl.gov>> wrote:

I'm not really understanding: you do have a MakeClass(), but no definition of the classes?

Or are you working from the streamer only? The python code is implemented using TClass, not TStreamer, and so requires a full class definition. Of course, if you do have a MakeClass generated code, you can use it to provide a class header: as long as the layout is the same as the original class used to write the data, it can be read back in the new class.

No, I did not do a MakeClass(): I want to use the TTree without a MakeClass(). I do not have the source code for the original classes either. So I have nothing and I am looking for a magic python solution. :-)

I already found it quite magic that I can immediately do things like "chain.Photon_size" without doing anything except opening the file and getting the TTree (as described in the ROOT User's Manual), and I was wondering whether that magic would apply to more complex TTrees.

chain.Photon[1] returns a <ROOT.TObject object ("TObject")>, which has no Pt member in its dictionary.

Yes, b/c the down-casting fails since there is no TClass available for the actual class, and hence it sticks to the original class, which is a TObject.

Yes, well this does not surprise at all. What really surprised me was the above fact that the TTree python object had "members" (chain.Photon_size) that are named after the branches. So then I got spoilt and wanted to see whether TObject objects from TTrees also were magically aware of their C++ members. Or whether TTree objects had members that are named after the members of the TObjects they contain.

If they had, it would be extremely cool - I would stop teaching students to do the following, as it confuses them when they start: "MakeClass() first, then load it, then make instances of the class generated by MakeClass(), then start wting code". Instead I would just tell them to open the ROOT file with pyroot and immediately start using every branch in the TTree simply by accessing the members of the python TTree object.

Cheers,
e.

Best regards,

          Wim
--

WLavrijsen@lbl.gov<mailto:WLavrijsen@lbl.gov> -- +1 (510) 486 6411 -- www.lavrijsen.net<http://www.lavrijsen.net>

--

In case they are not written explicitly, please be aware that my greetings and farewell are inherently implied in this email. If you have emailed me and did not get a quick response, please accept by apologies and resend, as I parse through more than 200 non-spam emails per day.

V. Erkcan Özcan, PhD
ATLAS Bogazici Teamleader
Associate Professor
Bogazici University
Department of Physics Received on Fri Jan 20 2012 - 22:39:58 CET

This archive was generated by hypermail 2.2.0 : Fri Jan 20 2012 - 23:50:01 CET