[ROOT-6885] TChain::Process with more than kBigNumber entries without reading TTree headers Created: 08/Nov/14  Updated: 21/Sep/15  Resolved: 21/Sep/15

Status: Closed
Project: ROOT
Component/s: Core Libraries
Affects Version/s: 5.34/23
Fix Version/s: None

Type: Bug Priority: High
Reporter: Valery Yundin Assignee: Philippe Canal
Resolution: Fixed Votes: 0
Labels: None


Issue Links:
relates to ROOT-7625 TTree::GetEntries(const char*selectio... Closed


TChain::Process stops prematurely after kBigNumber (1234567890) entries if trees were added without reading their sizes.

One can add files to TChain without touching them by using default value of the second parameter of AddFile:
AddFile(const char* name, Long64_t nentries = kBigNumber, const char* tname = "");

In which case we take the second branch below and set fEntries = nentries = kBigNumber

TChain::AddFile at TChain.cxx:515

   if (nentries > 0) {
      if (nentries != kBigNumber) {
         fTreeOffset[fNtrees+1] = fTreeOffset[fNtrees] + nentries;
         fEntries += nentries;
      } else {
         fTreeOffset[fNtrees+1] = theBigNumber;
         fEntries = nentries;

Which is problematic, because TTreePlayer::Process gets it from TTree::GetEntriesFriend via GetEntriesToProcess and uses it to decide how many entries to process:

TTreePlayer::Process at TTreePlayer.cxx:2109

nentries = GetEntriesToProcess(firstentry, nentries);

As a result it stops after kBigNumber (1234567890) entries

Later when another tree is loaded on demand it sets fEntries = fTreeOffset[fNtrees] = theBigNumber

TChain::LoadTree at TChain.cxx:1530

   if (fTreeOffset[fTreeNumber+1] != (fTreeOffset[fTreeNumber] + nentries)) {
      fTreeOffset[fTreeNumber+1] = fTreeOffset[fTreeNumber] + nentries;
      fEntries = fTreeOffset[fNtrees];

It would make sense to set fEntries to theBigNumber already in TChain::AddFile so TTreePlayer::Process uses it as the upper limit.
So line TChain.cxx:521 would look like

         fEntries = theBigNumber;

Nothing in TChain relies on fEntries being equal to kBigNumber and it changes to theBigNumber after the first tree is loaded anyway.

PS Line numbers correspond to git tag v5-34-23

Comment by Valery Yundin [ 09/Nov/14 ]

There is a not-so-obvious workaround:
Call TChain::GetFile before calling TChain::Process. It will load first tree and fEntries will be set to theBigNumber. This method has no extra overhead unlike calling TChain::GetEntries()

Comment by Philippe Canal [ 21/Sep/15 ]


This problem has been fixed in the v5-34, v6-02 and 6-04 patch branches as well as in the master (where kBigNumber and theBigNumber are actually also merged).

Thanks for your report and patience.

Generated at Fri May 29 22:20:46 CEST 2020 using Jira 8.3.4#803005-sha1:1f96e09b3c60279a408a2ae47be3c745f571388b.