|
ATLAS Offline Software
|
Go to the documentation of this file.
38 #include "TDirectory.h"
58 std::string
a = ctime(&
t);
60 for (
unsigned i=0 ;
i<
a.size()-1 ;
i++ )
b+=
a[
i];
73 std::ostream*
outp = &std::cout;
82 std::string
algorithm =
"HLT_Histogram_Not_Empty&GatherData";
88 std::string
description =
"https://twiki.cern.ch/twiki/bin/view/Atlas/HltTrackingDataQualityMonitoring#Tier0";
92 std::map<std::string, std::string>
remap;
99 std::map<std::string, int>
dirs;
106 if (
v.empty() )
return s;
107 for (
size_t i=0 ;
i<
v.size() ;
i++ )
s <<
v[
i] <<
"\n";
111 bool contains(
const std::string&
s,
const std::string& regx ) {
return s.find(regx)!=std::string::npos; }
116 std::ostream&
operator<<( std::ostream&
s,
const std::vector<T*>&
v ) {
117 if (
v.empty() )
return s;
118 for (
int i=0 ;
i<
v.size() ;
i++ )
s << *
v[
i] <<
"\n";
128 TObject*
a = tobj->ReadObj()->Clone();
129 ((TH1*)
a)->SetDirectory(0);
135 std::string
find(
const std::string&
s ) {
136 std::map<std::string, std::string>::const_iterator itr =
remap.find(
s);
137 if ( itr!=
remap.end() )
return itr->second;
143 int count( std::string
s,
const std::string& regx ) {
144 size_t p =
s.find( regx );
146 while (
p!=std::string::npos ) {
158 std::string
chop(std::string&
s1,
const std::string&
s2)
160 std::string::size_type
pos =
s1.find(
s2);
162 if (
pos == std::string::npos ) {
164 s1.erase(0,
s1.size());
174 std::vector<std::string>
split(
const std::string&
s,
const std::string&
t=
":" ) {
179 std::vector<std::string>
tags;
181 while (
pos!=std::string::npos ) {
196 std::string::size_type
pos =
s1.find(
s2);
198 if (
pos == std::string::npos ) {
211 std::string
chomp(std::string&
s1,
const std::string&
s2)
213 std::string::size_type
pos =
s1.find(
s2);
215 if (
pos == std::string::npos ) {
233 std::string::size_type
pos =
s1.find(
s2);
234 if (
pos != std::string::npos ) {
247 std::string::size_type
pos =
s1.find(
s2);
248 if (
pos != std::string::npos ) {
260 std::string::size_type
pos =
s1.find_first_not_of(
s2);
261 if (
pos != std::string::npos ) {
276 std::string::size_type
pos =
s1.find_last_not_of(
s2);
277 if (
pos != std::string::npos ) {
299 std::string::size_type
pos;
300 while ( (
pos =
s.find(
s2))!=std::string::npos ) {
307 std::string
replace( std::string
s,
const std::string&
s2,
const std::string&
s3) {
308 std::string::size_type
pos;
311 while ( (
pos =
s.find(
s2))!=std::string::npos ) {
322 std::string::size_type
pos;
323 while ( (
pos =
s.find(
regex))!=std::string::npos ) {
330 std::vector<std::string>
maphist(
const std::vector<std::string>&
v ) {
332 for (
unsigned i=0 ;
i<
v.size() ;
i++ ) {
334 std::string
tmp =
v[
i];
361 int i = ( i1<i2 ? i1 : i2 );
365 for (
i++ ;
i-- ; ) {
366 size_t p1 =
s1.find(
'/');
367 size_t p2 =
s2.find(
'/');
369 std::string ss1 =
s1.substr( 0,
p1 );
370 std::string ss2 =
s2.substr( 0,
p2 );
377 if ( ss1!=ss2 )
return false;
392 std::map<std::string,int>::const_iterator itr =
dirs.begin();
393 while ( itr!=
dirs.end() ) {
403 if (
dirs.size()==0 )
return true;
404 std::map<std::string,int>::const_iterator itr =
dirs.begin();
405 while ( itr!=
dirs.end() ) {
406 if (
s.find(itr->first)!=std::string::npos )
return true;
415 if (
dirs.size()==0 )
return "";
416 std::map<std::string,int>::const_iterator itr =
dirs.begin();
417 while ( itr!=
dirs.end() ) {
418 if (
s.find(itr->first)!=std::string::npos )
return itr->first;
425 std::map<std::string,int>::const_iterator
matchcwditr(
const std::string&
s ) {
426 if (
dirs.size()==0 )
return dirs.end();
427 std::map<std::string,int>::const_iterator itr =
dirs.begin();
428 while ( itr!=
dirs.end() ) {
429 if (
s.find(itr->first)!=std::string::npos )
return itr;
446 std::cerr <<
"opening file " <<
f << std::endl;
448 TFile*
r = TFile::Open(
f.c_str());
450 std::cerr <<
"cannot open root file " <<
f << std::endl;
460 for (
int i=0 ;
i<
tl->GetSize() ;
i++ ) {
462 TKey* tobj = (TKey*)
tl->At(
i);
464 if ( std::string(tobj->GetClassName()).find(
"TDirectory")!=std::string::npos ) {
467 TDirectory* tnd = (TDirectory*)tobj->ReadObj();
469 std::string
dir = tnd->GetName();
472 dir.erase( 0, std::string(
"run_").size() );
505 static bool first =
true;
507 s <<
"##########################\n";
508 s <<
"# References\n";
509 s <<
"##########################\n\n";
512 s <<
"reference " <<
r.name() <<
" {\n";
513 s <<
"\t\tfile = " <<
r.file() <<
"\n";
514 s <<
"\t\tpath = run_" <<
r.run() <<
"\n";
515 s <<
"\t\tname = same_name" <<
"\n";
534 (*outp) <<
"######################################################################\n";
535 (*outp) <<
"# $Id: collisions_run.config " <<
date() <<
" " <<
user <<
" $\n";
536 (*outp) <<
"######################################################################\n";
539 (*outp) <<
"#######################\n";
540 (*outp) <<
"# HLTidtrk\n";
541 (*outp) <<
"#######################\n";
558 (*outp) <<
"#######################\n";
559 (*outp) <<
"# Output\n";
560 (*outp) <<
"#######################\n\n\n";
574 if (
n.name()==
"top_level" )
print =
true;
590 std::string newspacer = space;
594 std::string output_name =
find(
n.name());
598 if (
path==
"" )
path += output_name;
599 else path +=
"/" + output_name;
600 if ( rawpath==
"" ) rawpath +=
n.name();
601 else rawpath +=
"/" +
n.name();
608 if (
print ) (*outp) << space <<
"output " << output_name <<
" {" <<
"\n";
610 for (
unsigned i=0 ;
i<
n.size() ;
i++ ) {
614 if (
print ) (*outp) << space <<
"}\n";
632 (*outp) <<
"#######################\n";
633 (*outp) <<
"# Histogram Assessments\n";
634 (*outp) <<
"#######################\n\n";
639 void makeass(
node&
n,
const std::string& space=
"", std::string
path=
"", std::string rawpath=
"",
bool found=
false ) {
641 static std::string savedir =
"";
654 std::string newspacer = space;
665 std::string output_name =
find(
n.name());
668 if (
path==
"" )
path += output_name;
669 else path +=
"/" + output_name;
670 if ( rawpath==
"" ) rawpath +=
n.name();
671 else rawpath +=
"/" +
n.name();
676 if (
print ) (*outp) << space <<
"dir " <<
n.name() <<
" {" <<
"\n";
678 bool first_hists =
true;
680 for (
unsigned i=0 ;
i<
n.size() ;
i++ ) {
685 (*outp) << space <<
"\t" <<
"hist .* {\n";
686 (*outp) << space <<
"\t\t" <<
"regex \t= 1\n";
687 (*outp) << space <<
"\t\t" <<
"algorithm \t= " <<
algorithm <<
"\n";
688 (*outp) << space <<
"\t\t" <<
"description \t= " <<
description <<
"\n";
689 (*outp) << space <<
"\t\t" <<
"output \t= " <<
path <<
"\n";
690 (*outp) << space <<
"\t\t" <<
"display \t= StatBox\n";
693 (*outp) << space <<
"\t" <<
"}\n";
698 (*outp) << space <<
"\t" <<
"hist " <<
n[
i]->name() <<
" {\n";
699 (*outp) << space <<
"\t\t" <<
"algorithm \t= " <<
algorithm <<
"\n";
700 (*outp) << space <<
"\t\t" <<
"description \t= " <<
description <<
"\n";
701 (*outp) << space <<
"\t\t" <<
"output \t= " <<
path <<
"\n";
702 (*outp) << space <<
"\t\t" <<
"display \t= StatBox\n";
705 (*outp) << space <<
"\t" <<
"}\n";
715 if (
print ) (*outp) << space <<
"}\n";
743 if ( std::string(td->GetName()).find(
"_LB")!=std::string::npos )
return;
744 if ( std::string(td->GetName()).find(
"lb_")!=std::string::npos )
return;
755 std::cerr <<
"search() WARNING too many levels of directories (max 10) !!!\n";
766 if (
cwd!=
"" )
cwd +=
"/";
767 cwd += td->GetName();
771 std::string
fulldir = td->GetName();
774 bool first_found =
false;
779 if ( (
cwd+
"/").
find( ase+
"/" )!=std::string::npos ) {
784 std::cerr <<
"matched dirs " <<
cwd <<
" " <<
matchdir(
cwd ) << std::endl;
787 std::map<std::string,int>::const_iterator fitr =
matchcwditr(
cwd );
789 if ( fitr!=
dirs.end() ) {
791 if ( fitr->second>0 ) {
793 std::vector<std::string> subpath;
795 std::string sp = fitr->first;
797 while( sp.size() ) subpath.push_back(
chop(sp,
"/") );
799 for (
unsigned ip=0 ;
ip<subpath.size()-1 ;
ip++ ) {
830 for (
int i=0 ;
i<
tl->GetSize() ;
i++ ) {
832 TKey* tobj = (TKey*)
tl->At(
i);
834 if ( tobj==0 )
continue;
840 if ( std::string(tobj->GetClassName()).find(
"TDirectory")!=std::string::npos ) {
843 TDirectory* tnd = (TDirectory*)tobj->ReadObj();
855 if ( std::string(tobj->GetClassName()).find(
"TH1")!=std::string::npos ||
856 std::string(tobj->GetClassName()).find(
"TH2")!=std::string::npos ||
857 std::string(tobj->GetClassName()).find(
"TProfile")!=std::string::npos ) {
874 if ( std::string(tobj->GetName())==
"Chain" ) {
875 double N = ((TH1*)get<TObject>(tobj))->
GetEntries();
879 std::cout <<
"\t" <<
subdir <<
"\t" <<
N << std::endl;
882 if (
p &&
p->name()!=
"Shifter" ) {
884 p->addrate(
p->name(),
N );
887 if (
p2 )
p2->addrate(
p->name(),
N );
921 int cost( std::vector<std::string>&
files,
node&
n,
const std::string&
directory=
"",
bool deleteref=
false,
bool relocate=
false ) {
923 std::cerr <<
"processing ..." << std::endl;
930 for (
unsigned i=0 ;
i<
files.size() ;
i++ ) {
934 std::cerr <<
"opening " <<
currentfile << std::endl;
937 std::cerr <<
"file " <<
files[
i] <<
" does not exist" << std::endl;
945 std::cerr <<
"file " <<
files[
i] <<
" cannot be opened" << std::endl;
970 if ( deleteref || relocate ) {
972 std::cerr <<
"remapping" << std::endl;
976 if ( relocate && !deleteref ) std::cerr <<
"saving histograms to file .newhist.root ... " << std::endl;
979 TFile* fnew =
new TFile(
outref.c_str(),
"recreate" );
986 for (
unsigned ih=0 ; ih<
savedhistos.size() ; ih++ ) {
990 for (
unsigned jh=0 ; jh<
dirs.size()-1 ; jh++ ) {
992 TDirectory* renedir =
gDirectory->GetDirectory(
dirs[jh].c_str() );
1000 href->Write(
dirs.back().c_str() );
1009 std::cerr <<
"closing files" << std::endl;
1016 if (
outref==
".newhist.root" ) {
1017 std::cerr <<
"replacing histogram file" << std::endl;
1018 std::string
cmd = std::string(
"mv ") +
files[
i] +
" " +
files[
i] +
".bak";
1019 std::system(
cmd.c_str() );
1020 cmd = std::string(
"mv .newhist.root ") +
files[
i];
1021 std::system(
cmd.c_str() );
1035 s <<
"Usage: " <<
argv[0] <<
" [OPTIONS] input1.root ... inputN.root\n\n";
1036 s <<
" -o FILENAME \tname of output (filename required)\n";
1037 s <<
" -b, --base DIR \tuse directory DIR as the base for the han config\n";
1038 s <<
" -d, --dir DIR \tonly directories below DIR where DIR is a structure such as HLT/TRIDT etc\n";
1039 s <<
" -x, DIR \texclude directory DIR\n";
1040 s <<
" -r SRC DST \tremap directory SRC to directory DST\n";
1041 s <<
" -ds, --desc DESCRIP \tuse DESCRIP as the description\n";
1042 s <<
" -t, --tag VALUE \tadd the VALUE to the list of command per histogram\n";
1043 s <<
" -a, --algorithm VALUE \tuse VALUE as the execution algorithm for each histogram\n";
1044 s <<
" -wc, --wildcard \tprint use hist * rather than a separate entry for each histogram\n";
1045 s <<
" -dr, --deleteref \tdelete unselected histograms\n";
1046 s <<
" -or, --outref FILENAME \tdelete file to write reduced output to (overwrites input otherwise) \n";
1047 s <<
" -rh, --relocate \trelocate selected histograms\n";
1048 s <<
" -ref, --reference TAG FILE \tadd FILE as a reference file with tag TAG\n";
1049 s <<
" -rc, --refconf FILE \tadd FILE to the config as a reference block\n";
1050 s <<
" -v, --verbose \tprint verbose output\n";
1051 s <<
" -h, --help \tdisplay this help\n";
1060 std::ifstream strm(
file.c_str());
1073 gStyle->SetPadRightMargin(0.05);
1074 gStyle->SetPadTopMargin(0.075);
1077 TCanvas* tg =
new TCanvas(
"tg",
"tg", 700, 600 );
1080 gStyle->SetStatY(0.4);
1082 gStyle->SetStatX(0.89);
1084 gStyle->SetStatW(0.25);
1086 gStyle->SetStatH(0.16);
1093 for (
int i=1 ;
i<
argc ;
i++ ) {
1097 std::string
dir =
"";
1099 std::vector<std::string> subdirs;
1102 bool deleteref =
false;
1103 bool relocate =
false;
1110 for (
int i=1 ;
i<
argc ;
i++ ) {
1111 if ( std::string(
argv[
i])==
"-v" || std::string(
argv[
i])==
"--verbose" )
verbose =
true;
1112 else if ( std::string(
argv[
i])==
"-o" ) {
1117 else if ( std::string(
argv[
i])==
"-or" || std::string(
argv[
i])==
"--outrefr" ) {
1122 else if ( std::string(
argv[
i])==
"-ref" || std::string(
argv[
i])==
"--reference" ) {
1134 else if ( std::string(
argv[
i])==
"-rc" || std::string(
argv[
i])==
"-refconf" ) {
1139 else if ( std::string(
argv[
i])==
"-dr" || std::string(
argv[
i])==
"--deleteref" ) deleteref =
true;
1140 else if ( std::string(
argv[
i])==
"-rh" || std::string(
argv[
i])==
"--relocate" ) relocate =
true;
1141 else if ( std::string(
argv[
i])==
"-wc" || std::string(
argv[
i])==
"--wildcard" )
allhists =
false;
1142 else if ( std::string(
argv[
i])==
"-d" || std::string(
argv[
i])==
"--dir" ) {
1146 std::string stringdir(
argv[
i]);
1147 dirs.insert( std::map<std::string,int>::value_type( stringdir,
std::count( stringdir.begin(), stringdir.end(),
'/' ) ) );
1149 std::string tdir =
argv[
i];
1154 subdirs.push_back(
chop( tdir,
"/" ) );
1157 while ( tdir.size() );
1161 else if ( std::string(
argv[
i])==
"-x" ) {
1166 else if ( std::string(
argv[
i])==
"-ds" || std::string(
argv[
i]).
find(
"--desc")==0 ) {
1171 else if ( std::string(
argv[
i])==
"-b" || std::string(
argv[
i])==
"--base" ) {
1176 else if ( std::string(
argv[
i])==
"-a" || std::string(
argv[
i])==
"--algorithm" ) {
1186 else if ( std::string(
argv[
i])==
"-t" || std::string(
argv[
i])==
"--tag" ) {
1191 else if ( std::string(
argv[
i])==
"-r" ) {
1197 remap.insert( std::map<std::string,std::string>::value_type(
src,
dest ) );
1223 if (
verbose ) std::cerr <<
"timing" << std::endl;
1230 n.name(
"top_level" );
1253 (*outp) << std::endl;
1257 if (
t>1000 ) std::cerr <<
"total time " <<
t*0.001 <<
" s" << std::endl;
1258 else std::cerr <<
"total time " <<
t <<
" ms" << std::endl;
std::ostream * outp
send output to here ...
std::string matchcwdstr(const std::string &s)
std::string replace(std::string s, const std::string &s2, const std::string &s3)
int cost(std::vector< std::string > &files, node &n, const std::string &directory="", bool deleteref=false, bool relocate=false)
std::string chomp(std::string &s1, const std::string &s2)
std::map< std::string, int >::const_iterator matchcwditr(const std::string &s)
path
python interpreter configuration --------------------------------------—
struct timeval simpletimer_start(void)
std::string find(const std::string &s)
return a remapped string
ass(node &n, bool ah=true)
std::string chopends(std::string &s1, const std::string &s2)
std::string date()
sadly, includes a return at the end
std::string chopex(std::string &s1, const std::string &s2)
std::string chop(std::string &s1, const std::string &s2)
std::vector< std::string > refblock
TGraphErrors * GetEntries(TH2F *histo)
std::set< std::string > exclude
list of directories to be excluded
node * addnode(node *np, const std::string &name, TObject *td, node::TYPE t)
add a submode with a specific name, or return the existing node if one already exists
std::vector< reference > references
const std::string & file() const
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
int main(int argc, char **argv)
std::string chopfirst(std::string &s1, const std::string &s2)
std::vector< std::string > tags
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...
std::vector< std::string > maphist(const std::vector< std::string > &v)
reference(const std::string &n, const std::string &f)
bool matchdir(const std::string &s)
see whether this directory matches any of the directories we are explicitly being asked to match
std::vector< std::string > files
file names and file pointers
std::vector< std::string > split(const std::string &s, const std::string &t=":")
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
void referenceblock(const std::string &file)
void depunctuate(std::string &s, const std::string ®ex=":")
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
std::vector< TFile * > fptr
reference(const reference &r)
std::string chomptoken(std::string &s1, const std::string &s2)
double simpletimer_stop(const struct timeval &start_time)
void removespace(std::string &s, const std::string &s2)
std::string choplast(std::string &s1, const std::string &s2)
std::map< std::string, int > dirs
list of directories to be explicitly included, together with corresponding depths of subdirectories
int ir
counter of the current depth
std::string getenv(const std::string &variableName)
get an environment variable
std::map< std::string, std::string > remap
list of directories to be explicitly remapped
def time(flags, cells_name, *args, **kw)
std::vector< std::string > savedhistos
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
std::vector< std::string > mapped
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
const std::string & name() const
int usage(std::ostream &s, int, char **argv, int status=-1)
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
std::ostream & operator<<(std::ostream &s, const std::vector< T > &v)
std::string choptoken(std::string &s1, const std::string &s2)
Define macros for attributes used to control the static checker.
void makeass(node &n, const std::string &space="", std::string path="", std::string rawpath="", bool found=false)
bool file_exists(const std::string &file)
bool match(std::string s1, std::string s2)
match the individual directories of two strings
bool matchcwd(const std::string &s)
std::string description
glabal timer - how long have I taken so far?
make the histogram assessment part of the config