Using TTreeReader with TChain

Dear experts,

I am trying to use TTreeReader with TChain in a macro as a practice.
I got the following warning when running the macro.

Warning in <TTreeReader::SetEntryBase()>: The current tree in the TChain Nominal has changed (e.g. by TTree::Process) even though TTreeReader::SetEntry() was called, which switched the tree again. Did you mean to call TTreeReader::SetLocalEntry()?

Should I be concerned about this warning?

The portion of my code for using the TChain with the reader.

TChain *tc = new TChain("Nominal");
tc->Add("/afs/cern.ch/work/j/jzeng/public/VBS_test/data/ttbar-*.root");
printf("%d;\n",tc->GetNtrees());
printf("%lld;\n",tc->GetEntries());

TTreeReader myReaderArr(tc);
TTreeReaderValue<float> met(myReaderArr,      "met");
TTreeReaderValue<float> weight(myReaderArr,   "weight");

while (myReaderArr.Next()) {
   if ( *met > met_min ) {
      h1 ->Fill(*met,*weight);
   }
}

Is there anything I need to add to avoid the warning?
Any feedback is welcome.

Thanks,
JC

1 Like

Hi,
the warning is due to your GetNtrees and GetEntries calls changing the “current tree” of the TChain, and TTreeReader is trying to tell you that it had to re-switch the tree to the first one in the chain to start the event loop. Can you confirm that removing those two calls the warning is not printed?

If this is the case, one thing you can do to avoid the warning is calling tc->SetEntry(0) before passing it to the TTreeReader. @Axel maybe has a more elegant solution.

Cheers,
Enrico

Thank you for the explanation.
It is good to know this warning is not a major issue.
The warning is gone after the two calls were removed.

As for your suggestion, SetEntry() is a member of the TTreeReader class. I couldn’t find a similar function for TChain/TTree.

Thanks,
JC

uhm sorry fc->LoadTree(-1) is the method that loads the first tree in the chain

Do you mean “tc->LoadTree(0)”? I tried it and it works.

Thanks,
JC.

I really meant -1, but I don’t think it makes a difference :smiley:

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