StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IO.cxx
1 
2 #include "IO.h"
3 #include "TChain.h"
4 #include "TSystem.h"
5 #include <iostream>
6 
7 ClassImp(IO)
8 
9 IO::IO(const char* dir, const char* ext)
10  : mNFile(0), mDir(dir), mExt(ext) {}
11 
12 IO::~IO() {}
13 
14 void
15 IO::chain(TChain* chain)
16 {
17  void *pDir = gSystem->OpenDirectory(mDir.Data());
18  if(!pDir){
19  cerr << "##Cannot open directory " << mDir.Data() << endl;
20  cerr << "##Goodbye" << endl;
21  exit(1);
22  }
23 
24  cout << "\tUsing directory : " << mDir.Data() << endl;
25  cout << "\tMatch extension : " << mExt.Data() << endl;
26  if(mNFile) cout << "\tMaximum # files : " << mNFile << endl;
27 
28  //
29  // now find the files that end in the specified extension
30  //
31  const char* fileName(0);
32  Int_t count(0);
33 
34  while((fileName = gSystem->GetDirEntry(pDir))){
35  if(strcmp(fileName,".")==0 || strcmp(fileName,"..")==0) continue;
36 
37  if(strstr(fileName,mExt.Data())){ // found a match
38  char* fullFile = gSystem->ConcatFileName(mDir.Data(),fileName);
39 
40  // add it to the chain
41  cout << "\tAdding " << fullFile << " to the chain" << endl;
42 
43  chain->Add(fullFile); count++;
44  delete fullFile;
45  if(mNFile && count > mNFile) break;
46  }
47  }
48  cout << "Added " << count << " files to the chain" << endl;
49 
50 }
Definition: IO.h:20