43 cout <<
"pattern:" << pattern << endl;
44 cout <<
"# of files by pattern:" << files.size() << endl;
45 vector<string> goodFiles;
46 for (
size_t i = 0; i < files.size(); i++) {
47 TFile* file = TFile::Open((files[i]).c_str(),
"READ");
48 if (file != NULL) cout << i <<
" open file" << endl;
50 Bool_t isGoodFile =
CheckFile(file, fileSizeLimit, nofEvents);
51 if (file != NULL) file->Close();
52 if (isGoodFile) goodFiles.push_back(files[i]);
54 cout <<
"GetGoodFiles all:" << files.size() <<
" good:" << goodFiles.size() << endl;
69 if (file == NULL)
return false;
70 if (file->GetEND() < fileSizeLimit)
return false;
71 TTree* tree = file->Get<TTree>(
"cbmsim");
72 if (tree == NULL)
return false;
73 Long64_t treeSizeAna = tree->GetEntriesFast();
74 if (treeSizeAna == nofEvents)
return true;
80 Int_t fileSizeLimit, Int_t nofEvents)
82 Int_t maxNofFiles = 100;
83 string fileNameAna = dir + string(
"analysis") + fileTemplate;
84 string fileNameReco = dir + string(
"reco") + fileTemplate;
85 string fileNameQa = dir + string(
"litqa") + fileTemplate;
87 cout <<
"-I- " << dir << endl;
89 TList* fileList =
new TList();
90 TList* tempTargetFiles =
new TList();
91 Int_t targetFileNum = 0;
92 for (
int i = 1; i < nofFiles; i++) {
98 TFile* fileAna = TFile::Open((fileNameAna + ss.str()).c_str(),
"READ");
99 TFile* fileReco = TFile::Open((fileNameReco + ss.str()).c_str(),
"READ");
101 Bool_t isGoodFile =
CheckFile(fileAna, fileSizeLimit, nofEvents) &&
CheckFile(fileReco, fileSizeLimit, nofEvents);
102 if (fileReco != NULL) fileReco->Close();
104 if (addString ==
"analysis") {
105 fileList->Add(fileAna);
108 if (addString ==
"litqa") {
109 TFile* fileQa = TFile::Open((fileNameQa + ss.str()).c_str(),
"READ");
112 fileList->Add(fileQa);
116 if (fileQa != NULL) fileQa->Close();
118 if (fileAna != NULL) fileAna->Close();
122 if (fileAna != NULL) fileAna->Close();
123 if (fileReco != NULL) fileReco->Close();
126 if (fileList->GetEntries() >= maxNofFiles || i == nofFiles - 1) {
128 tempTargetFiles->Add(tf);
130 fileList->RemoveAll();
134 cout << endl <<
"-I- number of files to merge = " << count << endl << endl;
136 string outputFile = fileNameAna +
"all.root";
137 if (addString ==
"litqa") outputFile = fileNameQa +
"all.root";
138 cout <<
"-I- OUTPUT: " << outputFile << endl;
139 TFile* targetFile = TFile::Open(outputFile.c_str(),
"RECREATE");
144 if (targetFile != NULL)
delete targetFile;
145 if (tempTargetFiles != NULL)
delete tempTargetFiles;
146 if (fileList != NULL)
delete fileList;
177 TString path((
char*) strstr(target->GetPath(),
":"));
180 TFile* first_source = (TFile*) sourcelist->First();
181 first_source->cd(path);
182 TDirectory* current_sourcedir = gDirectory;
184 Bool_t status = TH1::AddDirectoryStatus();
185 TH1::AddDirectory(kFALSE);
189 TIter nextkey(current_sourcedir->GetListOfKeys());
190 TKey *key, *oldkey = 0;
191 while ((key = (TKey*) nextkey())) {
193 if (oldkey && !strcmp(oldkey->GetName(), key->GetName()))
continue;
196 first_source->cd(path);
197 TObject* obj = key->ReadObj();
199 if (obj->IsA()->InheritsFrom(TH1::Class())) {
203 TH1* h1 = (TH1*) obj;
207 TFile* nextsource = (TFile*) sourcelist->After(first_source);
210 nextsource->cd(path);
211 TKey* key2 = (TKey*) gDirectory->GetListOfKeys()->FindObject(h1->GetName());
213 TH1* h2 = (TH1*) key2->ReadObj();
218 nextsource = (TFile*) sourcelist->After(nextsource);
269 obj->Write(key->GetName());
275 target->SaveSelf(kTRUE);
276 TH1::AddDirectory(status);
static void AddFilesInDir(const std::string &dir, const std::string &fileTemplate, const std::string &addString, Int_t nofFiles, Int_t fileSizeLimit=50000, Int_t nofEvents=1000)