Home | News | Documentation | Download

Access Value Readers from TTreeReader

Dear Experts,

Let’s say I have the following:

TTreeReader fReader;
TTreeReaderValue<Bool_t> v1{fReader, "b1"}
TTreeReaderValue<Float_t> v2{fReader, "b2"}

Is there any way to get from fReader a list with b1 and b2 strings?

Use case scenario:

PROOF is processing a TChain with a very large number of files, but a few of the TTrees included in those files didn’t have the expected branches, so in that case I’d like to skip the file and inform the user that a file has been skipped. However if I use fReader.SetEntry(nEntry) (in TSelector::Process) the process fails and crash. So I’d like to have the option to check that all the branches (large) are contained in the TTree during TSelector::Init(TTree *tree), for that I can use TTree::FindBranch but as the number of branches is large I’d like to retrieve the list of registered values from fReader. Is there a way to do that?

I don’t think you can list the value readers of a tree reader. Perhaps @pcanal or @Axel have an idea.

Does the application crash in fReader.SetEntry itself or at a later point? If it crashes only later, you could check the result of SetEntry, which should be different from 0 if a branch is missing. You could also use a helper function in the definition of the TTreeReaderValue in order to collect the branch name, like so

TTreeReaderValue<int> v1(myReader, SaveBranchName("b1"));

with

const char *SaveBranchName(const char *name)
{
   // store `name` somewhere
   return name;
}

Cheers,
Jakob

1 Like

Thanks @jblomer, that’s a great idea! Yes, it does crash right on fReader.SetEntry.

@Axel, is there a way to do this? and to register/deregister values from TTreeReader? I see there are some private methods to do it (1) but wondering if those methods can be exposed publicly for future development. This would be very useful for CMS, with NanoAOD (plain root files) which do not have a fixed structure across datasets (sets of root files), see (2), being able to register/deregister values prior to TTree processing would be a nice feature to have. The way I’m handling this right now is kind of hacky, registering a branch that may not exist and use it to reset the value if the branch is present. If you see this is feasible, with your guidance I can help with the implementation. Let me know what you think

(1) https://github.com/root-project/root/blob/master/tree/treeplayer/inc/TTreeReader.h#L265
(2) https://github.com/cms-nanoAOD/cmssw/issues/528