Problem adding ntuples to chain

Hi all,

I’m trying to write a program that will add a series of ntuples from several root files to a tree. However, fChain->GetEntriesFast() returns what I think is kBigNumber, 1234567890, although definitely isn’t right number of entries. I’d like to get the right number of entries so I can monitor my progress as I loop through fChain.

I initiate the tree with the following code:

TChain* theChain = new TChain("ntp1",""); //this chain will hold the ntp1 ntuples theChain->Add("rootfiles/*Moderato.root"); //grabs the ntp1 file from file.root and adds it to the chain //theChain->Add("rootfiles/B0ToPi0Pi0-Run1-OnPeak-R18b-v04-1Moderato.root"); //This makes things much faster, for testing fChain = theChain; TTree* mytree = fChain; Init(mytree);

This is the init function:

[code]void myclass::Init(TTree *tree)
// The Init() function is called when the selector needs to initialize
// a new tree or chain. Typically here the branch addresses of the tree
// will be set. It is normaly not necessary to make changes to the
// generated code, but the routine can be extended by the user if needed.
// Init() will be called many times when running with PROOF.

// Set branch addresses
if (tree == 0) return;
fChain = tree;
fCurrent = -1;

//and so on…

Any ideas?

Edit: my code executes correctly, but I cannot track my progress. Well, there is a segmentation fault that pops up from time to time, but I think I have a problem with one of my arrays somewhere…

[quote] fChain->GetEntriesFast() returns what I think is kBigNumber, 1234567890,[/quote]This is the intend. GetEntriesFast is returning a number that is greater or equal the total number of entries.
If you want the real number of entries, call the slow version: GetEntries. This will open each and every files and return the actual number of entries.


That works. Thanks for your help.

Note that if you are using chains that contain A LOT of files on remote servers, it can take a LONG TIME (> 10 minutes) and create a lot of unnecessary load on disk servers by using ‘GetEntries()’ instead of ‘GetEntriesFast()’ (we have crashed servers this way).

If you want ot use ‘GetEntriesFast()’ instead, you can then just loop until the chain tells you that it is empty:

   long loadTreeFlag = chainPtr->LoadTree (currentEntry++);

   if (m_loadTreeFlag < 0)
      // All Done
   chainPtr->GetEntry (m_loadTreeFlag);