Dear developers,
I have been using ROOT in python for a while and I have a couple of requests/suggestions. This might very well be a result of my ignorance for not knowing python well enough, and/or not taking into account all the different scenarios ROOT objects have to account for. I also still do not understand the ROOT data structure very well.
Say I have a TFile object, "myfile", which contains a tree "mytree", which contains "mybranch1" and "mybranch2". In my opinion based on how I believe most python objects are structured, this should then work:
for tree in myfile:
print "Tree name:", tree.GetName() for branch in tree: print "Branch name:",branch.GetName()
Which should then output:
Tree name: mytree
Branch: mybranch1
Branch: mybranch2
This can be done by defining the __iter__() function for the python objects (right?).
A second thing I would have loved to see is a built-in function for the branches which extracts a numpy array of the data in the branch. I often prefer to get the numpy arrays because they behave more like python objects which I know how to manipulate (slicing, averages...). On the other hand, since the ROOT objects are so focused on events, you might not want to promote this kind of usage at all? I really don't understand the structure of the data types well enough to have a clear idea in this matter. Comments are most welcome!
I attach a small example script which sort of exemplifies my request. The iteration part I show with extended classes for TFile and TTree, which I consider to be a very easy extension. The branch2numpy() function works, but it is dead slow for large amounts of data. I could probably improve it by using eg. cython, but it would be better if a person that know both root and python to a much better degree than me would write some similar functionality built into PyROOT.
For reference, I use ROOT version 5.30.00 in case some of this is already implemented in svn.
Cheers,
Yngve
This archive was generated by hypermail 2.2.0 : Thu Aug 11 2011 - 11:50:01 CEST