StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Chain.C
1 #include "Riostream.h"
2 #include "TChain.h"
3 #include "TFile.h"
4 #include "TList.h"
5 
6 TChain *Chain(const Char_t *TreeName = "T") {
7  TChain *chain = 0;
8  TCollection *files = gROOT->GetListOfFiles();
9  if (! files) return chain;
10  TIter next(files);
11  TFile *f = 0;
12  chain = new TChain(TreeName);
13  Int_t NFiles = 0;
14  ULong64_t nEvents = 0;
15  ULong64_t nEvTot = 0;
16  while ( (f = (TFile *) next()) ) {
17  TTree *tree = (TTree *) f->Get(TreeName);
18  if (tree) {
19  NFiles++;
20  nEvents = tree->GetEntries();
21  cout << "#\t" << NFiles << "\t" << f->GetName() << "\t" << nEvents << endl;
22  nEvTot += nEvents;
23  chain->Add(f->GetName());
24  }
25  delete f;
26  }
27  cout << "chained " << NFiles << " files \t"
28  << "with total " << nEvTot << " events \t"
29  << "chain returned pointer: " << chain << endl;
30  return chain;
31 }