SetBranchStatus - third flag?

Dear Developers,

I would like to suggest adding a third status option to the SetBranchStatus method. Currently, there are only two possibilities:

  • process branch

  • do not process branch

In my opinion, it would be very useful to introduce an additional option: “never process branch”.

Here is the motivation:
In my analysis I sometimes need to process rare events, where the relevant information is stored in the lets call it Trigger branch. Once a valid trigger is found, I have to call TTree::GetEntry(n, 1), which forces loading of all branches — including those that I do not need (for example, hits, when I am only analyzing tracks).

With a “never process branch” option, it would be possible to permanently disable branches that are never needed e.g. those “hits”.

This could significantly improve performance of some analyses.

Hi @dwielane,

thank you for sharing your use case and idea with us. I will let our TTree Expert - @pcanal comment on this.

However, the best and easiest way to improve the performance of your analysis, is to move to RDataFrame: ROOT: ROOT::RDataFrame Class Reference where you can take advantage of many optimisations starting from implicit Multi Threading. It will also allow you to move to RNTuple seamlessly. In fact, regarding the new features for analysis, all the effort from our side as the ROOT team is put into RDataFrame.

We have a number of tutorials from which you can learn about different RDataFrame features: ROOT: RDataFrame analysis tutorials . I would be happy to help you with the transition of your analysis to RDF in case you have any further questions.

Cheers,

Marta

Hi,

I’m not sure if this will be easy, the current architecture assumes that users have an array of bidirectional pointers (each to a different branch to write/read stuff). I think it is possible to do this in RDataFrame but I will have to change a lot of things. But if someday I will try to this and have a problem I will ask on this forum :slight_smile:

We do not plan to extend the TTree interfaces at the moment. Note that it is usually more efficient to call GetEntry on each of the top level branches you need rather than use SetBranchStatus. You can also emulate the feature you describe by simply removing the branches that should never be read from the list of branches of the TTree.

auto child = tree->GetBranch(unwanted_branch_name);
auto parent = child->GetMother()->GetSubBranch(child);
parent->GetListOfBranches()->Remove(child);
parent->GetListOfBranches()->Compress();

Note that if you have a chain, you need to execute this at each file boundary, so you would also need attach a notify action to the chain. (See ROOT: TNotifyLink< Type > Class Template Reference and See also the doc of TChain::LoadTree for an explanation on the usage of the notify object by the chain and TTreeReader TChain notify on change of file - #5 by zhubacek)