Keep only certain leaves in a ttree

Dear experts,

I am filling two branches in a TTree, one with an event-wise object and one with a particle-wise object (TClonesArray). Each branch contains several TLeaf.
Everything works, but since I have to run this code over large datasets in a controlled environment, the CPU usage and the memory allocation are too high if I do it like this.
The fastest way that I was thinking to solve this in order to avoid to reconfigure all my output objects, would be not to store several TLeaf that i don’t need.
Is this possible? Basically, to keep only certain TLeaf after filling the tree (or before that).

Thank you in advance!

I think @pcanal can help.

Before reconfiguring your files, you should investigate if you actually need to read all the data, doing partial read (only a few branches) is one of the main ‘feature’ of a TTree.

I.e. how do you read the data?

Thank you for your replies.
I fill each branch with an object. In the case of the track branch, the object is a TClonesArray type that has several observables in it, and when I fill the tree, this branch has several TLeaf, one for each observable.
As you suggested, I don’t need to read all the TLeaf, but I don’t want them filled at runtime neither. What I would need is to fill the branch with the same object, and what I’m looking for is a way to get rid of all the TLeaf that I don’t need, before the tree is filled.

In principle, you would need to create a stripped-down tree, only with the selected “leaves” (“branches”) you want later.

In general, you could also “prevent some class data member from being written to the file” (a.k.a. “transient data member”): ROOT Manual → Functional parts → I/O Concepts → Excluding data members from I/O

1 Like

If you know at compile time, you can actually mark of the “uninteresting” data member as being transient. (Alternatively you might be able to remove the uninteresting sub-branches from the list of branches of its parent before starting to Fill)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.