TChain::LoadTree

Hi all,
running an analysis over a tree, I get a “-2” when I LoadTree

  for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) {
        std::cout << "jentry: " << jentry << "\t";
        std::cout << "ientry: " << ientry << "\n";
        break;
      }
      //

Where:

ong64_t QCAnal::LoadTree(Long64_t entry)
{
// Set the environment to read one entry
   if (!fChain) return -5;
   Long64_t centry = fChain->LoadTree(entry);
   if (centry < 0) return centry;
   if (!fChain->InheritsFrom(TChain::Class()))  return centry;
   TChain *chain = (TChain*)fChain;
   if (chain->GetTreeNumber() != fCurrent) {
      fCurrent = chain->GetTreeNumber();
      Notify();
   }
   return centry;
}

Looking into TChain class, I found in the LoadTree method:

   if ((entry < 0) || ((entry > 0) && (entry >= fEntries && entry!=(theBigNumber-1) ))) {
      // -- Invalid entry number.
      return -2;
   }

I do not understand why I’m getting “-2”, since there is only one tree,
with Number of entries = 650049.

What’s wrong here?

Many thanks in advance!

Regards,
Marco

Hi,

Unless entry number somehow get bigger than 650049 or your TTree file is corrupted, I do not see why you would get -2. To investigate further I would need access to your ROOT file.

cheers,
Philippe

Hi,
in attachment you have the root tree and the analysis macro (QCAnal).

First of all: yes, you were right: I was reading beyond last event.
The problem was here:

   Long64_t nentries = fChain->GetEntriesFast();
   _nEntries = int(fChain->GetEntries ());


   std::cout << "Number of entries = " << _nEntries << std::endl;
   std::cout << "Number of entries = " << nentries << std::endl;

   Long64_t nbytes = 0, nb = 0;

   for (Long64_t jentry=0; jentry<nentries;jentry++) {

where I got:

You see that GetEntriesFast gives (apparently) meaningless number
(BTW, where does 1234567890 come from? ).

Ok, this is fixed ( I use GetEntries), but I have another problem now:

after t.Loop(), I open a TBrowser and I found all the histos empty (e.g. AdcU_Det0)

What’s wrong here?

Many thanks again!

Regards,
Marco
QCAnal.h (23.3 KB)
QCAnal.C (16.7 KB)
Sbt_Run3096.root (652 KB)

[quote]You see that GetEntriesFast gives (apparently) meaningless number
(BTW, where does 1234567890 come from? ). [/quote]This is intentionally a large number. This is used to be able to loop over the entry of chains without having to open all the files before starting to loop [GetEntries will open and close every single file in the chain]; opening all those file can be quite a slow operation if the file are not local.

When using GetEntriesFast, you ought to add a break in your loop:[code] Long64_t nentries = fChain->GetEntriesFast();
_nEntries = int(fChain->GetEntries ());

std::cout << "Number of entries = " << _nEntries << std::endl;
std::cout << "Number of entries = " << nentries << std::endl;

Long64_t nbytes = 0, nb = 0;

for (Long64_t jentry=0; jentry<nentries;jentry++) {
if (fChain->LoadTree(jentry) < 0) break;[/code]i.e. the -2 is expected.

Cheers,
Philippe.

Hi,

When running your example I noticed:Warning in <TROOT::Append>: Replacing existing TH1: beamProfU_Det0 (Potential memory leak). Warning in <TROOT::Append>: Replacing existing TH1: beamProfV_Det0 (Potential memory leak). ... etc ... which lead me to believe that you inadvertently create your histogram twice (and probably Fill one while Drawing the other)

Cheers,
Philippe.

I just saw your message… I will check and let you know.

Thanks for taking care of it!

Marco

Hi Philippe,
there was a cut on a quantity, which was preventing variables filling.

Sorry for the noise and thanks for the help!

Marco