ATLAS Offline Software
Loading...
Searching...
No Matches
hcg.cxx File Reference
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <sys/stat.h>
#include "simpletimer.h"
#include "node.h"
#include "addnode.h"
#include "spacer.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TKey.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TProfile.h"
#include "TFile.h"
#include "TClass.h"
#include "TDirectory.h"
#include "TPad.h"
#include <algorithm>
#include "CxxUtils/checker_macros.h"

Go to the source code of this file.

Classes

class  reference
class  header
class  menu
 make the sidebar many part of the config More...
class  ass
 make the histogram assessment part of the config More...

Functions

std::string date ()
 sadly, includes a return at the end
bool file_exists (const std::string &file)
template<typename T>
std::ostream & operator<< (std::ostream &s, const std::vector< T > &v)
bool contains (const std::string &s, const std::string &regx)
 does a string contain the substring
template<typename T>
std::ostream & operator<< (std::ostream &s, const std::vector< T * > &v)
template<class T>
T * get (TKey *tobj)
 get a TObject* from a TKey* (why can't a TObject be a TKey?)
std::string find (const std::string &s)
 return a remapped string
int count (std::string s, const std::string &regx)
 count how many occurances of a regx are in a string
std::string chop (std::string &s1, const std::string &s2)
std::vector< std::string > split (const std::string &s, const std::string &t=":")
std::string chopex (std::string &s1, const std::string &s2)
std::string chomp (std::string &s1, const std::string &s2)
std::string choptoken (std::string &s1, const std::string &s2)
std::string chomptoken (std::string &s1, const std::string &s2)
std::string chopfirst (std::string &s1, const std::string &s2)
std::string choplast (std::string &s1, const std::string &s2)
std::string chopends (std::string &s1, const std::string &s2)
void removespace (std::string &s, const std::string &s2)
std::string replace (std::string s, const std::string &s2, const std::string &s3)
void depunctuate (std::string &s, const std::string &regex=":")
std::vector< std::string > maphist (const std::vector< std::string > &v)
bool match (std::string s1, std::string s2)
 match the individual directories of two strings
bool matchdir (const std::string &s)
 see whether this directory matches any of the directories we are explicitly being asked to match
bool matchcwd (const std::string &s)
std::string matchcwdstr (const std::string &s)
std::map< std::string, int >::const_iterator matchcwditr (const std::string &s)
std::ostream & operator<< (std::ostream &s, const reference &r)
void search (TDirectory *td, const std::string &s, std::string cwd, node *n)
 recursive directory search for TH1 and TH2 and TProfiles
int cost (std::vector< std::string > &files, node &n, const std::string &directory="", bool deleteref=false, bool relocate=false)
int usage (std::ostream &s, int, char **argv, int status=-1)
void referenceblock (const std::string &file)
int main (int argc, char **argv)

Variables

 ATLAS_NO_CHECK_FILE_THREAD_SAFETY
std::vector< std::string > files
 file names and file pointers
std::vector< TFile * > fptr
std::vector< std::string > savedhistos
std::vector< std::string > mapped
bool verbose = false
std::ostream * outp = &std::cout
 send output to here ...
bool allhists = true
std::string base = "HLT"
std::string outref = ""
std::string algorithm = "HLT_Histogram_Not_Empty&GatherData"
std::string description = "https://twiki.cern.ch/twiki/bin/view/Atlas/HltTrackingDataQualityMonitoring#Tier0"
 glabal timer - how long have I taken so far?
std::map< std::string, std::string > remap
 list of directories to be explicitly remapped
std::set< std::string > exclude
 list of directories to be excluded
std::map< std::string, int > dirs
 list of directories to be explicitly included, together with corresponding depths of subdirectories
std::vector< std::string > tags
std::vector< referencereferences
bool found_dir = false
std::string currentfile = ""
std::vector< std::string > refblock

Function Documentation

◆ chomp()

std::string chomp ( std::string & s1,
const std::string & s2 )

Definition at line 214 of file hcg.cxx.

215{
216 std::string::size_type pos = s1.find(s2);
217 std::string s3;
218 if ( pos == std::string::npos ) {
219 s3 = s1;
220 s1.clear();
221 }
222 else {
223 s3 = s1.substr(pos+s2.size(),s1.size());
224 s1.erase(pos,s1.size());
225 }
226 return s3;
227}

◆ chomptoken()

std::string chomptoken ( std::string & s1,
const std::string & s2 )

Definition at line 247 of file hcg.cxx.

248{
249 std::string s3 = "";
250 std::string::size_type pos = s1.find(s2);
251 if ( pos != std::string::npos ) {
252 s3 = s1.substr(pos, s1.size());
253 s1.erase(pos, s1.size());
254 }
255 return s3;
256}

◆ chop()

std::string chop ( std::string & s1,
const std::string & s2 )

Definition at line 161 of file hcg.cxx.

162{
163 std::string::size_type pos = s1.find(s2);
164 std::string s3;
165 if ( pos == std::string::npos ) {
166 s3 = s1;
167 s1.erase(0, s1.size());
168 }
169 else {
170 s3 = s1.substr(0, pos);
171 s1.erase(0, pos+s2.size());
172 }
173 return s3;
174}

◆ chopends()

std::string chopends ( std::string & s1,
const std::string & s2 )

Definition at line 290 of file hcg.cxx.

291{
292 chopfirst(s1, s2);
293 choplast(s1, s2);
294 return s1;
295}
std::string chopfirst(std::string &s1, const std::string &s2)
Definition hcg.cxx:260
std::string choplast(std::string &s1, const std::string &s2)
Definition hcg.cxx:276

◆ chopex()

std::string chopex ( std::string & s1,
const std::string & s2 )

Definition at line 197 of file hcg.cxx.

198{
199 std::string::size_type pos = s1.find(s2);
200 std::string s3;
201 if ( pos == std::string::npos ) {
202 s3 = s1;
203 s1.clear();
204 }
205 else {
206 s3 = s1.substr(0, pos);
207 s1.erase(0, pos+s2.size());
208 }
209 return s3;
210}

◆ chopfirst()

std::string chopfirst ( std::string & s1,
const std::string & s2 )

Definition at line 260 of file hcg.cxx.

261{
262 std::string s3;
263 std::string::size_type pos = s1.find_first_not_of(s2);
264 if ( pos != std::string::npos ) {
265 s3 = s1.substr(0, pos);
266 s1.erase(0, pos);
267 }
268 else {
269 s3 = s1;
270 s1.clear();
271 }
272 return s3;
273}

◆ choplast()

std::string choplast ( std::string & s1,
const std::string & s2 )

Definition at line 276 of file hcg.cxx.

277{
278 std::string s3 = "";
279 std::string::size_type pos = s1.find_last_not_of(s2);
280 if ( pos != std::string::npos ) {
281 s3 = s1.substr(pos+1, s1.size());
282 s1.erase(pos+1, s1.size());
283 }
284 return s3;
285}

◆ choptoken()

std::string choptoken ( std::string & s1,
const std::string & s2 )

Definition at line 233 of file hcg.cxx.

234{
235 std::string s3 = "";
236 std::string::size_type pos = s1.find(s2);
237 if ( pos != std::string::npos ) {
238 s3 = s1.substr(0, pos+s2.size());
239 s1.erase(0, pos+s2.size());
240 }
241 return s3;
242}

◆ contains()

bool contains ( const std::string & s,
const std::string & regx )

does a string contain the substring

Definition at line 114 of file hcg.cxx.

114{ return s.find(regx)!=std::string::npos; }

◆ cost()

int cost ( std::vector< std::string > & files,
node & n,
const std::string & directory = "",
bool deleteref = false,
bool relocate = false )

open the output file

navigate the directory structure to extracting all the info

if asked to delete the unused referenece then do so if however asked to relocate the histgrams, simply modify the list of histogram destinations first

std::cerr << "\t" << dirs[jh] << std::endl;

Definition at line 922 of file hcg.cxx.

922 {
923
924 std::cerr << "processing ..." << std::endl;
925
926 // std::cerr << "opening root files" << std::endl;
927
928 fptr.resize(files.size());
929
930
931 for ( unsigned i=0 ; i<files.size() ; i++ ) {
932
934
935 std::cerr << "opening " << currentfile << std::endl;
936
937 if ( !contains( files[i], "root://eosatlas") && !file_exists( files[i] ) ){
938 std::cerr << "file " << files[i] << " does not exist" << std::endl;
939 return -1;
940 }
941
943 fptr[i] = TFile::Open( files[i].c_str() );
944
945 if ( fptr[i]==0 || fptr[i]->IsZombie() ) {
946 std::cerr << "file " << files[i] << " cannot be opened" << std::endl;
947 return -1;
948 }
949
950 fptr[i]->cd();
951
952 if ( directory!="" ) fptr[i]->cd(directory.c_str());
953
954 TDirectory* here = gDirectory;
955
956 // global_timer = simpletimer_start();
957
958 // int tcount = 0;
959
962
963 search( gDirectory, "", "", &n );
964
965 here->cd();
966
967
971 if ( deleteref || relocate ) {
972
973 std::cerr << "remapping" << std::endl;
974
975 if ( relocate ) mapped = maphist( savedhistos );
976
977 if ( relocate && !deleteref ) std::cerr << "saving histograms to file .newhist.root ... " << std::endl;
978
979 if ( outref=="" ) outref = ".newhist.root";
980 TFile* fnew = new TFile( outref.c_str(), "recreate" );
981 fnew->cd();
982
983 TDirectory* base = gDirectory;
984
985 if ( mapped.size() != savedhistos.size() ) mapped = savedhistos;
986
987 for ( unsigned ih=0 ; ih<savedhistos.size() ; ih++ ) {
988
989 std::vector<std::string> dirs = split( mapped[ih], "/" );
990
991 for ( unsigned jh=0 ; jh<dirs.size()-1 ; jh++ ) {
993 TDirectory* renedir = gDirectory->GetDirectory( dirs[jh].c_str() );
994 if ( renedir==0 ) gDirectory->mkdir( dirs[jh].c_str() );
995 gDirectory->cd( dirs[jh].c_str() );
996 }
997
998 TH1* href = (TH1*)fptr[i]->Get( savedhistos[ih].c_str() );
999 if ( href ) {
1000 // std::cerr << ih << " " << savedhistos[ih] << " 0x" << href << std::endl;
1001 href->Write( dirs.back().c_str() );
1002 }
1003
1004 base->cd();
1005 }
1006
1007
1008 }
1009
1010 std::cerr << "closing files" << std::endl;
1011
1012 fptr[i]->Close();
1013
1014 delete fptr[i];
1015
1016 if ( deleteref ) {
1017 if ( outref==".newhist.root" ) {
1018 std::cerr << "replacing histogram file" << std::endl;
1019 std::string cmd = std::string("mv ") + files[i] + " " + files[i] + ".bak";
1020 std::system( cmd.c_str() );
1021 cmd = std::string("mv .newhist.root ") + files[i];
1022 std::system( cmd.c_str() );
1023 }
1024 }
1025
1026 }
1027
1028 return 0;
1029}
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< TFile * > fptr
Definition hcg.cxx:51
std::string outref
Definition hcg.cxx:83
std::vector< std::string > maphist(const std::vector< std::string > &v)
Definition hcg.cxx:333
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:50
std::vector< std::string > savedhistos
Definition hcg.cxx:53
std::vector< std::string > mapped
Definition hcg.cxx:54
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
Definition hcg.cxx:739
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
bool file_exists(const std::string &file)
Definition hcg.cxx:68
std::string base
Definition hcg.cxx:81
std::map< std::string, int > dirs
list of directories to be explicitly included, together with corresponding depths of subdirectories
Definition hcg.cxx:102
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
std::string currentfile
Definition hcg.cxx:734
str directory
Definition DeMoScan.py:78

◆ count()

int count ( std::string s,
const std::string & regx )

count how many occurances of a regx are in a string

Definition at line 146 of file hcg.cxx.

146 {
147 size_t p = s.find( regx );
148 int i=0;
149 while ( p!=std::string::npos ) {
150 i++;
151 s.erase( 0, p+1 );
152 p = s.find( regx );
153 }
154 return i;
155}

◆ date()

std::string date ( )

sadly, includes a return at the end

Definition at line 58 of file hcg.cxx.

58 {
59 time_t t;
60 time(&t);
61 std::string a = ctime(&t);
62 std::string b = "";
63 for ( unsigned i=0 ; i<a.size()-1 ; i++ ) b+=a[i];
64 return b;
65}
static Double_t a
time(flags, cells_name, *args, **kw)

◆ depunctuate()

void depunctuate ( std::string & s,
const std::string & regex = ":" )

Definition at line 323 of file hcg.cxx.

323 :")
324{
325 std::string::size_type pos;
326 while ( (pos = s.find(regex))!=std::string::npos ) {
327 s.erase(pos, regex.size());
328 }
329}

◆ file_exists()

bool file_exists ( const std::string & file)

Definition at line 68 of file hcg.cxx.

68 {
69 struct stat buff;
70 return stat(file.c_str(),&buff)==0;
71}
TFile * file

◆ find()

std::string find ( const std::string & s)

return a remapped string

Definition at line 138 of file hcg.cxx.

138 {
139 std::map<std::string, std::string>::const_iterator itr = remap.find(s);
140 if ( itr!=remap.end() ) return itr->second;
141 else return s;
142}
std::map< std::string, std::string > remap
list of directories to be explicitly remapped
Definition hcg.cxx:95

◆ get()

template<class T>
T * get ( TKey * tobj)

get a TObject* from a TKey* (why can't a TObject be a TKey?)

Definition at line 130 of file hcg.cxx.

130 {
131 TObject* a = tobj->ReadObj()->Clone();
132 static_cast<TH1*>(a)->SetDirectory(0);
133 return static_cast<T*>(a);
134}
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
Definition RootUtils.cxx:28

◆ main()

int main ( int argc,
char ** argv )

check some input files

create the structure ...

create the side bar menu part

create the histogram assessment part

ensure that buffer is properly flushed

Definition at line 1066 of file hcg.cxx.

1066 {
1067
1068 // std::string cock = "HLT_j150_bperf_split/InDetTrigTrackingxAODCnv_BjetPrmVtx_FTF_SuperRoi/Chain";
1069
1070 // replace
1071
1072 // std::cout << replace
1073
1074 gStyle->SetPadRightMargin(0.05);
1075 gStyle->SetPadTopMargin(0.075);
1076
1077 // TCanvas* tg = new TCanvas("tg", "tg", 650, 900 );
1078 TCanvas* tg = new TCanvas("tg", "tg", 700, 600 );
1079 tg->cd();
1080
1081 gStyle->SetStatY(0.4);
1082 // Set y-position (fraction of pad size)
1083 gStyle->SetStatX(0.89);
1084 // Set x-position (fraction of pad size)
1085 gStyle->SetStatW(0.25);
1086 // Set width of stat-box (fraction of pad size)
1087 gStyle->SetStatH(0.16);
1088
1089
1090 // if ( argc<3 ) usage( std::cerr << "not enough command options", argc, argv );
1091 if ( argc<2 ) return usage( std::cerr, argc, argv );
1092
1093
1094 for ( int i=1 ; i<argc ; i++ ) {
1095 if ( std::string(argv[i])=="-h" || std::string(argv[i])=="--help" ) return usage( *outp, argc, argv, 0 );
1096 }
1097
1098 std::string dir = "";
1099
1100 std::vector<std::string> subdirs;
1101
1102
1103 bool deleteref = false;
1104 bool relocate = false;
1105
1106 std::string outfile = "";
1107
1108 int offset = 1;
1109
1110
1111 for ( int i=1 ; i<argc ; i++ ) {
1112 if ( std::string(argv[i])=="-v" || std::string(argv[i])=="--verbose" ) verbose = true;
1113 else if ( std::string(argv[i])=="-o" ) {
1114 ++i;
1115 if ( i<argc-offset ) outfile = argv[i];
1116 else return usage( std::cerr, argc, argv );
1117 }
1118 else if ( std::string(argv[i])=="-or" || std::string(argv[i])=="--outrefr" ) {
1119 ++i;
1120 if ( i<argc-offset ) outref = argv[i];
1121 else return usage( std::cerr, argc, argv );
1122 }
1123 else if ( std::string(argv[i])=="-ref" || std::string(argv[i])=="--reference" ) {
1124 std::string reftag;
1125 std::string reffile;
1126 ++i;
1127 if ( i<argc-offset ) reftag = argv[i];
1128 else return usage( std::cerr, argc, argv );
1129 ++i;
1130 if ( i<argc-offset ) reffile = argv[i];
1131 else return usage( std::cerr, argc, argv );
1132 references.push_back( reference( reftag, reffile ) );
1133 // std::cerr << references.back() << std::endl;
1134 }
1135 else if ( std::string(argv[i])=="-rc" || std::string(argv[i])=="-refconf" ) {
1136 ++i;
1137 if ( i<argc-offset ) referenceblock( argv[i] );
1138 else return usage( std::cerr, argc, argv );
1139 }
1140 else if ( std::string(argv[i])=="-dr" || std::string(argv[i])=="--deleteref" ) deleteref = true;
1141 else if ( std::string(argv[i])=="-rh" || std::string(argv[i])=="--relocate" ) relocate = true;
1142 else if ( std::string(argv[i])=="-wc" || std::string(argv[i])=="--wildcard" ) allhists = false;
1143 else if ( std::string(argv[i])=="-d" || std::string(argv[i])=="--dir" ) {
1144 ++i;
1145
1146 if ( i<argc-offset ) {
1147 std::string stringdir(argv[i]);
1148 dirs.insert( std::map<std::string,int>::value_type( stringdir, std::count( stringdir.begin(), stringdir.end(), '/' ) ) );
1149
1150 std::string tdir = argv[i];
1151
1152 // std::cerr << "dirs " << argv[i] << std::endl;
1153
1154 do {
1155 subdirs.push_back( chop( tdir, "/" ) );
1156 // std::cerr << "chop " << subdirs.back() << std::endl;
1157 }
1158 while ( tdir.size() );
1159 }
1160 else return usage( std::cerr, argc, argv );
1161 }
1162 else if ( std::string(argv[i])=="-x" ) {
1163 ++i;
1164 if ( i<argc-offset ) exclude.insert( argv[i] );
1165 else return usage( std::cerr, argc, argv );
1166 }
1167 else if ( std::string(argv[i])=="-ds" || std::string(argv[i]).find("--desc")==0 ) {
1168 ++i;
1169 if ( i<argc-offset ) description = argv[i];
1170 else return usage( std::cerr, argc, argv );
1171 }
1172 else if ( std::string(argv[i])=="-b" || std::string(argv[i])=="--base" ) {
1173 ++i;
1174 if ( i<argc-offset ) base = argv[i] ;
1175 else return usage( std::cerr, argc, argv );
1176 }
1177 else if ( std::string(argv[i])=="-a" || std::string(argv[i])=="--algorithm" ) {
1178 ++i;
1179 if ( i<argc-offset ) algorithm = argv[i] ;
1180 else return usage( std::cerr, argc, argv );
1181 }
1182 // else if ( std::string(argv[i])=="-o" ) {
1183 // ++i;
1184 // if ( i<argc ) output_file = argv[i];
1185 // else return usage( std::cerr, argc, argv );
1186 // }
1187 else if ( std::string(argv[i])=="-t" || std::string(argv[i])=="--tag" ) {
1188 ++i;
1189 if ( i<argc-offset ) tags.push_back( argv[i] );
1190 else return usage( std::cerr, argc, argv );
1191 }
1192 else if ( std::string(argv[i])=="-r" ) {
1193 std::string src;
1194 std::string dest;
1195 if ( i<argc+2-offset ) {
1196 src = argv[++i];
1197 dest = argv[++i];
1198 remap.insert( std::map<std::string,std::string>::value_type( src, dest ) );
1199 } else return usage( std::cerr, argc, argv );
1200 }
1201 else {
1202 offset = 0;
1203 files.push_back(argv[i]);
1204 }
1205 }
1206
1207
1208 if ( base == "" ) base = std::move(dir);
1209
1210
1212
1213 if ( files.size()<1 ) return usage( std::cerr, argc, argv );
1214
1215
1216 // time the actual running of the cost() routine
1217
1218 if ( verbose ) std::cerr << "timing" << std::endl;
1219
1220 struct timeval tv = simpletimer_start();
1221
1223
1224 node n(0, "" );
1225 n.name( "top_level" );
1226
1227 int status = cost( files, n, "", deleteref, relocate );
1228
1229 // std::cerr << "\n\nnodes " << n << std::endl;
1230
1231 if ( status ) return status;
1232
1233 if ( outfile!="" ) outp = new std::ofstream(outfile.c_str());
1234
1235 header h;
1236
1237 for ( unsigned ir=0 ; ir<references.size() ; ir++ ) (*outp) << references[ir] << std::endl;
1238
1239 if ( refblock.size() ) (*outp) << refblock << std::endl;
1240
1242 menu m( n );
1243
1245 ass( n, allhists );
1246
1248 (*outp) << std::endl;
1249
1250 double t = simpletimer_stop(tv);
1251
1252 if ( t>1000 ) std::cerr << "total time " << t*0.001 << " s" << std::endl;
1253 else std::cerr << "total time " << t << " ms" << std::endl;
1254
1255 return 0;
1256}
struct timeval simpletimer_start(void)
double simpletimer_stop(const struct timeval &start_time)
Header file for AthHistogramAlgorithm.
make the histogram assessment part of the config
Definition hcg.cxx:627
make the sidebar many part of the config
Definition hcg.cxx:552
Definition node.h:24
int ir
counter of the current depth
Definition fastadd.cxx:49
StatusCode usage()
bool allhists
Definition hcg.cxx:79
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91
std::vector< std::string > tags
Definition hcg.cxx:105
void referenceblock(const std::string &file)
Definition hcg.cxx:1060
std::vector< reference > references
Definition hcg.cxx:523
std::ostream * outp
send output to here ...
Definition hcg.cxx:76
int cost(std::vector< std::string > &files, node &n, const std::string &directory="", bool deleteref=false, bool relocate=false)
Definition hcg.cxx:922
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
std::set< std::string > exclude
list of directories to be excluded
Definition hcg.cxx:98
std::string algorithm
Definition hcg.cxx:85
bool verbose
Definition hcg.cxx:73
std::vector< std::string > refblock
Definition hcg.cxx:1058
std::string chop(std::string &s1, const std::string &s2)
Definition hcg.cxx:161
status
Definition merge.py:16

◆ maphist()

std::vector< std::string > maphist ( const std::vector< std::string > & v)

Definition at line 333 of file hcg.cxx.

333 {
334 mapped.clear();
335 for ( unsigned i=0 ; i<v.size() ; i++ ) {
336 if ( contains( v[i], "Expert" ) ){
337 std::string tmp = v[i];
338 std::string path = chop( tmp, "Expert/" );
339 path += "Chains/";
340 tmp = replace( tmp, "/", "__" );
341 path += tmp;
342 mapped.push_back( std::move(path) );
343 }
344 else {
345 mapped.push_back( v[i] );
346 }
347 }
348
349 return mapped;
350}
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310
path
python interpreter configuration --------------------------------------—
Definition athena.py:128

◆ match()

bool match ( std::string s1,
std::string s2 )

match the individual directories of two strings

Definition at line 357 of file hcg.cxx.

357 {
358
359 int i1 = std::count( s1.begin(), s1.end(), '/' );
360 int i2 = std::count( s2.begin(), s2.end(), '/' );
361
362 int i = ( i1<i2 ? i1 : i2 );
363
364 // std::cerr << "match s1 " << s1 << " " << s2 << std::endl;
365
366 for ( i++ ; i-- ; ) {
367 size_t p1 = s1.find('/');
368 size_t p2 = s2.find('/');
369
370 std::string ss1 = s1.substr( 0, p1 );
371 std::string ss2 = s2.substr( 0, p2 );
372
373 s1.erase( 0, p1+1 );
374 s2.erase( 0, p2+1 );
375
376 // std::cerr << i << "\tmatch :" << ss1 << ":" << ss2 << "::\t " << s1 << ":" << s2 << "\tresult " << (ss1!=ss2 ) << std::endl;
377
378 if ( ss1!=ss2 ) return false;
379
380 }
381
382 return true;
383
384}

◆ matchcwd()

bool matchcwd ( const std::string & s)

Definition at line 403 of file hcg.cxx.

403 {
404 if ( dirs.size()==0 ) return true;
405 std::map<std::string,int>::const_iterator itr = dirs.begin();
406 while ( itr!=dirs.end() ) {
407 if ( s.find(itr->first)!=std::string::npos ) return true;
408 ++itr;
409 }
410 return false;
411}

◆ matchcwditr()

std::map< std::string, int >::const_iterator matchcwditr ( const std::string & s)

Definition at line 426 of file hcg.cxx.

426 {
427 if ( dirs.size()==0 ) return dirs.end();
428 std::map<std::string,int>::const_iterator itr = dirs.begin();
429 while ( itr!=dirs.end() ) {
430 if ( s.find(itr->first)!=std::string::npos ) return itr;
431 ++itr;
432 }
433 return dirs.end();
434}

◆ matchcwdstr()

std::string matchcwdstr ( const std::string & s)

Definition at line 415 of file hcg.cxx.

415 {
416 if ( dirs.size()==0 ) return "";
417 std::map<std::string,int>::const_iterator itr = dirs.begin();
418 while ( itr!=dirs.end() ) {
419 if ( s.find(itr->first)!=std::string::npos ) return itr->first;
420 ++itr;
421 }
422 return "";
423}

◆ matchdir()

bool matchdir ( const std::string & s)

see whether this directory matches any of the directories we are explicitly being asked to match

Definition at line 390 of file hcg.cxx.

390 {
391 bool matched = false;
392 // int idepth = count( s, "/" );
393 std::map<std::string,int>::const_iterator itr = dirs.begin();
394 while ( itr!=dirs.end() ) {
395 if ( match( s, itr->first) ) matched = true;
396 // std::cerr << "\tmatchdir :" << s << "::" << itr->first << ": " << itr->second << std::endl;
397 if ( matched ) return true;
398 ++itr;
399 }
400 return false;
401}
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357

◆ operator<<() [1/3]

std::ostream & operator<< ( std::ostream & s,
const reference & r )

Definition at line 505 of file hcg.cxx.

505 {
506 static bool first = true;
507 if ( first ) {
508 s << "##########################\n";
509 s << "# References\n";
510 s << "##########################\n\n";
511 first = false;
512 }
513 s << "reference " << r.name() << " {\n";
514 s << "\t\tfile = " << r.file() << "\n";
515 s << "\t\tpath = run_" << r.run() << "\n";
516 s << "\t\tname = same_name" << "\n";
517 s << "}\n\n";
518 return s;
519}
int r
Definition globals.cxx:22
bool first
Definition DeMoScan.py:534

◆ operator<<() [2/3]

template<typename T>
std::ostream & operator<< ( std::ostream & s,
const std::vector< T * > & v )

Definition at line 119 of file hcg.cxx.

119 {
120 if ( v.empty() ) return s;
121 for ( int i=0 ; i<v.size() ; i++ ) s << *v[i] << "\n";
122 return s;
123}

◆ operator<<() [3/3]

template<typename T>
std::ostream & operator<< ( std::ostream & s,
const std::vector< T > & v )

Definition at line 108 of file hcg.cxx.

108 {
109 if ( v.empty() ) return s;
110 for ( size_t i=0 ; i<v.size() ; i++ ) s << v[i] << "\n";
111 return s;
112}

◆ referenceblock()

void referenceblock ( const std::string & file)

Definition at line 1060 of file hcg.cxx.

1060 {
1061 std::ifstream strm(file.c_str());
1062 for ( std::string line ; getline( strm, line ); ) refblock.push_back( line );
1063}

◆ removespace()

void removespace ( std::string & s,
const std::string & s2 )

Definition at line 300 of file hcg.cxx.

301{
302 std::string::size_type pos;
303 while ( (pos = s.find(s2))!=std::string::npos ) {
304 s.erase(pos, s2.size());
305 }
306}

◆ replace()

std::string replace ( std::string s,
const std::string & s2,
const std::string & s3 )

Definition at line 310 of file hcg.cxx.

310 {
311 std::string::size_type pos;
312 // while ( (pos = s.find(" "))!=std::string::npos ) {
313 // s.replace(pos, 1, "-");
314 while ( (pos = s.find(s2))!=std::string::npos ) {
315 s.replace(pos, s2.size(), s3);
316 if ( contains(s3,s2) ) break;
317 }
318 return s;
319}

◆ search()

void search ( TDirectory * td,
const std::string & s,
std::string cwd,
node * n )

recursive directory search for TH1 and TH2 and TProfiles

not a directory

don't go more than 10 directories deep

go through sub directories

descend into the subdirectory ...

if this is a directory we want, print (*outp) the histograms

get the full path to this object path relative to the file

save the histograms in case we need to save the, later ...

keep the max number of entries updated

Definition at line 739 of file hcg.cxx.

739 {
740
742 if ( td==0 ) return;
743
744 if ( std::string(td->GetName()).find("_LB")!=std::string::npos ) return;
745 if ( std::string(td->GetName()).find("lb_")!=std::string::npos ) return;
746
747 // std::cout << "search() in " << s << td->GetName() << ": :" << cwd << ":" << std::endl;
748
749 static int ir = 0;
750
751 ir++;
752
754
755 if ( ir>10 ) {
756 std::cerr << "search() WARNING too many levels of directories (max 10) !!!\n";
757 return;
758 }
759
760
761 TDirectory* here = gDirectory;
762
763 // gDirectory->pwd();
764
765 td->cd();
766
767 if ( cwd!="" ) cwd += "/";
768 cwd += td->GetName();
769
770 node* np = n;
771
772 std::string fulldir = td->GetName();
773
774
775 bool first_found = false;
776 if ( !found_dir && matchcwd( cwd ) ) {
777
778 std::string ase = matchcwdstr( cwd );
779
780 if ( (cwd+"/").find( ase+"/" )!=std::string::npos ) {
781
782 found_dir = true;
783 first_found = true;
784
785 std::cerr << "matched dirs " << cwd << " " << matchdir( cwd ) << std::endl;
786
787
788 std::map<std::string,int>::const_iterator fitr = matchcwditr( cwd );
789
790 if ( fitr!=dirs.end() ) {
791
792 if ( fitr->second>0 ) {
793
794 std::vector<std::string> subpath;
795
796 std::string sp = fitr->first;
797
798 while( sp.size() ) subpath.push_back( chop(sp,"/") );
799
800 for ( unsigned ip=0 ; ip<subpath.size()-1 ; ip++ ) {
801 // std::cerr << "subpath " << ip << " " << subpath[ip] << std::endl;
802
803 node* np_ = addnode( np, subpath[ip] );
804
805 np = np_;
806
807 }
808 }
809 }
810
811 }
812 }
813
814
815 if ( found_dir ) {
816 node* np_ = addnode( np, fulldir, td );
817 np = np_;
818 }
819
820 if ( found_dir && verbose ) std::cerr << s << cwd << std::endl;
821
822
823 TList* tl = gDirectory->GetListOfKeys();
824
825 // struct timeval tv = simpletimer_start();
826
827 // (*outp) << "\ttl " << tl << std::endl;
828
830
831 for ( int i=0 ; i<tl->GetSize() ; i++ ) {
832
833 TKey* tobj = (TKey*)tl->At(i);
834
835 if ( tobj==0 ) continue;
836
837 // (*outp) << "tobj " << tobj;
838 // if ( tobj ) (*outp) << " : \t" << tobj->GetName();
839 // (*outp) << std::endl;
840
841 if ( std::string(tobj->GetClassName()).find("TDirectory")!=std::string::npos ) {
842 // (*outp) << ns << "Directory " << tobj->GetName() << std::endl;
843
844 TDirectory* tnd = (TDirectory*)tobj->ReadObj();
845
846
848 if ( tnd ) search( tnd, s+spacer, cwd, np );
849
850 }
851 else {
852
854
855 if ( found_dir ) {
856 if ( std::string(tobj->GetClassName()).find("TH1")!=std::string::npos ||
857 std::string(tobj->GetClassName()).find("TH2")!=std::string::npos ||
858 std::string(tobj->GetClassName()).find("TProfile")!=std::string::npos ) {
859
860 // TH1* th = (TH1*)tobj->ReadObj();
861
862 // node* h = addnode( np, "", get<TObject>(tobj), node::HISTOGRAM );
863 // node* h =
864 addnode( np, tobj->GetName(), get<TObject>(tobj), node::HISTOGRAM );
865
866
868 std::string subdir = cwd;
869 chop( subdir, currentfile+"/" );
870
872 savedhistos.push_back( subdir+"/"+tobj->GetName() );
873
875 if ( std::string(tobj->GetName())=="Chain" ) {
876 double N = static_cast<TH1*>(get<TObject>(tobj))->GetEntries();
877
878 // std::cout << "entries " << np->name() << " " << " " << np->parent()->name() << " " << N << std::endl;
879 // std::cout << "\tentries " << np->parent()->name() << "/" << np->name() << "\t" << N << std::endl;
880 std::cout << "\t" << subdir << "\t" << N << std::endl;
881
882 node* p = np->parent();
883 if ( p && p->name()!="Shifter" ) {
884
885 p->addrate( p->name(), N );
886
887 node* p2 = p->parent();
888 if ( p2 ) p2->addrate( p->name(), N );
889 }
890 }
891
892 }
893
894 // if ( !status ) std::cerr << "bad status" << std::endl;
895 }
896 }
897
898 }
899
900
901 // double _t = simpletimer_stop(tv);
902
903 // double global_time = simpletimer_stop(global_timer);
904
905 ir--;
906
907 here->cd();
908
909 if ( first_found ) found_dir = false;
910
911}
static Double_t sp
TGraphErrors * GetEntries(TH2F *histo)
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
Definition addnode.cxx:28
@ HISTOGRAM
Definition node.h:28
bool matchcwd(const std::string &s)
Definition hcg.cxx:403
bool matchdir(const std::string &s)
see whether this directory matches any of the directories we are explicitly being asked to match
Definition hcg.cxx:390
bool found_dir
Definition hcg.cxx:732
std::map< std::string, int >::const_iterator matchcwditr(const std::string &s)
Definition hcg.cxx:426
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
std::string matchcwdstr(const std::string &s)
Definition hcg.cxx:415
std::string cwd
Definition listroot.cxx:38
const std::string spacer
Definition spacer.h:27

◆ split()

std::vector< std::string > split ( const std::string & s,
const std::string & t = ":" )

Definition at line 177 of file hcg.cxx.

177 :" ) {
178
179 std::string s2 = s;
180 size_t pos = s2.find(t);
181
182 std::vector<std::string> tags;
183
184 while ( pos!=std::string::npos ) {
185 tags.push_back( chop(s2,t) );
186 pos = s2.find(t);
187 }
188
189 tags.push_back(std::move(s2));
190
191 return tags;
192}

◆ usage()

int usage ( std::ostream & s,
int ,
char ** argv,
int status = -1 )

Definition at line 1035 of file hcg.cxx.

1035 {
1036 s << "Usage: " << argv[0] << " [OPTIONS] input1.root ... inputN.root\n\n";
1037 s << " -o FILENAME \tname of output (filename required)\n";
1038 s << " -b, --base DIR \tuse directory DIR as the base for the han config\n";
1039 s << " -d, --dir DIR \tonly directories below DIR where DIR is a structure such as HLT/TRIDT etc\n";
1040 s << " -x, DIR \texclude directory DIR\n";
1041 s << " -r SRC DST \tremap directory SRC to directory DST\n";
1042 s << " -ds, --desc DESCRIP \tuse DESCRIP as the description\n";
1043 s << " -t, --tag VALUE \tadd the VALUE to the list of command per histogram\n";
1044 s << " -a, --algorithm VALUE \tuse VALUE as the execution algorithm for each histogram\n";
1045 s << " -wc, --wildcard \tprint use hist * rather than a separate entry for each histogram\n";
1046 s << " -dr, --deleteref \tdelete unselected histograms\n";
1047 s << " -or, --outref FILENAME \tdelete file to write reduced output to (overwrites input otherwise) \n";
1048 s << " -rh, --relocate \trelocate selected histograms\n";
1049 s << " -ref, --reference TAG FILE \tadd FILE as a reference file with tag TAG\n";
1050 s << " -rc, --refconf FILE \tadd FILE to the config as a reference block\n";
1051 s << " -v, --verbose \tprint verbose output\n";
1052 s << " -h, --help \tdisplay this help\n";
1053 s << std::endl;
1054 return status;
1055}

Variable Documentation

◆ algorithm

std::string algorithm = "HLT_Histogram_Not_Empty&GatherData"

Definition at line 85 of file hcg.cxx.

◆ allhists

bool allhists = true

Definition at line 79 of file hcg.cxx.

◆ ATLAS_NO_CHECK_FILE_THREAD_SAFETY

ATLAS_NO_CHECK_FILE_THREAD_SAFETY

Definition at line 47 of file hcg.cxx.

◆ base

std::string base = "HLT"

Definition at line 81 of file hcg.cxx.

◆ currentfile

std::string currentfile = ""

Definition at line 734 of file hcg.cxx.

◆ description

std::string description = "https://twiki.cern.ch/twiki/bin/view/Atlas/HltTrackingDataQualityMonitoring#Tier0"

glabal timer - how long have I taken so far?

Definition at line 91 of file hcg.cxx.

◆ dirs

std::map<std::string, int> dirs

list of directories to be explicitly included, together with corresponding depths of subdirectories

Definition at line 102 of file hcg.cxx.

◆ exclude

std::set<std::string> exclude

list of directories to be excluded

Definition at line 98 of file hcg.cxx.

◆ files

std::vector<std::string> files

file names and file pointers

Definition at line 50 of file hcg.cxx.

◆ found_dir

bool found_dir = false

Definition at line 732 of file hcg.cxx.

◆ fptr

std::vector<TFile*> fptr

Definition at line 51 of file hcg.cxx.

◆ mapped

std::vector<std::string> mapped

Definition at line 54 of file hcg.cxx.

◆ outp

std::ostream* outp = &std::cout

send output to here ...

Definition at line 76 of file hcg.cxx.

◆ outref

std::string outref = ""

Definition at line 83 of file hcg.cxx.

◆ refblock

std::vector<std::string> refblock

Definition at line 1058 of file hcg.cxx.

◆ references

std::vector<reference> references

Definition at line 523 of file hcg.cxx.

◆ remap

std::map<std::string, std::string> remap

list of directories to be explicitly remapped

Definition at line 95 of file hcg.cxx.

◆ savedhistos

std::vector<std::string> savedhistos

Definition at line 53 of file hcg.cxx.

◆ tags

std::vector<std::string> tags

Definition at line 105 of file hcg.cxx.

◆ verbose

bool verbose = false

Definition at line 73 of file hcg.cxx.