[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
Environment:

All


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

 Description   

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];
      element->SetNumberEntries(nentries);

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



 Comments   
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 ]

Hi,

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.
Philippe.

Generated at Tue Sep 24 10:48:47 CEST 2019 using Jira 7.13.1#713001-sha1:5e06076c2d215a6f699b7e5c90ab2fae7ba5a1ce.