#include "TSystem.h"
#include "TH1.h"
#include "TH2.h"
#include "TFile.h"
#include "TKey.h"
#include "TTree.h"
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "CxxUtils/checker_macros.h"
#include "DataQualityUtils/MonitoringFile.h"
Go to the source code of this file.
◆ ATLAS_NOT_THREAD_SAFE()
void identical ATLAS_NOT_THREAD_SAFE |
( |
TObject * |
a, |
|
|
const TObject * |
b |
|
) |
| |
Definition at line 139 of file LArQuickHistMerge.cxx.
140 TH1* a1=(
dynamic_cast<TH1*
>(
a));
141 const TH1* b1=
dynamic_cast<const TH1*
>(
b);
143 std::cout <<
"ERROR in weightedAverageTH1: Object not of type TH1" << std::endl;
◆ defaultMerge()
template<class HIST >
void defaultMerge |
( |
TObject * |
a, |
|
|
const TObject * |
b |
|
) |
| |
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 466 of file LArQuickHistMerge.cxx.
468 if (
argc<2 || (
argc>1 && (!strcmp(
argv[1],
"-h") || !strcmp(
argv[1],
"--help")))) {
469 std::cout <<
"Syntax:\n" <<
argv[0] <<
" [-v ] [-i inputTextFile] [-d directroy] <outfile> <infile1> <infile2> .... " << std::endl;
470 std::cout <<
" -v verbose " << std::endl;
477 std::vector<std::string> baseDirs;
479 for(
int iArg=1;iArg<
argc;++iArg) {
480 if (!strcmp(
argv[iArg],
"-v")) {
485 if (!strcmp(
argv[iArg],
"-d")) {
488 std::cout <<
"ERROR: Expected a parameter (directory name) after '-d'" << std::endl;
491 baseDirs.push_back(std::string(
argv[iArg]));
496 if (!strcmp(
argv[iArg],
"-i")) {
499 std::cout <<
"ERROR: Expected text file name after '-i'" << std::endl;
513 std::cout <<
"ERROR: No output file name given!" << std::endl;
517 if (!gSystem->AccessPathName(
outFileName.c_str())) {
518 std::cout <<
"ERROR: Output file " <<
outFileName <<
" exists already!" << std::endl;
523 std::cout <<
"WARNING: No input files given! Will produce empty output file" << std::endl;
527 std::cout <<
"Number of input files: " <<
inFileNames.size() << std::endl;
528 std::cout <<
"Output file: " <<
outFileName << std::endl;
530 if (baseDirs.empty()) {
531 baseDirs.push_back(
"LAr");
532 baseDirs.push_back(
"CaloMonitoring/LArCellMon_NoTrigSel");
533 baseDirs.push_back(
"CaloTopoClusters/CalBAR");
534 baseDirs.push_back(
"CaloTopoClusters/CalECA");
535 baseDirs.push_back(
"CaloTopoClusters/CalECC");
536 baseDirs.push_back(
"CaloTopoClusters/CalEMBAR");
537 baseDirs.push_back(
"CaloTopoClusters/CalEMECA");
538 baseDirs.push_back(
"CaloTopoClusters/CalEMECC");
543 for (
size_t i=0;
i<baseDirs.size();++
i) {
544 std::vector<std::string> dirtok=
splitString(baseDirs[
i],std::string(
"/"));
545 if (dirtok.empty()) {
549 baseDirs[
i]=dirtok[0];
550 for (
size_t j=1;j<dirtok.size();++j) {
551 baseDirs[
i]+=
"/"+dirtok[j];
557 std::vector<std::string> foundDirs;
560 listOfHists.addExclusion(
"/CaloMonitoring/LArCellMon_NoTrigSel/Sporadic");
563 std::string runDir(
"/");
565 unsigned nSkippedFiles=0;
571 for (;fileIndex<
nFiles && foundDirs.size()!=baseDirs.size() ;++fileIndex) {
575 std::cout <<
"ERROR: Could not open first file " <<
inFileNames[fileIndex] <<
"after all attempts" << std::endl;
577 std::cout <<
"Failed to read " << nSkippedFiles <<
" input files. Abort job ..." << std::endl;
581 std::cout <<
"Failed to read " << 100.0*nSkippedFiles/
nFiles <<
"% of input files. Abort job ..." << std::endl;
585 std::cout <<
"Continue without this file. Skipped " << nSkippedFiles <<
" input files so far." << std::endl;
589 std::cout <<
"First loop: Working on file " <<
inFileNames[fileIndex] <<std::endl;
591 TIter
next(in1->GetListOfKeys() );
594 const char*
name=
key->GetName();
595 if (!strncmp(
name,
"run_",4)) {
596 if (runDir.size()>1) {
597 std::cout <<
"ERROR More than one run_XXX directory found! Ignoring " <<
name << std::endl;
604 if (runDir.size()==1) {
605 std::cout <<
"WARNING: No run_XXXX directory found. Empty File? Ignored." << std::endl;
611 std::vector<std::string>::const_iterator dIt=baseDirs.begin();
612 std::vector<std::string>::const_iterator dIt_e=baseDirs.end();
614 for (;dIt!=dIt_e;++dIt) {
615 std::string
dirName=runDir+
"/"+(*dIt);
618 TDirectory*
dir=
dynamic_cast<TDirectory*
>(in1->Get(
dirName.c_str()));
620 std::cout <<
"Did not find directory " <<
dirName <<
" in file "<<
inFileNames[fileIndex].c_str()<<
" !" << std::endl;
623 if (
std::find(foundDirs.begin(), foundDirs.end(),
dirName) != foundDirs.end())
625 std::cout<<
"Already found "<<
dirName<<
" before"<<std::endl;
630 if (
debug) std::cout <<
"Found directory " <<
dirName <<
" in file "<<
inFileNames[fileIndex].c_str()<<
" !" << std::endl;
634 std::cout <<
"Number of directories: " << listOfHists.size() << std::endl;
635 std::cout<<
"SIZE "<< listOfHists.size() <<std::endl;
637 if (
debug) listOfHists.print();
644 for (;fileIndex<
nFiles;++fileIndex) {
649 std::cout <<
"ERROR: Could not open file " <<
filename <<
"after all attempts" << std::endl;
651 std::cout <<
"Failed to read " << nSkippedFiles <<
" input files. Abort job ..." << std::endl;
655 std::cout <<
"Failed to read " << 100.0*nSkippedFiles/
nFiles <<
"% of input files. Abort job ..." << std::endl;
659 std::cout <<
"Continue without this file. Skipped " << nSkippedFiles <<
" input files so far." << std::endl;
662 std::cout <<
"Working on file " <<
filename << std::endl;
663 TObject* dirObj=in->Get(runDir.c_str()+1);
665 std::cout <<
"Directory " << runDir <<
" not found. Ignoring apprently empty file" << std::endl;
668 listOfHists.addFile(in);
674 if (!
out || !
out->IsOpen()) {
675 std::cout <<
"ERROR: Failed to open output file " <<
outFileName <<
" for writing" << std::endl;
678 listOfHists.write(
out);
682 if (in1 && in1->IsOpen()) {
687 if (nSkippedFiles>0) {
688 std::cout <<
"WARNING: Skipped " << nSkippedFiles <<
" input file(s)." << std::endl;
◆ openWithRetry()
TFile* openWithRetry |
( |
const char * |
path, |
|
|
const unsigned |
nTrys = 3 |
|
) |
| |
Definition at line 27 of file LArQuickHistMerge.cxx.
30 unsigned sleepSeconds=30;
31 while (!
f && iTry<nTrys) {
32 f=TFile::Open(
path,
"READ");
33 if (!
f || !(
f->IsOpen())) {
35 std::cout <<
"WARNING: Failed to open file " <<
path <<
" on " << iTry <<
". attempt." << std::endl;
37 std::cout <<
"Will re-try after " << sleepSeconds <<
" seconds..." << std::endl;
43 std::cout <<
"No more retrys" << std::endl;
◆ readFromTextFile()
bool readFromTextFile |
( |
const char * |
filename, |
|
|
std::vector< std::string > & |
out |
|
) |
| |
Definition at line 441 of file LArQuickHistMerge.cxx.
442 std::ifstream ifs (
filename, std::ifstream::in );
444 std::cout <<
"Failed to open file " <<
filename <<
" for reading." << std::endl;
452 std::vector<std::string>::const_iterator
it=linetok.begin();
453 std::vector<std::string>::const_iterator it_e=linetok.end();
454 for(;
it!=it_e;++
it) {
455 if ((*
it)[0]==
'#')
break;
◆ splitString()
std::vector<std::string> splitString |
( |
const std::string & |
in, |
|
|
const std::string & |
delim |
|
) |
| |
Definition at line 428 of file LArQuickHistMerge.cxx.
429 std::vector<std::string> retvec;
430 size_t pos1=0,pos2=0;
431 while (pos2!=std::string::npos) {
432 pos2=in.find_first_of(delim,pos1);
433 const std::string sub=in.substr(pos1,pos2-pos1);
435 retvec.push_back(sub);
◆ MAXSKIPPEDFILES
const int MAXSKIPPEDFILES = 10 |
◆ MAXSKIPPEDFILESFRACTION
const float MAXSKIPPEDFILESFRACTION = 0.1 |