24 glob(pattern.c_str(), GLOB_TILDE, NULL, &glob_result);
26 for (
unsigned int i = 0;
i < glob_result.gl_pathc; ++
i) {
27 files.push_back(
string(glob_result.gl_pathv[
i]));
29 globfree(&glob_result);
37 vector<string> files = GetFilesByPattern(pattern);
38 cout <<
"pattern:" << pattern << endl;
39 cout <<
"# of files by pattern:" << files.size() << endl;
40 vector<string> goodFiles;
41 for (
size_t i = 0;
i < files.size();
i++) {
42 TFile* file = TFile::Open((files[
i]).c_str(),
"READ");
43 if (file != NULL) cout <<
i <<
" open file" << endl;
45 Bool_t isGoodFile = CheckFile(file, fileSizeLimit, nofEvents);
46 if (file != NULL) file->Close();
47 if (isGoodFile) goodFiles.push_back(files[
i]);
49 cout <<
"GetGoodFiles all:" << files.size() <<
" good:" << goodFiles.size()
55 if (file == NULL)
return false;
56 if (file->GetEND() < fileSizeLimit)
return false;
64 if (file == NULL)
return false;
65 if (file->GetEND() < fileSizeLimit)
return false;
66 TTree* tree = (TTree*) file->Get(
"cbmsim");
67 if (tree == NULL)
return false;
68 Long64_t treeSizeAna = tree->GetEntriesFast();
69 if (treeSizeAna == nofEvents)
return true;
75 const string& fileTemplate,
76 const string& addString,
80 Int_t maxNofFiles = 100;
81 string fileNameAna = dir + string(
"analysis") + fileTemplate;
82 string fileNameReco = dir + string(
"reco") + fileTemplate;
83 string fileNameQa = dir + string(
"litqa") + fileTemplate;
85 cout <<
"-I- " << dir << endl;
87 TList* fileList =
new TList();
88 TList* tempTargetFiles =
new TList();
89 Int_t targetFileNum = 0;
90 for (
int i = 1;
i < nofFiles;
i++) {
96 TFile* fileAna = TFile::Open((fileNameAna + ss.str()).c_str(),
"READ");
97 TFile* fileReco = TFile::Open((fileNameReco + ss.str()).c_str(),
"READ");
99 Bool_t isGoodFile = CheckFile(fileAna, fileSizeLimit, nofEvents)
100 && CheckFile(fileReco, fileSizeLimit, nofEvents);
101 if (fileReco != NULL) fileReco->Close();
103 if (addString ==
"analysis") {
104 fileList->Add(fileAna);
107 if (addString ==
"litqa") {
108 TFile* fileQa = TFile::Open((fileNameQa + ss.str()).c_str(),
"READ");
109 Bool_t isGoodQaFile = CheckFileSize(fileQa, fileSizeLimit);
111 fileList->Add(fileQa);
114 if (fileQa != NULL) fileQa->Close();
116 if (fileAna != NULL) fileAna->Close();
119 if (fileAna != NULL) fileAna->Close();
120 if (fileReco != NULL) fileReco->Close();
123 if (fileList->GetEntries() >= maxNofFiles ||
i == nofFiles - 1) {
125 CreateAndMergeTempTargetFile(dir, addString, targetFileNum, fileList);
126 tempTargetFiles->Add(tf);
127 CloseFilesFromList(fileList);
128 fileList->RemoveAll();
132 cout << endl <<
"-I- number of files to merge = " << count << endl << endl;
134 string outputFile = fileNameAna +
"all.root";
135 if (addString ==
"litqa") outputFile = fileNameQa +
"all.root";
136 cout <<
"-I- OUTPUT: " << outputFile << endl;
137 TFile* targetFile = TFile::Open(outputFile.c_str(),
"RECREATE");
138 MergeRootfile(targetFile, tempTargetFiles);
139 CloseFilesFromList(tempTargetFiles);
142 if (targetFile != NULL)
delete targetFile;
143 if (tempTargetFiles != NULL)
delete tempTargetFiles;
144 if (fileList != NULL)
delete fileList;
148 const string& addString,
151 cout <<
"-I- CreateAndMergeTempTargetFile no:" << targetFileNum
152 <<
", nofFiles:" << fileList->GetEntries() << endl;
154 ss << targetFileNum <<
".root";
155 TFile* targetFile = TFile::Open(
156 string(dir + addString +
".temp.taget.file." + ss.str()).c_str(),
158 if (fileList->GetEntries() > 0) MergeRootfile(targetFile, fileList);
164 int nFL = fileList->GetEntries();
165 for (
int iFL = 0; iFL < nFL; iFL++) {
166 TFile*
f = (TFile*) fileList->At(iFL);
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);
212 (TKey*) gDirectory->GetListOfKeys()->FindObject(h1->GetName());
214 TH1* h2 = (TH1*) key2->ReadObj();
219 nextsource = (TFile*) sourcelist->After(nextsource);
270 obj->Write(key->GetName());
276 target->SaveSelf(kTRUE);
277 TH1::AddDirectory(status);