21 #include <boost/algorithm/string/split.hpp>
22 #include <boost/algorithm/string/classification.hpp>
23 #include <boost/lexical_cast.hpp>
28 #include <TDirectory.h>
33 #include <TIterator.h>
37 #include <TEfficiency.h>
38 #include "TTreeReader.h"
39 #include "TTreeReaderArray.h"
46 bool histOKToMerge(TH1*
h) {
47 Long_t arrsize, computedsize;
48 switch (
h->GetDimension()) {
50 computedsize =
h->GetNbinsX()+2;
53 computedsize = (
h->GetNbinsX()+2)*(
h->GetNbinsY()+2);
56 computedsize = (
h->GetNbinsX()+2)*(
h->GetNbinsY()+2)*(
h->GetNbinsZ()+2);
59 std::cerr <<
"Unable to handle dimension of " <<
h->GetName() <<
"; refusing to merge";
62 TArray* arrptr =
dynamic_cast<TArray*
>(
h);
64 std::cerr <<
"Unable to cast TH1 to TArray for " <<
h->GetName() <<
" - saying it's OK and hoping for the best" << std::endl;
67 arrsize = arrptr->GetSize();
68 if (computedsize != arrsize) {
69 std::cout <<
"Sizes: computed " << computedsize <<
" array " << arrsize << std::endl;
71 return computedsize == arrsize;
82 makeBranch(
"Name",
"Name/C" );
83 makeBranch(
"Interval",
"Interval/C" );
84 makeBranch(
"TriggerChain",
"TriggerChain/C" );
85 makeBranch(
"MergeMethod",
"MergeMethod/C" );
90 makeBranch(
const char* branchName,
const char* branchstr)
93 m_metadata->Branch(branchName, (
void*)
nullptr, branchstr);
99 fill(
const std::string & theName,
100 const std::string & theInterval,
101 const std::string & theChain,
102 const std::string & theMerge )
104 std::string
name=theName;
106 std::string
chain = theChain;
107 std::string
merge = theMerge;
108 m_metadata->SetBranchAddress(
"Name",
name.data());
109 m_metadata->SetBranchAddress(
"Interval",
interval.data());
110 m_metadata->SetBranchAddress(
"TriggerChain",
chain.data());
111 m_metadata->SetBranchAddress(
"MergeMethod",
merge.data());
153 std::cerr<<__PRETTY_FUNCTION__<<
"Warning empty regular expression string is given. Old RegEx \""<<
m_mergeMatchHistoREString<<
"\" is not changed"<<std::endl;
154 std::cerr<<__PRETTY_FUNCTION__<<
"See http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/boost_regex/syntax.html for allowed regular expression syntax"<<std::endl;
161 std::string
test(
"Test String");
162 std::regex_match(
test,*reNew);
164 std::cerr<<__PRETTY_FUNCTION__<<
"Invalid RegEx string \""<<
re<<
"\". Old RegEx \""<<
m_mergeMatchHistoREString<<
"\" is not changed"<<std::endl;
165 std::cerr<<__PRETTY_FUNCTION__<<
"See http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/boost_regex/syntax.html for allowed regular expression syntax"<<std::endl;
179 std::cerr<<__PRETTY_FUNCTION__<<
"Warning empty regular expression string is given. Old RegEx \""<<
m_mergeMatchDirREString<<
"\" is not changed"<<std::endl;
180 std::cerr<<__PRETTY_FUNCTION__<<
"See http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/boost_regex/syntax.html for allowed regular expression syntax"<<std::endl;
186 std::regex_match(
"Test string",*reNew);
188 std::cerr<<__PRETTY_FUNCTION__<<
"Invalid RegEx string \""<<
re<<
"\". Old RegEx \""<<
m_mergeMatchDirREString<<
"\" is not changed"<<std::endl;
189 std::cerr<<__PRETTY_FUNCTION__<<
"See http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/boost_regex/syntax.html for allowed regular expression syntax"<<std::endl;
208 if( dirName !=
"" ) {
209 DirMap_t::value_type dirmapVal( dirName,
dir );
210 dirmap.insert( dirmapVal );
213 TIter
next(
dir->GetListOfKeys() );
215 while( (
key =
dynamic_cast<TKey*
>(
next() )) != 0 ) {
217 TObject*
obj =
key->ReadObj();
218 TDirectory*
subdir =
dynamic_cast<TDirectory*
>(
obj );
220 std::string subdirName(
subdir->GetName() );
221 std::string
fName(
"");
222 if( dirName !=
"" ) {
244 DirMap_t::const_iterator diter;
245 std::string::size_type
i =
path.find_first_of(
'/');
246 std::string
fName(
"");
252 if(
i != std::string::npos ) {
253 std::string dName(
path, 0,
i );
254 std::string pName(
path,
i+1, std::string::npos );
257 diter = dirmap.find(
fName );
258 if( diter != dirmap.end() ) {
264 dirmap.insert( dirmapVal );
275 diter = dirmap.find(
fName );
276 if( diter != dirmap.end() ) {
277 return diter->second;
282 dirmap.insert( dirmapVal );
296 std::string::size_type
i =
path.find_first_of(
'/');
297 if(
i != std::string::npos ) {
298 std::string dName(
path, 0,
i );
299 std::string pName(
path,
i+1, std::string::npos );
301 key =
dir->FindKey( dName.c_str() );
303 TDirectory* subDir =
dynamic_cast<TDirectory*
>(
key->ReadObj() );
313 return dir->FindKey(
path.c_str() );
317 std::string
getInputDirectory(
const std::string & outputDirName, TFile*
input,
bool has_multiple_runs, std::map< TFile*, std::string >* prefixes) {
318 if (! has_multiple_runs) {
319 return outputDirName;
321 std::string
retval(outputDirName);
322 std::string::size_type sepi =
retval.find(
"run_multiple");
323 if (sepi != std::string::npos && prefixes->find(
input) != prefixes->end()) {
330 std::string
getOutputDirectory(
const std::string & inputDirName, TFile*
input,
bool has_multiple_runs, std::map< TFile*, std::string >* prefixes) {
331 if (! has_multiple_runs) {
334 std::string
retval(inputDirName);
335 if (prefixes->find(
input) == prefixes->end()) {
338 std::string::size_type sepi =
retval.find((*prefixes)[
input]);
339 if (sepi != std::string::npos) {
347 if (TClass::GetClass(
key->GetClassName())->InheritsFrom(
"TDirectory")) {
350 return key->GetName();
356 TIter nextKey(
dir->GetListOfKeys() );
359 while( (
key =
dynamic_cast<TKey*
>( nextKey() )) != 0 ) {
360 kcmap[
key->GetName()].push_back(
key->GetCycle());
368 const std::vector<int>& cycles,
370 const std::string & mergeType,
371 std::unique_ptr<TObject>&
obj) {
372 if (cycles.size() == 0) {
376 if (
obj ==
nullptr) {
377 TKey*
key(
dir->GetKey(keyname.c_str(), cycles[0]));
378 obj.reset(
key->ReadObj());
380 TH1*
h =
dynamic_cast<TH1*
>(
obj.get());
381 if (
h && !histOKToMerge(
h)) {
383 std::cerr <<
"WARNING: HISTOGRAM " <<
h->GetName() <<
" IS INTERNALLY INCONSISTENT, NOT MERGING" << std::endl;
387 for (std::vector<int>::size_type
idx = start_idx;
388 idx < cycles.size(); ++
idx) {
389 TKey* nextKey =
dir->GetKey(keyname.c_str(), cycles[
idx]);
391 std::unique_ptr<TObject> nextObj(nextKey->ReadObj());
392 if (nextObj.get() == 0) {
393 std::cerr <<
"MonitoringFile::mergeObjsMultiCycles(): "
394 <<
"In directory \"" <<
dir->GetPath() <<
"\",\n"
395 <<
" Object \"" << keyname <<
"\" cannot be read from file: skipping\n";
398 TH1*
h =
dynamic_cast<TH1*
>(nextObj.get());
399 if (
h && !histOKToMerge(
h)) {
401 std::cerr <<
"WARNING: HISTOGRAM " <<
h->GetName() <<
" IS INTERNALLY INCONSISTENT, NOT MERGING" << std::endl;
402 (void)nextObj.release();
407 h =
dynamic_cast<TH1*
>(
obj.get());
408 if (
h &&
h->GetEntries() == 0 &&
h->GetSumOfWeights() == 0) {
410 obj.reset(nextObj.release());
413 if (
h && (
obj->IsA() !=
h->IsA())) {
415 std::cerr <<
"WARNING: CHANGE OF CLASS TYPES FOR " <<
h->GetName() <<
", NOT MERGING" << std::endl;
420 std::cerr <<
"MonitoringFile::mergeObjsMultiCycles(): NULL KEY; corrupt file?" << std::endl;
427 void getListOfKeysWithName(TDirectory*
dir,
const std::string& keyname,
431 TIter keyit(
dir->GetListOfKeys());
433 while ( (
key =
dynamic_cast<TKey*
>(keyit())) != 0 ) {
434 if (keyname ==
key->GetName()) {
440 void populateCycleVector(
const TCollection&
source, std::vector<int>&
target)
444 while ( (
key =
dynamic_cast<TKey*
>(keyit())) != 0 ) {
457 typedef std::set< std::string > ObjNameSet_t;
458 typedef std::map< std::string, MetaData > MetaDataMap_t;
466 std::string outputDirPath(
outputDir->GetPath() );
467 std::string outputDirName( outputDirPath );
468 std::string::size_type sepi = outputDirPath.find_last_of(
':');
469 if( sepi != std::string::npos ) {
470 outputDirName = std::string( outputDirPath, sepi+2, std::string::npos );
473 bool metadataInDir =
false;
479 TTree* mdTree =
new TTree(
"metadata",
"Monitoring Metadata" );
480 mdTree->SetDirectory(0);
481 OutputMetadata outputmd( mdTree );
483 ObjNameSet_t mergedObjs;
486 std::vector<TFile*>::const_iterator inputFilesEnd =
inputFiles.end();
487 for( std::vector<TFile*>::const_iterator
i =
inputFiles.begin();
i != inputFilesEnd; ++
i ) {
503 TIter nextKey(
inputDir->GetListOfKeys() );
512 key =
inputDir->GetKey(kcit->first.c_str(), kcit->second.back());
514 std::cout <<
"Key " << kcit->first.c_str() <<
";" << kcit->second.back() <<
" not readable" << std::endl;
517 kcit->second.pop_back();
520 if( obji != mergedObjs.end() ) {
530 if(!targetDir && !
isDir){
534 std::unique_ptr<TObject>
obj(
key->ReadObj());
535 if (
obj.get() == 0) {
536 std::cerr <<
"MonitoringFile::mergeDirectory(): "
537 <<
"In directory \"" <<
inputDir->GetPath() <<
"\",\n"
538 <<
" Object \"" <<
key->GetName() <<
"\" cannot be read from file: skipping\n";
557 if ( (targetDir) && ( (
h =
dynamic_cast<TH1*
>(
obj.get()))
558 || (
g =
dynamic_cast<TGraph*
>(
obj.get()))
559 ||((
t =
dynamic_cast<TTree*
>(
obj.get())) && (
keyName!=
"metadata"))
560 || (
e =
dynamic_cast<TEfficiency*
>(
obj.get()))
570 std::string mergeType(
"<default>");
572 if( mdi != mdMap.end() ) {
573 metadataInDir =
true;
574 const MetaData& md = mdi->second;
575 if (has_multiple_runs &&
576 (md.interval !=
"run" &&
577 md.interval !=
"fill" &&
578 md.interval !=
"all" &&
579 md.interval !=
"file")){
582 outputmd.fill( md.name, md.interval, md.chain, md.merge );
583 mergeType = md.merge;
584 if(
g && (md.merge !=
"<default>") ) {
585 std::cerr <<
"MonitoringFile::mergeDirectory(): "
586 <<
"In directory \"" <<
inputDir->GetPath() <<
"\",\n"
587 <<
" TGraph \"" <<
keyName <<
"\" requests merging type " << mergeType
588 <<
" but only default merging implemented for TGraphs\n";
590 if(
t && (md.merge !=
"<default>") ) {
591 std::cerr <<
"MonitoringFile::mergeDirectory(): "
592 <<
"In directory \"" <<
inputDir->GetPath() <<
"\",\n"
593 <<
" TTree \"" <<
keyName <<
"\" requests merging type " << mergeType
594 <<
" but only default merging implemented for TTrees\n";
596 if(
e && (md.merge !=
"<default>") ) {
597 std::cerr <<
"MonitoringFile::mergeDirectory(): "
598 <<
"In directory \"" <<
inputDir->GetPath() <<
"\",\n"
599 <<
" TEfficiency \"" <<
keyName <<
"\" requests merging type " << mergeType
600 <<
" but only default merging implemented for TEfficiency\n";
603 std::cerr <<
"MonitoringFile::mergeDirectory(): "
604 <<
"In directory \"" <<
inputDir->GetPath() <<
"\",\n"
605 <<
" object \"" <<
keyName <<
"\" has no metadata\n";
610 TTree*
t2 =
t->CloneTree();
617 for( std::vector<TFile*>::const_iterator j =
i+1; j!= inputFilesEnd; ++j ) {
618 TFile* nextInputFile = *j;
619 TDirectory* nextInputDir = nextInputFile->GetDirectory(
getInputDirectory(outputDirName, *j, has_multiple_runs, prefixes).c_str() );
620 if( nextInputDir == 0 ) {
625 TObjArray
tl; std::vector<int> nextCycles;
626 getListOfKeysWithName(nextInputDir, kcit->first, &
tl);
627 populateCycleVector(
tl, nextCycles);
630 nextInputDir, mergeType,
obj);
634 if ((
h =
dynamic_cast<TH1*
>(
obj.get()))) {
639 }
else if( (targetDir) && (
t =
dynamic_cast<TTree*
>(
obj.get())) ) {
641 }
else if((
d =
dynamic_cast<TDirectory*
>(
obj.get() ))) {
647 TDirectory* outputSubDir =
outputDir->mkdir( outputSubDirName.c_str(),
d->GetTitle() );
650 std::cout <<
"MonitoringFile::mergeDirectory(): "
651 <<
"In directory \"" <<
inputDir->GetPath() <<
"\",\n"
652 <<
" Object \"" <<
key->GetName() <<
"\" will not be merged\n";
659 if( metadataInDir ) {
670 fillMetaDataMap( std::map<std::string,dqutils::MonitoringFile::MetaData>& mdMap, TDirectory*
dir )
672 if (
dir == 0)
return;
673 TTree *md =
dynamic_cast<TTree*
>(
dir->Get(
"metadata"));
677 TTreeReaderArray<char> i_name(
reader,
"Name");
678 TTreeReaderArray<char> i_interval(
reader,
"Interval");
679 TTreeReaderArray<char> i_chain(
reader,
"TriggerChain");
680 TTreeReaderArray<char> i_merge(
reader,
"MergeMethod");
683 const std::string nameStr(
static_cast<char*
>(i_name.GetAddress()));
684 if( mdMap.find(nameStr) == mdMap.end() ) {
685 MetaData md( nameStr,
686 static_cast<char*
>(i_interval.GetAddress()),
687 static_cast<char*
>(i_chain.GetAddress()),
688 static_cast<char*
>(i_merge.GetAddress()) );
689 std::map<std::string,MetaData>::value_type mdVal( nameStr, md );
690 mdMap.insert( mdVal );
705 TH1::AddDirectory(
false);
707 std::cout<<
" ========== Using regular expressions for selective merging ========== "<<std::endl;
712 std::cout <<
"CPU time measurement activated " << std::endl;
714 typedef std::vector<TFile*> TFileList_t;
715 typedef std::map<TFile*, std::string> PrefixIgnore_t;
719 std::cerr <<
"MonitoringFile::mergeFiles(): "
720 <<
"Output file not opened\n";
725 PrefixIgnore_t prefix_ignore;
727 std::vector< std::string >::const_iterator filesEnd =
files.end();
728 std::vector< std::string >::const_iterator
fi;
730 std::cout <<
"Opening file: " << *
fi <<
"\n";
731 TFile*
f = TFile::Open(
fi->c_str() );
732 if(
f == 0 || !
f->IsOpen()) {
733 std::cerr <<
"MonitoringFile::mergeFiles(): "
734 <<
"Input file not opened\n";
738 TList*
keys =
f->GetListOfKeys();
739 if (
keys->GetSize() == 0) {
740 std::cerr <<
"MonitoringFile::mergeFiles(): "
741 <<
"Input file " << *
fi <<
" has no keys!"
746 std::vector< std::string > runkeys;
750 while ( (
key =
dynamic_cast<TKey*
>(keyitr())) != 0 ) {
751 std::string keyname(
key->GetName());
752 if (keyname.substr(0,4) ==
"run_") {
753 runkeys.push_back(keyname);
756 if (runkeys.size() > 1) {
757 std::cerr <<
"MonitoringFile::mergeFiles():\n"
758 <<
" Input root file " << *
fi <<
" has multiple top-level run_* keys\n"
759 <<
" Assuming " << runkeys[0] <<
" is the run key"
762 if (runkeys.size() > 0) {
763 prefix_ignore[
f] = runkeys[0];
769 bool has_multiple_runs =
false;
770 std::string prev_key_name(
"");
772 for (PrefixIgnore_t::const_iterator pi_it = prefix_ignore.begin();
773 pi_it != prefix_ignore.end();
775 if (prev_key_name != pi_it->second) {
776 if (prev_key_name ==
"") {
777 prev_key_name = pi_it->second;
779 has_multiple_runs =
true;
785 if (has_multiple_runs) {
786 std::cout <<
"Multiple runs detected in input files.\n"
787 <<
"Will merge ONLY RUN, FILL, FILE, or ALL histograms to run_multiple directory.\n"
788 <<
"(That is, no event block, lumi block, lowStat, medStat,\n"
789 <<
"or higStat histograms will be in the output.)"
793 std::cout <<
"Writing file: " <<
outFileName <<
"\n";
794 std::cout <<
"\nWarning messages from merging follow:\n\n";
800 TFileList_t::const_iterator tfilesEnd = tfiles.end();
801 TFileList_t::const_iterator tfi;
802 for( tfi = tfiles.begin(); tfi != tfilesEnd; ++tfi ) {
810 std::vector<std::pair<std::string,clock_t> > cpuPerHistVec;
811 std::cout <<
"CPU time (seconds) for histogram merging:" << std::endl;
813 cpuPerHistVec.emplace_back(
name,time);
815 auto ordering=[](
const std::pair<std::string,clock_t>&
a,
const std::pair<std::string,clock_t>&
b) {
return a.second<
b.second;};
816 std::sort(cpuPerHistVec.begin(),cpuPerHistVec.end(),
ordering);
818 for (
const auto& [
name,time] : cpuPerHistVec) {
819 const double tSec=
double(time)/CLOCKS_PER_SEC;
824 std::cout <<
"****************************************\n\n";
832 typedef std::vector< std::string > FileList_t;
834 const unsigned int nFilesAtOnce = 50;
839 std::cerr <<
"MonitoringFile::mergeFiles(): Cannot merge files\n";
843 if(
allFiles.size() <= nFilesAtOnce ) {
848 FileList_t procFiles, tmpIntermediateFiles;
851 FileList_t::const_iterator filesEnd =
allFiles.end();
852 FileList_t::const_iterator
fi =
allFiles.begin();
855 std::string tmpInputFile(
"");
856 std::string tmpOutputFile(
"");
859 while(
fi != filesEnd ) {
861 procFiles.push_back(*
fi);
863 if (
counter % nFilesAtOnce == 0 ||
fi == filesEnd ) {
864 std::ostringstream nameStream;
865 nameStream <<
"tmp_merge_" <<
counter <<
".root";
866 tmpOutputFile = nameStream.str();
867 tmpIntermediateFiles.push_back(tmpOutputFile);
907 for (
const auto& tmpFile : tmpIntermediateFiles) {
908 const bool deleteSuccessful = (
std::remove(tmpFile.c_str()) == 0);
909 if (not deleteSuccessful){
910 std::cerr<<
"Temporary file "<<tmpFile<<
" could not be deleted.";
935 std::cerr <<
"MonitoringFile::printDirectories(): "
936 <<
"No input file is open\n";
944 DirMap_t::const_iterator idirend = indirmap.end();
945 for( DirMap_t::const_iterator idir = indirmap.begin(); idir != idirend; ++idir ) {
946 std::string idirName = idir->first;
947 std::cout << idirName <<
"\n";
957 std::cerr <<
"MonitoringFile::printStatistics(): "
958 <<
"No input file is open\n";
966 DirMap_t::const_iterator idirend = indirmap.end();
967 for( DirMap_t::const_iterator idir = indirmap.begin(); idir != idirend; ++idir ) {
968 std::string idirName = idir->first;
970 GatherStatistics stat_shift( idirName );
971 GatherStatistics stat_all( idirName );
976 std::cout.setf(std::ios_base::left,std::ios_base::adjustfield);
978 std::cout << idirName <<
" ";
980 std::cout.setf(std::ios_base::right,std::ios_base::adjustfield);
981 std::cout <<
" shift: ";
983 std::cout << stat_shift.m_nHist1D <<
" ";
985 std::cout << stat_shift.m_nHist1DBins <<
" ";
987 std::cout << stat_shift.m_nHist2D <<
" ";
989 std::cout << stat_shift.m_nHist2DBins <<
" ";
991 std::cout << stat_shift.m_nGraph <<
" ";
993 std::cout << stat_shift.m_nGraphPoints <<
" ";
996 std::cout <<
" all: ";
998 std::cout << stat_all.m_nHist1D <<
" ";
1000 std::cout << stat_all.m_nHist1DBins <<
" ";
1002 std::cout << stat_all.m_nHist2D <<
" ";
1004 std::cout << stat_all.m_nHist2DBins <<
" ";
1006 std::cout << stat_all.m_nGraph <<
" ";
1008 std::cout << stat_all.m_nGraphPoints <<
"\n";
1024 std::cerr <<
"MonitoringFile::copyHistograms(): "
1025 <<
"No input file is open\n";
1033 if( dirName !=
"all" ) {
1036 std::cerr <<
"MonitoringFile::copyHistograms(): "
1037 <<
"Directory \'" << dirName <<
"\' not found in input file\n";
1041 TDirectory* fromDir =
dynamic_cast<TDirectory*
>(dkey->ReadObj());
1043 DirMap_t::value_type dirmapVal( dirName, fromDir );
1044 indirmap.insert( dirmapVal );
1047 std::cout <<
"Building list of all TDirectories in file...\n" <<
std::flush;
1051 DirMap_t::const_iterator idirend = indirmap.end();
1052 for( DirMap_t::const_iterator idir = indirmap.begin(); idir != idirend; ++idir ) {
1054 std::string idirName = idir->first;
1055 std::cout <<
"Checking " << idirName <<
"\n" <<
std::flush;
1067 reducedmap.insert( *idir );
1072 std::cerr <<
"MonitoringFile::copyHistograms(): "
1073 <<
"Output file not opened\n";
1077 idirend = reducedmap.end();
1078 for( DirMap_t::const_iterator idir = reducedmap.begin(); idir != idirend; ++idir ) {
1080 std::string idirName = idir->first;
1081 std::cout <<
"Processing " << idirName <<
"\n" <<
std::flush;
1085 std::cerr <<
"MonitoringFile::copyHistograms(): "
1086 <<
"Directory \'" << idirName <<
"\' not created in output file\n";
1090 CopyHistogram copyFcn( toDir, idirName );
1107 const std::string &
hcfg,
const std::string & hcfg_lowStat,
const std::string & hcfg_medStat )
1111 std::cout <<
"\nUsing han configurations:\n"
1112 <<
" entire run: " <<
hcfg <<
"\n"
1113 <<
" low stat interval: " << hcfg_lowStat <<
"\n"
1114 <<
" medium stat interval: " << hcfg_medStat <<
"\n\n" <<
std::flush;
1119 std::cerr <<
"MonitoringFile::getHanResults(): "
1120 <<
"Cannot open input file \"" <<
input <<
"\"\n";
1124 std::vector<std::string> run_dirs;
1125 std::vector<std::string> lowStat_dirs;
1126 std::vector<std::string> medStat_dirs;
1128 TIter next_run(
infile->GetListOfKeys() );
1130 while( (key_run =
dynamic_cast<TKey*
>( next_run() )) != 0 ) {
1131 TObject* obj_run = key_run->ReadObj();
1132 TDirectory* tdir_run =
dynamic_cast<TDirectory*
>( obj_run );
1133 if( tdir_run != 0 ) {
1134 std::string tdir_run_name( tdir_run->GetName() );
1135 if( tdir_run_name.find(
"run") != std::string::npos ) {
1136 run_dirs.push_back( tdir_run_name );
1137 TIter next_minutes( tdir_run->GetListOfKeys() );
1138 TKey* key_minutes(0);
1139 while( (key_minutes =
dynamic_cast<TKey*
>( next_minutes() )) != 0 ) {
1140 TObject* obj_minutes = key_minutes->ReadObj();
1141 TDirectory* tdir_minutes =
dynamic_cast<TDirectory*
>( obj_minutes );
1142 if( tdir_minutes != 0 ) {
1143 std::string tdir_minutes_name( tdir_minutes->GetName() );
1144 if( tdir_minutes_name.find(
"lowStat") != std::string::npos ) {
1145 lowStat_dirs.push_back( tdir_run_name +
'/' + tdir_minutes_name );
1147 else if( tdir_minutes_name.find(
"medStat") != std::string::npos ) {
1148 medStat_dirs.push_back( tdir_run_name +
'/' + tdir_minutes_name );
1163 std::vector<std::string>::const_iterator dirs_end;
1164 std::vector<std::string>::const_iterator
dir;
1166 dirs_end = run_dirs.end();
1167 for(
dir = run_dirs.begin();
dir != dirs_end; ++
dir ) {
1168 const std::string& tdir_run_name = *
dir;
1169 std::string han_output_run =
hanResultsDir+
'/'+tdir_run_name+
"_han.root";
1170 std::cout <<
"Calling han( " <<
hcfg <<
", " <<
input <<
", " << tdir_run_name
1171 <<
", " << han_output_run <<
" ):\n" <<
std::flush;
1172 han.Analyze(
hcfg,
input, han_output_run, tdir_run_name );
1174 fileList += han_output_run +
" " + tdir_run_name +
"\n" ;
1177 dirs_end = lowStat_dirs.end();
1178 for(
dir = lowStat_dirs.begin();
dir != dirs_end; ++
dir ) {
1179 const std::string& tdir_minutes_path = *
dir;
1181 std::string tdir_minutes_underscore = tdir_minutes_path;
1182 std::string::size_type tdir_minutes_i = tdir_minutes_underscore.find(
'/');
1183 tdir_minutes_underscore.replace( tdir_minutes_i, 1,
"_" );
1185 std::string han_output_lowStat =
hanResultsDir+
'/'+tdir_minutes_underscore+
"_han.root";
1186 std::cout <<
"Running han, writing to " << han_output_lowStat <<
":\n" <<
std::flush;
1187 han.Analyze( hcfg_lowStat,
input, han_output_lowStat, tdir_minutes_path );
1189 std::string subdirname( tdir_minutes_path, tdir_minutes_i+1, std::string::npos );
1190 std::string
dirname( tdir_minutes_path, 0, tdir_minutes_i );
1191 fileList += han_output_lowStat +
" " + subdirname +
" " +
dirname +
" " + subdirname +
"\n" ;
1194 dirs_end = medStat_dirs.end();
1195 for(
dir = medStat_dirs.begin();
dir != dirs_end; ++
dir ) {
1196 const std::string& tdir_minutes_path = *
dir;
1198 std::string tdir_minutes_underscore = tdir_minutes_path;
1199 std::string::size_type tdir_minutes_i = tdir_minutes_underscore.find(
'/');
1200 tdir_minutes_underscore.replace( tdir_minutes_i, 1,
"_" );
1202 std::string han_output_medStat =
hanResultsDir+
'/'+tdir_minutes_underscore+
"_han.root";
1203 std::cout <<
"Running han, writing to " << han_output_medStat <<
":\n" <<
std::flush;
1204 han.Analyze( hcfg_medStat,
input, han_output_medStat, tdir_minutes_path );
1206 std::string subdirname( tdir_minutes_path, tdir_minutes_i+1, std::string::npos );
1207 std::string
dirname( tdir_minutes_path, 0, tdir_minutes_i );
1208 fileList += han_output_medStat +
" " + subdirname +
" " +
dirname +
" " + subdirname +
"\n" ;
1220 std::cerr <<
"MonitoringFile::printHanConfig(): "
1221 <<
"No input file is open\n";
1229 std::string
indent, indent_p,indent_c;
1230 std::string idirName_p;
1231 DirMap_t::const_iterator idirend = indirmap.end();
1232 for( DirMap_t::const_iterator idir = indirmap.begin(); idir != idirend; ++idir ) {
1233 std::string idirName = idir->first;
1234 std::string::size_type shortNameIndex = idirName.rfind(
'/' );
1235 std::string
shortName = idirName.substr( shortNameIndex+1, std::string::npos );
1237 std::string::size_type fsIndex = idirName.find(
'/' );
1238 std::string shortPath;
1239 if( fsIndex != shortNameIndex )
1240 shortPath = idirName.substr( fsIndex+1, shortNameIndex );
1242 shortPath = idirName.substr( fsIndex+1, std::string::npos );
1244 std::cout << idirName <<
"\n";
1245 std::cout << shortPath <<
", " <<
shortName <<
"\n";
1289 std::string space = leadingSpace;
1290 std::string::size_type
i =
pathName.find_first_of(
'/');
1291 if(
i != std::string::npos ) {
1292 std::string subPath(
pathName,
i+1, std::string::npos );
1303 int length = (
name1.size() < name2.size() ) ?
name1.size() : name2.size();
1326 , m_dirName(dirName)
1329 m_metadata =
new TTree(
"metadata",
"Monitoring Metadata" );
1330 m_metadata->SetDirectory(0);
1331 m_metadata->Branch(
"Name", (
void*)
nullptr,
"Name/C" );
1332 m_metadata->Branch(
"Interval", (
void*)
nullptr,
"Interval/C" );
1333 m_metadata->Branch(
"TriggerChain", (
void*)
nullptr,
"TriggerChain/C" );
1334 m_metadata->Branch(
"MergeMethod", (
void*)
nullptr,
"MergeMethod/C" );
1342 m_metadata->SetDirectory(m_target);
1343 m_metadata->Write();
1353 hist->SetDirectory(m_target);
1378 fillMD(
const MetaData& md )
1380 std::string
name(md.name);
1382 std::string
chain(md.chain);
1383 std::string
merge(md.merge);
1384 m_metadata->SetBranchAddress(
"Name",
name.data() );
1385 m_metadata->SetBranchAddress(
"Interval",
interval.data() );
1386 m_metadata->SetBranchAddress(
"TriggerChain",
chain.data() );
1387 m_metadata->SetBranchAddress(
"MergeMethod",
merge.data() );
1396 hist->SetDirectory(m_target);
1407 executeMD( TGraph* graph,
const MetaData& md )
1428 : m_dirName(dirName)
1443 TH2* hist2d =
dynamic_cast<TH2*
>(
hist );
1446 m_nHist2DBins += (hist2d->GetNbinsX() * hist2d->GetNbinsY());
1450 m_nHist1DBins +=
hist->GetNbinsX();
1460 m_nGraphPoints += graph->GetMaxSize();
1468 TH1* h_total =
eff->GetCopyPassedHisto();
1469 TH2* h_total2D =
dynamic_cast<TH2*
>( h_total );
1471 if( h_total2D != 0 ) {
1472 m_nEfficiencyBins += (h_total2D->GetNbinsX() * h_total2D->GetNbinsY());
1475 m_nEfficiencyBins += h_total->GetNbinsX();
1491 m_names.push_back( std::string(
hist->GetName()) );
1500 m_names.push_back( std::string(graph->GetName()) );
1506 m_names.push_back( std::string(
eff->GetName()) );
1538 TKey* mdKey =
dir->FindKey(
"metadata" );
1543 TTree* md =
dynamic_cast<TTree*
>( mdKey->ReadObj() );
1556 std::cerr <<
"Exception: \"" <<
e.what() <<
"\" in directory \""
1573 TIter
next(
dir->GetListOfKeys() );
1575 while( (
key =
dynamic_cast<TKey*
>(
next() )) != 0 ) {
1576 TObject*
obj =
key->ReadObj();
1580 if ((
h =
dynamic_cast<TH1*
>(
obj))) {
1582 }
else if ((
g =
dynamic_cast<TGraph*
>(
obj))) {
1584 }
else if ((
e =
dynamic_cast<TEfficiency*
>(
obj))) {
1597 TKey* mdKey =
dir->FindKey(
"metadata" );
1602 TTree* md =
dynamic_cast<TTree*
>( mdKey->ReadObj() );
1610 TTreeReaderArray<char> i_name(
reader,
"Name");
1611 TTreeReaderArray<char> i_interval(
reader,
"Interval");
1612 TTreeReaderArray<char> i_chain(
reader,
"TriggerChain");
1613 TTreeReaderArray<char> i_merge(
reader,
"MergeMethod");
1616 const std::string nameStr(
static_cast<char*
>(i_name.GetAddress()));
1618 i_key =
dir->FindKey(
static_cast<char*
>(i_name.GetAddress()) );
1620 std::cerr <<
"MonitoringFile::loopOnHistogramsInMetadata(): "
1621 <<
"No \'" << nameStr <<
"\' object found\n";
1624 MetaData md( nameStr,
1625 static_cast<char*
>(i_interval.GetAddress()),
1626 static_cast<char*
>(i_chain.GetAddress()),
1627 static_cast<char*
>(i_merge.GetAddress()) );
1628 TObject*
obj = i_key->ReadObj();
1629 TH1*
h =
dynamic_cast<TH1*
>(
obj );
1631 fcn.executeMD(
h, md );
1634 TGraph*
g =
dynamic_cast<TGraph*
>(
obj );
1636 fcn.executeMD(
g, md );
1652 using namespace std;
1656 ifstream listfile( listFileName.c_str() );
1658 cerr <<
"MonitoringFile::setListFromFile(): "
1659 <<
"cannot read from file: " << listFileName <<
"\n";
1666 while( getline(listfile,
line) ) {
1667 istringstream linestream(
line);
1668 while(linestream.get(
c)) {
1675 linestream.putback(
c);
1678 cerr <<
"MonitoringFile::setListFromFile(): "
1679 <<
"badly formatted line: " <<
line <<
"\n";
1694 std::string
name(
"mergeObjs");
1696 std::cerr <<
name <<
": empty target object pointer" << std::endl;
1700 std::cerr <<
name <<
": empty object pointer" << std::endl;
1705 std::cout <<
name <<
": obj->GetName() = " <<
obj->GetName() <<
", mergeType = " << mergeType <<
", class = " <<
obj->IsA()->GetName() << std::endl;
1707 const std::clock_t cpuStart=std::clock();
1709 TH2 *h2=0, *nextH2=0;
1717 if((
h =
dynamic_cast<TH1*
>( objTarget )) ) {
1720 nextH =
dynamic_cast<TH1*
>(
obj );
1722 std::cerr << objTarget->GetName() <<
" is a TH1, but " <<
obj->GetName() <<
" is not: skip merging" << std::endl;
1725 if( mergeType ==
"effAsPerCent" ) {
1726 if((h2 =
dynamic_cast<TH2*
>( objTarget )) && (nextH2 =
dynamic_cast<TH2*
>( nextH ))){
1731 }
else if( mergeType ==
"perBinEffPerCent" ) {
1733 }
else if( mergeType ==
"weightedAverage" ) {
1735 }
else if( mergeType ==
"weightedAverage2D" ) {
1738 }
else if( mergeType ==
"weightedEff" ) {
1740 }
else if( mergeType ==
"mergeRebinned" ) {
1742 }
else if( mergeType ==
"eventSample" ) {
1743 if((h2 =
dynamic_cast<TH2*
>( objTarget ))&& (nextH2 =
dynamic_cast<TH2*
>( nextH ))){
1746 }
else if( mergeType ==
"mergeRMS" ) {
1748 }
else if( mergeType ==
"RMSpercentDeviation" ) {
1750 }
else if( mergeType ==
"lowerLB" ) {
1752 }
else if( mergeType ==
"identical" ) {
1754 }
else if( mergeType ==
"merge" ) {
1755 TList
tl;
tl.Add(nextH);
h->Merge(&
tl);
1757 if (!
h->Add( nextH )) {
1758 std::cerr <<
"Histogram " <<
h->GetName() <<
" should NOT be using Add: needs to specify a merge method (e.g. merge) in its metadata\n";
1761 }
else if( (
g =
dynamic_cast<TGraph*
>( objTarget )) ) {
1762 if( mergeType !=
"<default>" ) {
1763 std::cerr <<
name <<
": TGraph " <<
obj->GetName() <<
" request mergeType = " << mergeType
1764 <<
" but only default merging implemented for TGraphs\n";
1766 TGraph *nextG =
dynamic_cast<TGraph*
>(
obj );
1771 }
else if( (
e =
dynamic_cast<TEfficiency*
>( objTarget )) ) {
1772 if( mergeType !=
"<default>" ) {
1773 std::cerr <<
name <<
": TEfficiency " <<
obj->GetName() <<
" request mergeType = " << mergeType
1774 <<
" but only default merging implemented for TEfficiencies.\n";
1776 TEfficiency *nextE =
dynamic_cast<TEfficiency*
>(
obj );
1781 }
else if ((
t =
dynamic_cast<TTree*
>( objTarget ))) {
1783 std::cout <<
"Merging Tree " <<
obj->GetName() << std::endl;
1785 if( mergeType !=
"<default>" ) {
1786 std::cerr <<
name <<
": TTree " <<
obj->GetName() <<
" request mergeType = " << mergeType
1787 <<
" but only default merging implemented for TTrees\n";
1789 TTree *nextT =
dynamic_cast<TTree*
>(
obj );
1795 std::cerr <<
name <<
": object is not a histogram or graph, merging not implemented" << std::endl;
1798 const std::clock_t
duration=std::clock()-cpuStart;
1800 if (!objPath.empty()) {
1803 for (
unsigned i=0;
i<3 && pSlash!=std::string::npos;++
i) {
1804 pSlash=objPath.find_first_of(
'/',pSlash+1);
1806 if (pSlash != std::string::npos) {
1807 name=objPath.substr(pSlash+1);
1824 std::string
name(
"mergeLB_recursiveDirCopy");
1826 std::cerr <<
name <<
": empty directory pointer cwd" << std::endl;
1829 if( ! dir_top_out ) {
1830 std::cerr <<
name <<
": empty directory pointer dir_top_out" << std::endl;
1834 std::cerr <<
name <<
": empty directory pointer dir_out" << std::endl;
1838 TIter
next(
cwd->GetListOfKeys());
1840 while( (
key=(TKey*)
next() ) ) {
1841 std::string keyClassName(
key->GetClassName());
1842 if( (keyClassName.size() > 9) && (keyClassName.substr(0,10) ==
"TDirectory") ) {
1843 TDirectory *
dir = (TDirectory*)
cwd->Get(
key->GetName());
1845 std::cerr <<
name <<
": could not retrieve directory " <<
key->GetName() <<
1846 " from " <<
cwd->GetPath() << std::endl;
1850 std::string p_top(dir_top_out->GetPath());
1852 if( p_top.size() <
p.size() ) {
1853 p =
p.substr(p_top.size()+1,
p.size()-p_top.size()-1);
1860 for(
it = v_dirsSub.begin();
it != v_dirsSub.end(); ++
it ) {
1861 if( *
it == (
p +
dir->GetName()) )
break;
1863 if(
it == v_dirsSub.end() ) {
1865 v_dirsSub.push_back(
p +
dir->GetName());
1868 TKey *test_key = dir_out->FindKey(
dir->GetName());
1869 TDirectory *dir_out_new(0);
1872 std::cout <<
name <<
": creating subdirectory " <<
dir->GetName();
1873 if(
p.size() != 0 ) std::cout <<
" in " <<
p << std::endl;
1874 else std::cout << std::endl;
1876 dir_out_new = (TDirectory*)
gDirectory->mkdir(
dir->GetName());
1877 if( ! dir_out_new ) {
1878 std::cerr <<
name <<
": could not create directory " <<
dir->GetName()
1879 <<
" in " <<
gDirectory->GetPath() << std::endl;
1884 std::cout <<
name <<
": " << dir_out->GetPath() <<
'/' <<
dir->GetName() <<
" exists already" << std::endl;
1886 dir_out_new = (TDirectory*) dir_out->Get(test_key->GetName());
1887 if( ! dir_out_new ) {
1888 std::cerr <<
name <<
": could not retrieve directory " << test_key->GetName()
1889 <<
" from " << dir_out->GetPath() << std::endl;
1903 std::string
name(
"mergeLB_createListOfHistos");
1905 std::cerr <<
name <<
": empty directory pointer" << std::endl;
1909 TIter
next(
cwd->GetListOfKeys());
1911 while( (
key=(TKey*)
next() ) ) {
1912 std::string keyClassName(
key->GetClassName());
1913 if( ( (keyClassName.size() > 2) && ( (keyClassName.substr(0,3) ==
"TH1") || (keyClassName.substr(0,3) ==
"TH2") ) ) ||
1914 ( (keyClassName.size() > 7) && ( (keyClassName.substr(0,8) ==
"TProfile") ) ) ||
1915 ( (keyClassName.size() > 5) && ( (keyClassName.substr(0,6) ==
"TGraph") ) ) ||
1916 ( (keyClassName.size() > 10) && ( (keyClassName.substr(0,11) ==
"TEfficiency") ) ) ) {
1918 std::cout <<
name <<
": found object: " <<
key->GetName();
1921 std::string p_top(dir_top->GetPath());
1922 std::string
p(
cwd->GetPath());
1923 if( p_top.size() <
p.size() ) {
1924 p =
p.substr(p_top.size()+1,
p.size()-p_top.size()-1);
1930 for(
it = v_histos.begin();
it != v_histos.end(); ++
it ) {
1931 if( *
it == (
p +
key->GetName()) )
break;
1934 if(
it == v_histos.end() ) {
1935 std::string objName(
p +
key->GetName());
1936 v_histos.push_back(objName);
1938 std::cout <<
", added to list: " <<
p +
key->GetName() << std::endl;
1942 std::cout <<
", already in list" << std::endl;
1953 std::string
name(
"mergeLB_processLBinterval");
1955 if( v_dirsStat.size() == 0 )
return 0;
1958 std::cerr <<
name <<
": empty pointer dir_run" << std::endl;
1962 if( ! v_dirsStat[0] ) {
1963 std::cerr <<
name <<
": empty first directory pointer" << std::endl;
1980 TDirectory *dir_merged = dir_run;
2000 std::vector<TDirectory*>::const_iterator
i;
2004 std::vector<std::string> v_dirsSub;
2005 for(
i = v_dirsStat.begin();
i != v_dirsStat.end(); ++
i ) {
2006 TDirectory *dirStat = *
i;
2009 std::cout <<
name <<
": getting input from directory " << dirStat->GetPath() << std::endl;
2015 if( v_dirsSub.size() == 0 ) {
2017 std::cout <<
name <<
": no subdirectories found" << std::endl;
2026 std::vector<std::string>::const_iterator it_string;
2027 for( it_string = v_dirsSub.begin(); it_string != v_dirsSub.end(); ++it_string ) {
2028 std::string dirFullName = *it_string;
2029 std::vector<std::string> v_histos;
2031 std::cout <<
name <<
": processing " << dirFullName << std::endl;
2032 for(
i = v_dirsStat.begin();
i != v_dirsStat.end(); ++
i ) {
2033 TDirectory *dirStat = *
i;
2034 TDirectory *
dir = (TDirectory*) dirStat->Get(dirFullName.c_str());
2036 std::cerr <<
name <<
": could not retrieve directory " << dirFullName <<
2037 " from " << dirStat->GetPath() << std::endl;
2041 std::cout <<
name <<
": processing LB folder " <<
dir->GetPath() << std::endl;
2045 if( v_histos.size() == 0 ) {
2047 std::cout <<
name <<
": no objects found" << std::endl;
2051 TDirectory *dir_out = (TDirectory*) dir_merged->Get(dirFullName.c_str());
2053 std::cerr <<
name <<
": could not retrieve directory " << dirFullName <<
2054 " from " << dir_merged->GetPath() << std::endl;
2059 typedef std::map< std::string, MetaData > MetaDataMap_t;
2060 TTree* mdTree =
dynamic_cast<TTree*
>(dir_out->Get(
"metadata"));
2062 mdTree =
new TTree(
"metadata",
"Monitoring Metadata" );
2064 mdTree->SetDirectory(0);
2065 OutputMetadata outputmd( mdTree );
2070 MetaDataMap_t mdMap;
2071 TDirectory *dir_in = (TDirectory*) v_dirsStat[0]->
Get(dirFullName.c_str());
2073 std::cerr <<
name <<
": could not retrieve directory " << dirFullName <<
2074 " from " << v_dirsStat[0]->GetPath() << std::endl;
2080 std::vector<std::string>::const_iterator it_string2;
2081 for( it_string2 = v_histos.begin(); it_string2 != v_histos.end(); ++it_string2 ) {
2082 std::string histFullName = *it_string2;
2084 TObject *objMerged(0);
2085 std::string mergeType(
"<default>");
2087 bool key_checked =
false;
2088 for(
i = v_dirsStat.begin();
i != v_dirsStat.end(); ++
i ) {
2090 TDirectory *dir_current = (*i);
2091 std::unique_ptr<TObject> objThis((TObject*) dir_current->Get(histFullName.c_str()));
2093 if( ! objThis.get() ) {
2098 if (! key_checked) {
2099 TKey *test_key = dir_out->FindKey(objThis->GetName());
2102 std::cout <<
name <<
": " << dir_out->GetPath() <<
'/' << objThis->GetName()
2103 <<
" exists already, not written" << std::endl;
2111 objMerged = objThis->Clone();
2114 const MetaData *md(0);
2115 if( mdi != mdMap.end() ) {
2116 md = &(mdi->second);
2125 mdi = mdMap.find(objThis->GetName());
2126 if( mdi != mdMap.end() ) {
2127 md = &(mdi->second);
2132 std::cerr <<
name <<
": no metadata for " << histFullName << std::endl;
2133 std::cerr <<
name <<
": => using default merging" << std::endl;
2136 outputmd.fill( md->name, md->interval, md->chain, md->merge );
2137 mergeType = md->merge;
2143 TH1*
h =
dynamic_cast<TH1*
>(objMerged);
2144 if (
h &&
h->GetEntries() == 0 &&
h->GetSumOfWeights() == 0) {
2146 objMerged = objThis->Clone();
2148 mergeObjs(objMerged, objThis.get(), mergeType,
debugLevel, std::string(dir_out->GetPath()));
2159 std::cout <<
name <<
": wrote " << dir_out->GetPath() <<
'/' << objMerged->GetName() << std::endl;
2165 mdTree->SetDirectory(dir_out);
2166 mdTree->Write(0, kOverwrite);
2175 std::vector<std::string> v_splits;
2176 typedef std::vector<std::pair<TDirectory*, std::pair<int, int> > > range_t;
2178 for (std::vector<TDirectory*>::const_iterator dirit = v_dirsInterval.begin();
2179 dirit != v_dirsInterval.end();
2181 std::string
dirname((*dirit)->GetName());
2182 std::string corename(
dirname.substr(10, std::string::npos));
2183 boost::split(v_splits, corename, boost::algorithm::is_any_of(std::string(
"-")));
2184 if (v_splits.size() != 2) {
2185 std::cerr <<
"Unable to properly parse " << (*dirit)->GetName() << std::endl;
2189 << v_splits[0] <<
" "
2190 << v_splits[1] << std::endl;
2192 v_ranges.push_back(std::make_pair(*dirit, std::make_pair(boost::lexical_cast<int>(v_splits[0]), boost::lexical_cast<int>(v_splits[1]))));
2193 }
catch (boost::bad_lexical_cast&
e) {
2194 std::cerr <<
"Unable to cast to integers: " << v_splits[0] <<
" "
2195 << v_splits[1] << std::endl;
2198 for (std::vector<TDirectory*>::const_iterator dirit = v_dirLBs.begin();
2199 dirit != v_dirLBs.end();
2201 std::string
dirname((*dirit)->GetName());
2202 int lbnum = boost::lexical_cast<int>(
dirname.substr(3, std::string::npos));
2203 for (range_t::const_iterator rangeit = v_ranges.begin();
2204 rangeit != v_ranges.end(); ++rangeit) {
2205 if ((*rangeit).second.first <=
lbnum &&
2206 lbnum <= (*rangeit).second.second) {
2208 (*mapit).second.push_back(*dirit);
2215 std::map<TDirectory*,std::vector<TDirectory*> >
mapping;
2216 for (std::vector<TDirectory*>::const_iterator dirit = v_dirsInterval.begin();
2217 dirit != v_dirsInterval.end(); ++dirit) {
2218 mapping[*dirit] = std::vector<TDirectory*>();
2223 mapit !=
mapping.end(); ++mapit) {
2233 std::string
name(
"mergeLB_processRun");
2235 std::cerr <<
name <<
": empty pointer to run directory" << std::endl;
2240 std::cout <<
name <<
": processing dir " << dir_run->GetName() << std::endl;
2242 std::vector<TDirectory*> v_dirsLowStat, v_dirsMedStat, v_dirsHigStat,
2245 TIter
next(dir_run->GetListOfKeys());
2247 while( (
key=(TKey*)
next() ) ) {
2248 std::string keyClassName(
key->GetClassName());
2249 if( (keyClassName.size() > 9) && (keyClassName.substr(0,10) ==
"TDirectory") ) {
2250 TDirectory *
dir = (TDirectory*) dir_run->Get(
key->GetName());
2252 std::cerr <<
name <<
": could not retrieve " <<
key->GetName() <<
" from " << dir_run->GetPath() << std::endl;
2255 std::string dirName(
dir->GetName());
2256 if ( dirName.substr(0,3) ==
"lb_" ) {
2257 v_dirsLB.push_back(
dir);
2258 }
else if( dirName.size() > 7 ) {
2259 if( dirName.substr(0,8) ==
"lowStat_" ) {
2260 v_dirsLowStat.push_back(
dir);
2262 else if( dirName.substr(0,8) ==
"medStat_" ) {
2263 v_dirsMedStat.push_back(
dir);
2265 else if( dirName.substr(0,8) ==
"higStat_" ) {
2266 v_dirsHigStat.push_back(
dir);
2272 if(
debugLevel >=
DEBUG ) std::cout <<
"\n" <<
name <<
": processing LB directories" << std::endl;
2275 if(
debugLevel >=
DEBUG ) std::cout <<
"\n" <<
name <<
": processing lowStat directories" << std::endl;
2278 if(
debugLevel >=
DEBUG ) std::cout <<
"\n" <<
name <<
": processing medStat directories" << std::endl;
2281 if(
debugLevel >=
DEBUG ) std::cout <<
"\n" <<
name <<
": processing higStat directories" << std::endl;
2290 std::string
name(
"mergeLBintervals");
2293 if(inDebugLevel.empty()){
2303 TIter
next(
f->GetListOfKeys());
2305 while( (
key=(TKey*)
next() ) ) {
2306 std::string keyClassName(
key->GetClassName());
2307 if( (keyClassName.size() > 9) && (keyClassName.substr(0,10) ==
"TDirectory") ) {
2308 TDirectory *
dir = (TDirectory*)
f->Get(
key->GetName());
2310 std::cerr <<
name <<
": could not retrieve " <<
key->GetName()
2311 <<
" from top level directory of " << inFilename << std::endl;
2314 std::string dirName(
dir->GetName());
2315 if( (dirName.size() > 3) && (dirName.substr(0,4) ==
"run_") ) {
2317 std::cout <<
name <<
": found run dir " << dirName << std::endl;
2332 std::unique_ptr<TObject>
obj(
f->Get(HistoName));
2350 std::string
path =
dir->GetPath();
2351 if (
path.find(
':') != std::string::npos )