Cannot read integral-valued branches from TTree with PyROOT (originally written as custom object data members)

Hi,

One more general question I have is whether or not it is good practice to have one branch in a tree with multiple sub-branches. Wouldn’t it be better to remove the top branch and have multiple branches instead? I get the current construction because I write the MyResults object to file, so it’s done automatically. Is there a way to flatten the sub-branches into branches?

When you store a branch (i.e. you invoke tree.Branch) you can indicate the split level of that branch. This will determine if it will be stored as a whole or it will be automatically split into sub-branches. Splitting or not splitting depends on what you want to do: if you are sure you will always need to read the whole branch, no need to split. If on the contrary you will likely be accessing sub-branches and you only want to read those, then split. More info here:

https://root.cern.ch/doc/master/classTTree.html
https://root.cern.ch/root/htmldoc/guides/users-guide/Trees.html

Note that what I explained above does not apply if you use the Python syntax to access the branches (e.g. event.binding_cells.foo). This is nice syntax-wise, but it also reads the whole branch. If you wanted to benefit from the optimization, you would need to do (from Python) SetBranchAddress + GetEntry. Alternatively, you could also use RDataFrame to efficiently read tree data from Python:

https://root.cern/doc/master/classROOT_1_1RDataFrame.html

1 Like