00001
00002 #include "IO.h"
00003 #include "TChain.h"
00004 #include "TSystem.h"
00005 #include <iostream>
00006
00007 ClassImp(IO)
00008
00009 IO::IO(const char* dir, const char* ext)
00010 : mNFile(0), mDir(dir), mExt(ext) {}
00011
00012 IO::~IO() {}
00013
00014 void
00015 IO::chain(TChain* chain)
00016 {
00017 void *pDir = gSystem->OpenDirectory(mDir.Data());
00018 if(!pDir){
00019 cerr << "##Cannot open directory " << mDir.Data() << endl;
00020 cerr << "##Goodbye" << endl;
00021 exit(1);
00022 }
00023
00024 cout << "\tUsing directory : " << mDir.Data() << endl;
00025 cout << "\tMatch extension : " << mExt.Data() << endl;
00026 if(mNFile) cout << "\tMaximum # files : " << mNFile << endl;
00027
00028
00029
00030
00031 const char* fileName(0);
00032 Int_t count(0);
00033
00034 while((fileName = gSystem->GetDirEntry(pDir))){
00035 if(strcmp(fileName,".")==0 || strcmp(fileName,"..")==0) continue;
00036
00037 if(strstr(fileName,mExt.Data())){
00038 char* fullFile = gSystem->ConcatFileName(mDir.Data(),fileName);
00039
00040
00041 cout << "\tAdding " << fullFile << " to the chain" << endl;
00042
00043 chain->Add(fullFile); count++;
00044 delete fullFile;
00045 if(mNFile && count > mNFile) break;
00046 }
00047 }
00048 cout << "Added " << count << " files to the chain" << endl;
00049
00050 }