ATLAS Offline Software
LArQuickHistMerge.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
8 
9 
10 //Standalone compilation:
11 //g++ -g -o mergetest.exe `root-config --libs --cflags` -L InstallArea/i686-slc5-gcc43-opt/lib/ -l DataQualityUtils LArHistMerge.version2.cxx
12 
13 // This file uses thread-unsafe classes from DataQualityUtils.
15 
16 #include "TSystem.h"
17 #include "TH1.h"
18 #include "TH2.h"
19 #include "TFile.h"
20 #include "TKey.h"
21 #include "TTree.h"
22 
23 #include <iostream>
24 #include <string>
25 #include <vector>
26 #include <fstream>
27 
29 
30 #define MAXSKIPPEDFILES 5
31 #define MAXSKIPPEDFILESFRACTION 0.1
32 
33 TFile* openWithRetry(const char* path, const unsigned nTrys=3) {
34  TFile* f=nullptr;
35  unsigned iTry=0;
36  unsigned sleepSeconds=30;
37  while (!f && iTry<nTrys) {
38  f=TFile::Open(path,"READ");
39  if (!f || !(f->IsOpen())) {
40  ++iTry;
41  std::cout << "WARNING: Failed to open file " << path << " on " << iTry << ". attempt." << std::endl;
42  if (iTry<nTrys) {
43  std::cout << "Will re-try after " << sleepSeconds << " seconds..." << std::endl;
44  sleep(sleepSeconds);
45  f=nullptr;
46  sleepSeconds*=2;
47  }
48  else {//no more attempts
49  std::cout << "No more retrys" << std::endl;
50  }
51  }//end if file not open
52  }// end while
53  return f;
54 }
55 
57 
58 public:
59 
60  explicit histCollection(bool debug=false) : m_dbg(debug) {};
61  void addDirectory(TDirectory* dir, const std::string& dirName);
62  size_t size() {return m_data.size();};
63  void addFile(TFile* in);
64  void print();
65  void write(TFile* out);
66 
67  void addExclusion(const std::string& dir);
68 
69 private:
70  class histPerDir_t {
71  public:
72  histPerDir_t(const std::string& nameIn, TObject* objIn, TTree* md, bool dbg=false);
73  std::string name;
74  TObject* obj;
75  void (*mergeMethod)(TObject* a, const TObject* b);
76  };
77 
78  struct histDir_t {
79  explicit histDir_t(TTree* mdIn): md(mdIn) {};
80  std::vector<histPerDir_t> histos;
81  TTree* md;
82  };
83 
84 
85 private:
86  bool isExcluded(const std::string& dir);
87  std::map<std::string,histDir_t> m_data;
88  bool m_dbg;
89  std::vector<std::string> m_exclusion;
90 
91 };
92 
93 
94 void histCollection::addExclusion(const std::string& dir) {
95  m_exclusion.push_back(dir);
96  return;
97 }
98 
99 bool histCollection::isExcluded(const std::string& dir) {
100 
101  const size_t firstSlash=dir.find('/',1);
102  if (firstSlash==std::string::npos) return false;
103 
104  std::vector<std::string>::const_iterator it=m_exclusion.begin();
105  std::vector<std::string>::const_iterator it_e=m_exclusion.end();
106  for(;it!=it_e;++it) {
107  const std::string& excl=*it;
108  const size_t s=excl.size();
109  //std::cout << "Comparing " << dir << " (index "<< firstSlash <<") with " << excl << std::endl;
110  if (dir.compare(firstSlash,s,excl)==0) {
111  return true;
112  }
113  }
114  return false;
115 }
116 
118  std::map<std::string,histDir_t>::const_iterator it=m_data.begin();
119  std::map<std::string,histDir_t>::const_iterator it_e=m_data.end();
120  for(;it!=it_e;++it) {
121  std::cout << "Dir: " << it->first << std::endl;
122  const histDir_t& hd=it->second;
123  std::vector<histPerDir_t>::const_iterator it1=hd.histos.begin();
124  std::vector<histPerDir_t>::const_iterator it1_e=hd.histos.end();
125  for (;it1!=it1_e;++it1)
126  std::cout << "\t" << it1->name << std::endl;
127  }
128 
129  std::cout << "\nExclusion List: " << std::endl;
130  std::vector<std::string>::const_iterator sit=m_exclusion.begin();
131  std::vector<std::string>::const_iterator sit_e=m_exclusion.end();
132  for(;sit!=sit_e;++sit)
133  std::cout << "\t" << *sit << std::endl;
134 
135  return;
136 }
137 
138 template<class HIST>
139 void defaultMerge(TObject* a, const TObject* b) {
140  ((HIST*)a)->Add((HIST*)b);
141  return;
142 }
143 
144 void weightedAverageTH1 ATLAS_NOT_THREAD_SAFE (TObject* a, const TObject* b) {
145  TH1* a1=(dynamic_cast<TH1*>(a));
146  const TH1* b1=dynamic_cast<const TH1*>(b);
147  if (!b1 || !a1)
148  std::cout << "ERROR in weightedAverageTH1: Object not of type TH1" << std::endl;
149  else
151  return;
152 }
153 
154 void weightedAverageTH2 ATLAS_NOT_THREAD_SAFE (TObject* a, const TObject* b) {
155  TH2* a1=(dynamic_cast<TH2*>(a));
156  const TH2* b1=(dynamic_cast<const TH2*>(b));
157  if (!b1 || !a1)
158  std::cout << "ERROR in weightedAverageTH2: Object not of type TH2" << std::endl;
159  else
161  return;
162 }
163 
164 void weightedEff ATLAS_NOT_THREAD_SAFE (TObject* a, const TObject* b) {
165  TH1* a1=(dynamic_cast<TH1*>(a));
166  const TH1* b1=(dynamic_cast<const TH1*>(b));
167  if (!b1 || !a1)
168  std::cout << "ERROR in weightedEff: Object not of type TH1" << std::endl;
169  else
171  return;
172 }
173 
174 void mergeRMS ATLAS_NOT_THREAD_SAFE (TObject* a, const TObject* b) {
175  TH1* a1=(dynamic_cast<TH1*>(a));
176  const TH1* b1=dynamic_cast<const TH1*>(b);
177  if (!b1 || !a1)
178  std::cout << "ERROR in mergeRMS: Object not of type TH1" << std::endl;
179  else
181  return;
182 }
183 
184 void RMSpercentDeviation ATLAS_NOT_THREAD_SAFE (TObject* a, const TObject* b) {
185  TH1* a1=(dynamic_cast<TH1*>(a));
186  const TH1* b1=dynamic_cast<const TH1*>(b);
187  if (!b1 || !a1)
188  std::cout << "ERROR in RMSpercentDeviation: Object not of type TH1" << std::endl;
189  else
191  return;
192 }
193 
194 void perBinEffPerCent ATLAS_NOT_THREAD_SAFE (TObject* a, const TObject* b) {
195  TH1* a1=(dynamic_cast<TH1*>(a));
196  const TH1* b1=dynamic_cast<const TH1*>(b);
197  if (!b1 || !a1)
198  std::cout << "ERROR in getBinEffPerCent: Object not of type TH1" << std::endl;
199  else
201  return;
202 }
203 
204 void lowerLB ATLAS_NOT_THREAD_SAFE (TObject* a, const TObject* b) {
205  TH1* a1=(dynamic_cast<TH1*>(a));
206  const TH1* b1=dynamic_cast<const TH1*>(b);
207  if (!b1 || !a1)
208  std::cout << "ERROR in lowerLB: Object not of type TH1" << std::endl;
209  else
211  return;
212 }
213 
214 void identical(TObject* a, const TObject* b) {
215  TH1* a1=(dynamic_cast<TH1*>(a));
216  const TH1* b1=dynamic_cast<const TH1*>(b);
217  TH2* c1=(dynamic_cast<TH2*>(a));
218  const TH2* d1=dynamic_cast<const TH2*>(b);
219  if (a1 and b1){
221  } else if (c1 and d1){
223  } else {
224  std::cout << "ERROR in identical: Object not of type THist" << std::endl;
225  std::cout << a1 << " " << b1 << " " << c1 << " " <<d1 <<std::endl;
226  }
227  return;
228 }
229 
230 
231 histCollection::histPerDir_t::histPerDir_t(const std::string& nameIn, TObject* objIn, TTree* md, bool dbg) :
232  name (nameIn),
233  obj(objIn),
234  mergeMethod(nullptr)
235 {
236 
237  //Some sanity checks:
238  if (!objIn) {
239  std::cout << "ERROR while adding " << nameIn << ": Histogram pointer is NULL" << std::endl;
240  return;
241  }
242 
243  char howToMerge[256]={};
244  char mdName[256]={};
245  strcpy(howToMerge,"<default>");
246  if (!md) {
247  std::cout << "ERROR while adding " << nameIn << ": No metadata tree. Use default merging method" << std::endl;
248  }
249  else {
250  md->SetBranchAddress("MergeMethod", howToMerge);
251  md->SetBranchAddress("Name", mdName);
252  unsigned nEntries = md->GetEntries();
253  for (unsigned i=0;i<nEntries;++i) {
254  md->GetEntry(i);
255  if (name.compare(mdName)==0) break;
256  }
257  }
258 
259  if (dbg) std::cout << "Name:" << mdName << " mergeMethod=" << howToMerge << std::endl;
260  if (nullptr!=dynamic_cast<TH1*>(obj)) {
261  if (!strcmp(howToMerge,"<default>"))
262  mergeMethod=&defaultMerge<TH1>;
263  else if (!strcmp(howToMerge,"weightedAverage"))
264  mergeMethod=&weightedAverageTH1;
265  else if (!strcmp(howToMerge,"weightedEff"))
266  mergeMethod=&weightedEff;
267  else if (!strcmp(howToMerge,"mergeRMS"))
268  mergeMethod=&mergeRMS;
269  else if (!strcmp(howToMerge,"RMSpercentDeviation"))
270  mergeMethod=&RMSpercentDeviation;
271  else if (!strcmp(howToMerge,"perBinEffPerCent"))
272  mergeMethod=&perBinEffPerCent;
273  else if (!strcmp(howToMerge,"lowerLB"))
275  else if (!strcmp(howToMerge,"identical"))
277 
278  else {
279  std::cout << "ERROR: Unknown merging method (" << howToMerge << ") for object of type TH1 named " << nameIn << std::endl;
280  obj=nullptr;
281  }
282  }// end if TH1
283  else if (nullptr!=dynamic_cast<TH2*>(obj)) {
284  if (!strcmp(howToMerge,"<default>"))
285  mergeMethod=&defaultMerge<TH2>;
286  else if (!strcmp(howToMerge,"weightedAverage"))
287  mergeMethod=&weightedAverageTH2;
288  else {
289  std::cout << "ERROR: Unknown merging method (" << howToMerge << ") for object of type TH2 named " << nameIn << std::endl;
290  obj=nullptr;
291  }
292 
293  }// end if TH2
294  else {
295  std::cout << "Object "<< name << " has unkown type" << std::endl;
296  obj=nullptr;
297  }
298 }
299 
300 
301 void histCollection::addDirectory(TDirectory* dir, const std::string& dirName) {
302 
303  TIter next( dir->GetListOfKeys() );
304  TKey* key;
305  while((key=(TKey*)next())) {
306  const char* name=key->GetName();
307  const char* classname=key->GetClassName();
308  if (m_dbg) std::cout << "Found name " << name << ", classname=" << classname << std::endl;
309 
310  const std::string newName=dirName+"/"+name;
311 
312  if (this->isExcluded(newName)) {
313  std::cout << "Path " << newName << " excluded" << std::endl;
314  return;
315  }
316 
317 
318  if (!strncmp(classname,"TH1",3) || !strncmp(classname,"TH2",3) || !strncmp(classname,"TProfile",8)) {
320  if (mIt==m_data.end()) { // New top-level directory
321  TTree* md=(TTree*)dir->Get("metadata");
322  if (!md) std::cout << "ERROR: Did not find metadata tree in directroy " << dirName << std::endl;
323  mIt=m_data.insert(std::make_pair(dirName,histDir_t(md))).first;
324  }
325  histPerDir_t histo(name,key->ReadObj(),mIt->second.md,m_dbg);
326  mIt->second.histos.push_back(histo);
327  }
328  else if (!strncmp(classname,"TDirectory",10)) {
329  TObject* obj = key->ReadObj();
330  TDirectory* subdir = dynamic_cast<TDirectory*>( obj );
331  if (subdir) {
332  this->addDirectory(subdir,newName);
333  }
334  }
335  else if (!strcmp(classname,"TTree") && (!strcmp(name,"metadata"))) {
336  //std::cout << "Found Metadata tree" << std::endl;
337  }
338  else {
339  std::cout << "Ignored objects '" << name << "' of type "<< classname << std::endl;
340  }
341  }
342  return;
343 }
344 
345 
346 void histCollection::addFile(TFile* in) {
347  std::map<std::string,histDir_t>::const_iterator it=m_data.begin();
348  std::map<std::string,histDir_t>::const_iterator it_e=m_data.end();
349  for(;it!=it_e;++it) {
350  const std::string& dirName=it->first;
351  const histDir_t& hd=it->second;
352  std::vector<histPerDir_t>::const_iterator it1=hd.histos.begin();
353  std::vector<histPerDir_t>::const_iterator it1_e=hd.histos.end();
354  for (;it1!=it1_e;++it1) {
355  const std::string fullName=dirName+"/"+it1->name;
356  if (!it1->obj) {
357  //std::cout << "Object " << fullName << " not properly set up. Not merged." << std::endl;
358  continue;
359  }
360  TObject* obj=in->Get(fullName.c_str());
361  if (!obj) {
362  std::cout << "ERROR: Could not access path " << fullName <<" in file " << in->GetName() << std::endl;
363  }
364  else
365  (*it1->mergeMethod)(it1->obj,obj);
366  }//End loop over histograms in directory
367  }//End loop over directory names
368  return;
369 }
370 
371 
372 
374  unsigned nWritten=0;
375  unsigned nIgnored=0;
376  TDirectory* histDir=nullptr;
377  std::string lastDir;
378  std::map<std::string,histDir_t>::const_iterator it=m_data.begin();
379  std::map<std::string,histDir_t>::const_iterator it_e=m_data.end();
380  for(;it!=it_e;++it) {
381  const std::string fulldir=it->first + "/";
382  //Create dirs if necessary
383  std::string::size_type j=0,j1=0;
384  while (j1!=std::string::npos) {
385  do {
386  j=j1+1;
387  j1=fulldir.find('/',j);
388  //std::cout << "Inner loop " << fulldir.substr(0,j1) << " << ==? " << lastDir.substr(0,j1) << std::endl;
389  }
390  while(j1!=std::string::npos && !fulldir.compare(0,j1,lastDir,0,j1));
391  const std::string currDirAtLevel(fulldir.substr(j,j1-j));
392  const std::string currFullDir(fulldir.substr(0,j1));
393  const std::string currBaseDir(fulldir.substr(0,j));
394  //std::cout << "Working on dir " << fulldir << " [" << currFullDir << " " << currBaseDir << " " << currDirAtLevel << std::endl;
395  lastDir=currFullDir;
396  out->cd(currBaseDir.c_str());
397  gDirectory->mkdir(currDirAtLevel.c_str());
398  }//End outer while loop - full directory created
399  //std::cout << "Done creating " << fulldir << std::endl;
400  out->cd(fulldir.c_str());
401  it->second.md->SetDirectory(histDir);
402  it->second.md->Write(nullptr,TObject::kOverwrite);
403  std::vector<histPerDir_t>::const_iterator ith=it->second.histos.begin();
404  std::vector<histPerDir_t>::const_iterator ith_e=it->second.histos.end();
405  for (;ith!=ith_e;++ith) {
406  if (ith->obj) {
407  ith->obj->Write();
408  std::cout << "Writing " << ith->name << " to dir " << fulldir << std::endl;
409  ++nWritten;
410  }
411  else {
412  std::cout << "NOT writing " << ith->name << ". Invalid." << std::endl;
413  ++nIgnored;
414  }
415  }//End loop over histograms in one directory
416  }//End loop over directories;
417  std::cout << "Wrote " << nWritten << " histograms to output file.";
418  if (nIgnored)
419  std::cout << " Omitting " << nIgnored << " histograms." << std::endl;
420  else
421  std::cout << std::endl;
422 
423  return;
424 }
425 
426 std::vector<std::string> splitString(const std::string& in, const std::string& delim) {
427  std::vector<std::string> retvec;
428  size_t pos1=0,pos2=0;
429  while (pos2!=std::string::npos) {
430  pos2=in.find_first_of(delim,pos1);
431  const std::string sub=in.substr(pos1,pos2-pos1);
432  if (!sub.empty())
433  retvec.push_back(sub);
434  pos1=pos2+1;
435  }
436  return retvec;
437 }
438 
439 
440 
441 bool readFromTextFile(const char* filename, std::vector<std::string>& out) {
442 
443  std::ifstream ifs (filename, std::ifstream::in );
444  if (!ifs.good()) {
445  std::cout << "Failed to open file " << filename << " for reading." << std::endl;
446  return false;
447  }
448 
449  while (ifs.good()) {
450  std::string line;
451  getline(ifs,line);
452  //Bit of cleaning and splitting:
453  const std::vector<std::string> linetok=splitString(line," ,;\t\n");
454  std::vector<std::string>::const_iterator it=linetok.begin();
455  std::vector<std::string>::const_iterator it_e=linetok.end();
456  for(;it!=it_e;++it) {
457  if ((*it)[0]=='#') break; //ingore all characters behind '#'
458  out.push_back(*it);
459  }
460  //if (!line.size()) continue;
461  //out.push_back(line);
462  }
463  ifs.close();
464  return true;
465 }
466 
467 
468 
469 // =================================================================================================
470 
471 
472 int main(int argc, char** argv) {
473 
474  if (argc<2 || (argc>1 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"--help")))) {
475  std::cout << "Syntax:\n" << argv[0] << " [-v ] [-i inputTextFile] [-d directroy] <outfile> <infile1> <infile2> .... " << std::endl;
476  std::cout << " -v verbose " << std::endl;
477  return -1;
478  }
479 
480  bool debug=false;
481  std::string outFileName;
482  std::vector<std::string> inFileNames;
483  std::vector<std::string> baseDirs;
484 
485  for(int iArg=1;iArg<argc;++iArg) {
486  if (!strcmp(argv[iArg],"-v")) {
487  debug=true;
488  continue;
489  }
490 
491  if (!strcmp(argv[iArg],"-d")) {
492  ++iArg;
493  if (argc<=iArg) {
494  std::cout << "ERROR: Expected a parameter (directory name) after '-d'" << std::endl;
495  return -1;
496  }
497  baseDirs.push_back(std::string(argv[iArg]));
498  continue;
499  }
500 
501 
502  if (!strcmp(argv[iArg],"-i")) {
503  ++iArg;
504  if (argc<=iArg) {
505  std::cout << "ERROR: Expected text file name after '-i'" << std::endl;
506  return -1;
507  }
509  continue;
510  }
511  if (outFileName.empty())
512  outFileName=argv[iArg];
513  else
514  inFileNames.push_back(std::string(argv[iArg]));
515  }//end loop over arguments
516 
517 
518  if (outFileName.empty()) {
519  std::cout << "ERROR: No output file name given!" << std::endl;
520  return -1;
521  }
522 
523  if (!gSystem->AccessPathName(outFileName.c_str())) {
524  std::cout << "ERROR: Output file " << outFileName << " exists already!" << std::endl;
525  return -1;
526  }
527 
528  if (inFileNames.empty()) {
529  std::cout << "WARNING: No input files given! Will produce empty output file" << std::endl;
530  }
531 
532 
533  std::cout << "Number of input files: " << inFileNames.size() << std::endl;
534  std::cout << "Output file: " << outFileName << std::endl;
535 
536  if (baseDirs.empty()) {
537  baseDirs.push_back("LAr");
538  baseDirs.push_back("CaloMonitoring/LArCellMon_NoTrigSel");
539  baseDirs.push_back("CaloTopoClusters/CalBAR");
540  baseDirs.push_back("CaloTopoClusters/CalECA");
541  baseDirs.push_back("CaloTopoClusters/CalECC");
542  baseDirs.push_back("CaloTopoClusters/CalEMBAR");
543  baseDirs.push_back("CaloTopoClusters/CalEMECA");
544  baseDirs.push_back("CaloTopoClusters/CalEMECC");
545 
546  }
547  else {
548  //clean superfluos slash characters
549  for (size_t i=0;i<baseDirs.size();++i) {
550  std::vector<std::string> dirtok=splitString(baseDirs[i],std::string("/"));
551  if (dirtok.empty()) {
552  baseDirs[i].clear();
553  continue;
554  }
555  baseDirs[i]=dirtok[0];
556  for (size_t j=1;j<dirtok.size();++j) {
557  baseDirs[i]+="/"+dirtok[j];
558  }//eld loop over dir tokens
559  }//end loop over directories
560  }
561 
562 
563  histCollection listOfHists(debug);
564  listOfHists.addExclusion("/CaloMonitoring/LArCellMon_NoTrigSel/Sporadic");
565 
566  TFile* in1=nullptr;
567  std::string runDir("/");
568  size_t fileIndex=0;
569  unsigned nSkippedFiles=0;
570 
571  const size_t nFiles=inFileNames.size();
572 
573  //Loop to find the first non-empty file
574  for (;fileIndex<nFiles && runDir.size()==1;++fileIndex) {
575  //in1=TFile::Open(inFileNames[fileIndex].c_str(),"READ");
576  in1=openWithRetry(inFileNames[fileIndex].c_str());
577  if (!in1) {
578  std::cout << "ERROR: Could not open first file " << inFileNames[fileIndex] << "after all attempts" << std::endl;
579  if (nSkippedFiles>MAXSKIPPEDFILES) {
580  std::cout << "Failed to read " << nSkippedFiles << " input files. Abort job ..." << std::endl;
581  return -1;
582  }
583  if (nSkippedFiles>nFiles*MAXSKIPPEDFILESFRACTION) {
584  std::cout << "Failed to read " << 100.0*nSkippedFiles/nFiles << "% of input files. Abort job ..." << std::endl;
585  return -1;
586  }
587  ++nSkippedFiles;
588  std::cout << "Continue without this file. Skipped " << nSkippedFiles << " input files so far." << std::endl;
589  continue;
590  }
591 
592  std::cout << "Working on file " << inFileNames[fileIndex] << std::endl;
593  //Get run_XXXX directory name
594  TIter next(in1->GetListOfKeys() );
595  TKey* key;
596  while((key=(TKey*)next())) {
597  const char* name=key->GetName();
598  if (!strncmp(name,"run_",4)) {
599  if (runDir.size()>1) {
600  std::cout << "ERROR More than one run_XXX directory found! Ignoring " << name << std::endl;
601  }
602  else
603  runDir.append(name);
604  }
605  }
606 
607  if (runDir.size()==1) {
608  std::cout << "WARNING: No run_XXXX directory found. Empty File? Ignored." << std::endl;
609  in1->Close();
610  continue;
611  }
612 
613  //Collect histogram directories
614  std::vector<std::string>::const_iterator dIt=baseDirs.begin();
615  std::vector<std::string>::const_iterator dIt_e=baseDirs.end();
616  for (;dIt!=dIt_e;++dIt) {
617  std::string dirName=runDir+"/"+(*dIt);
618  TDirectory* dir=dynamic_cast<TDirectory*>(in1->Get(dirName.c_str()));
619  if (!dir) {
620  std::cout << "Did not find directory " << dirName <<"!" << std::endl;
621  continue;
622  }
623  listOfHists.addDirectory(dir,dirName);
624  }
625 
626  std::cout << "Number of directories: " << listOfHists.size() << std::endl;
627 
628  if (debug) listOfHists.print();
629 
630  //std::cout << "Closing first file" << std::endl;
631  //in1->Close("R");
632  //delete in1;
633  }//end loop to find first non-empty file
634 
635  for (;fileIndex<nFiles;++fileIndex) { // Loop over remaining files
636  const char* filename=inFileNames[fileIndex].c_str();
637  //TFile* in=TFile::Open(filename,"READ");
638  TFile* in=openWithRetry(filename);
639  if (!in) {
640  std::cout << "ERROR: Could not open file " << filename << "after all attempts" << std::endl;
641  if (nSkippedFiles>MAXSKIPPEDFILES) {
642  std::cout << "Failed to read " << nSkippedFiles << " input files. Abort job ..." << std::endl;
643  return -1;
644  }
645  if (nSkippedFiles>nFiles*MAXSKIPPEDFILESFRACTION) {
646  std::cout << "Failed to read " << 100.0*nSkippedFiles/nFiles << "% of input files. Abort job ..." << std::endl;
647  return -1;
648  }
649  ++nSkippedFiles;
650  std::cout << "Continue without this file. Skipped " << nSkippedFiles << " input files so far." << std::endl;
651  continue;
652  }
653  std::cout << "Working on file " << filename << std::endl;
654  TObject* dirObj=in->Get(runDir.c_str()+1);
655  if (!dirObj) {
656  std::cout << "Directory " << runDir << " not found. Ignoring apprently empty file" << std::endl;
657  }
658  else
659  listOfHists.addFile(in);
660  in->Close();
661  delete in;
662  }
663 
664  TFile* out=new TFile(outFileName.c_str(),"NEW");
665  if (!out || !out->IsOpen()) {
666  std::cout << "ERROR: Failed to open output file " << outFileName << " for writing" << std::endl;
667  return -1;
668  }
669  listOfHists.write(out);
670  out->Close();
671  delete out;
672 
673  if (in1 && in1->IsOpen()) {
674  in1->Close();
675  delete in1;
676  }
677 
678  if (nSkippedFiles>0) {
679  std::cout << "WARNING: Skipped " << nSkippedFiles << " input file(s)." << std::endl;
680  }
681 
682  return 0;
683 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
histCollection
Definition: LArQuickHistMerge.cxx:56
histCollection::addExclusion
void addExclusion(const std::string &dir)
Definition: LArQuickHistMerge.cxx:94
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
fitman.nWritten
int nWritten
Definition: fitman.py:420
ATLAS_NOT_THREAD_SAFE
void weightedAverageTH1 ATLAS_NOT_THREAD_SAFE(TObject *a, const TObject *b)
Definition: LArQuickHistMerge.cxx:144
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
splitString
std::vector< std::string > splitString(const std::string &in, const std::string &delim)
Definition: LArQuickHistMerge.cxx:426
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
openWithRetry
TFile * openWithRetry(const char *path, const unsigned nTrys=3)
Definition: LArQuickHistMerge.cxx:33
histCollection::print
void print()
Definition: LArQuickHistMerge.cxx:117
MAXSKIPPEDFILESFRACTION
#define MAXSKIPPEDFILESFRACTION
Definition: LArQuickHistMerge.cxx:31
WriteCellNoiseToCool.fullName
fullName
Definition: WriteCellNoiseToCool.py:461
histCollection::histDir_t::histos
std::vector< histPerDir_t > histos
Definition: LArQuickHistMerge.cxx:79
extractSporadic.c1
c1
Definition: extractSporadic.py:134
histCollection::write
void write(TFile *out)
Definition: LArQuickHistMerge.cxx:373
skel.it
it
Definition: skel.GENtoEVGEN.py:423
dqutils::MonitoringFile::merge_lowerLB
static void merge_lowerLB(TH1 &a, const TH1 &b)
Definition: MonitoringFile_MergeAlgs.cxx:647
MAXSKIPPEDFILES
#define MAXSKIPPEDFILES
Definition: LArQuickHistMerge.cxx:30
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
defaultMerge
void defaultMerge(TObject *a, const TObject *b)
Definition: LArQuickHistMerge.cxx:139
histCollection::size
size_t size()
Definition: LArQuickHistMerge.cxx:62
histCollection::histCollection
histCollection(bool debug=false)
Definition: LArQuickHistMerge.cxx:60
SH::Meta::dbg
std::string dbg(const Meta &obj, unsigned verbosity=0)
the debugging info of this object
Definition: Meta.cxx:28
histCollection::m_exclusion
std::vector< std::string > m_exclusion
Definition: LArQuickHistMerge.cxx:89
dbg
bool dbg
Definition: listroot.cxx:36
histCollection::histDir_t::histDir_t
histDir_t(TTree *mdIn)
Definition: LArQuickHistMerge.cxx:79
CombineRootFiles.inFileNames
inFileNames
Definition: CombineRootFiles.py:22
DumpGeoConfig.outFileName
string outFileName
Definition: DumpGeoConfig.py:238
main
int main(int argc, char **argv)
Definition: LArQuickHistMerge.cxx:472
doubleTestComp.j1
j1
Definition: doubleTestComp.py:21
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:92
DetDescrDictionaryDict::it1
std::vector< HWIdentifier >::iterator it1
Definition: DetDescrDictionaryDict.h:17
histCollection::m_dbg
bool m_dbg
Definition: LArQuickHistMerge.cxx:88
histCollection::histPerDir_t::obj
TObject * obj
Definition: LArQuickHistMerge.cxx:74
histCollection::histDir_t
Definition: LArQuickHistMerge.cxx:78
histCollection::m_data
std::map< std::string, histDir_t > m_data
Definition: LArQuickHistMerge.cxx:87
hotSpotInTAG.lowerLB
int lowerLB
Definition: hotSpotInTAG.py:175
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
TH2
Definition: rootspy.cxx:373
histCollection::isExcluded
bool isExcluded(const std::string &dir)
Definition: LArQuickHistMerge.cxx:99
beamspotman.dir
string dir
Definition: beamspotman.py:623
dqutils::MonitoringFile::merge_RMS
static void merge_RMS(TH1 &a, const TH1 &b)
Definition: MonitoringFile_MergeAlgs.cxx:534
dqutils::MonitoringFile::merge_weightedAverage
static void merge_weightedAverage(TH1 &a, const TH1 &b)
Definition: MonitoringFile_MergeAlgs.cxx:290
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
MakeNewFileFromOldAndSubstitution.newName
dictionary newName
Definition: ICHEP2016/MakeNewFileFromOldAndSubstitution.py:95
histCollection::addFile
void addFile(TFile *in)
Definition: LArQuickHistMerge.cxx:346
identical
void identical(TObject *a, const TObject *b)
Definition: LArQuickHistMerge.cxx:214
MonitoringFile.h
dqutils::MonitoringFile::merge_weightedAverage2D
static void merge_weightedAverage2D(TH2 &a, const TH2 &b)
Definition: MonitoringFile_MergeAlgs.cxx:363
a
TList * a
Definition: liststreamerinfos.cxx:10
dqutils::MonitoringFile::merge_identical
static void merge_identical(TH1 &a, const TH1 &b)
Definition: MonitoringFile_MergeAlgs.cxx:694
TH1
Definition: rootspy.cxx:268
DeMoScan.first
bool first
Definition: DeMoScan.py:534
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
histCollection::histDir_t::md
TTree * md
Definition: LArQuickHistMerge.cxx:81
dqutils::MonitoringFile::merge_perBinEffPerCent
static void merge_perBinEffPerCent(TH1 &a, const TH1 &b)
Definition: MonitoringFile_MergeAlgs.cxx:126
readFromTextFile
bool readFromTextFile(const char *filename, std::vector< std::string > &out)
Definition: LArQuickHistMerge.cxx:441
python.envutil.fulldir
fulldir
Definition: envutil.py:172
python.LumiCalcRecover.subdir
subdir
Definition: LumiCalcRecover.py:25
histCollection::histPerDir_t::name
std::string name
Definition: LArQuickHistMerge.cxx:73
plotBeamSpotCompare.histo
histo
Definition: plotBeamSpotCompare.py:415
checker_macros.h
Define macros for attributes used to control the static checker.
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
python.PyAthena.obj
obj
Definition: PyAthena.py:135
dqutils::MonitoringFile::merge_weightedEff
static void merge_weightedEff(TH1 &a, const TH1 &b)
Definition: MonitoringFile_MergeAlgs.cxx:401
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
Definition: LArQuickHistMerge.cxx:7
histCollection::histPerDir_t
Definition: LArQuickHistMerge.cxx:70
dqutils::MonitoringFile::merge_RMSpercentDeviation
static void merge_RMSpercentDeviation(TH1 &a, const TH1 &b)
Definition: MonitoringFile_MergeAlgs.cxx:589
histCollection::addDirectory
void addDirectory(TDirectory *dir, const std::string &dirName)
Definition: LArQuickHistMerge.cxx:301
histCollection::histPerDir_t::histPerDir_t
histPerDir_t(const std::string &nameIn, TObject *objIn, TTree *md, bool dbg=false)
Definition: LArQuickHistMerge.cxx:231
histCollection::histPerDir_t::mergeMethod
void(* mergeMethod)(TObject *a, const TObject *b)
Definition: LArQuickHistMerge.cxx:75
CscCalibQuery.nFiles
int nFiles
Definition: CscCalibQuery.py:332
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37