for i, event in enumerate(tree):
if i == 42:
print(event.secret)
break
Question 1:
Is there more pythonic way of extracting data content, without unnecessary loop in method 3 and avoiding array as in method 2?
Something like:
print( tree.GetEventAtIndex(42).secret ) # or even...
print( tree[42].secret )
Question 2:
Can I read somewhere what is actually variable event in the for event in tree ?
As a newbie, I would naively assume it is just an “item” in a “tree” iterable object, but it seems more complicated…
items = [ MyClass() ]
type(items[0]) # obviously MyClass
for event in tree:
type(event) # not obviously, still TTree: <class cppyy.gbl.TTree at 0x58028e0>
Question 3:
Do I miss some other more aesthetic methods of extracting TTree content into variables than listed in the three methods above? Please share!
where rdfentry_ is the entry number (created by default, you don’t need to do it yourself). There may be a better option, but making a sum of 1 element is fast and allows you to select the branch/leaf and use GetValue.
Depending on what else you do, it may be slower or faster than your methods 2 or 3, and if you also have ROOT.EnableImplicitMT(), it may make it faster also depending on what else you do in the code.
yes, I noticed but didn’t see another way (I’m still starting to have a look at RDataFrame so don’t know much yet), and I suppose the gains (mainly through multi-threading I guess) will be noticeable when more stuff is done, unlike this very simple example, right? At least when looping over a big TChain to fill a couple of histograms, I saw a big difference between using SetBranchAddress and a dataframe.