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");

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.


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.


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.


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.


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.