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

static const std::string delimiter ("/")
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 216 of file hcg.cxx.

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

◆ chomptoken()

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

Definition at line 249 of file hcg.cxx.

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

◆ chop()

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

Definition at line 163 of file hcg.cxx.

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

◆ chopends()

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

Definition at line 292 of file hcg.cxx.

293{
294 chopfirst(s1, s2);
295 choplast(s1, s2);
296 return s1;
297}
std::string chopfirst(std::string &s1, const std::string &s2)
Definition hcg.cxx:262
std::string choplast(std::string &s1, const std::string &s2)
Definition hcg.cxx:278

◆ chopex()

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

Definition at line 199 of file hcg.cxx.

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

◆ chopfirst()

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

Definition at line 262 of file hcg.cxx.

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

◆ choplast()

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

Definition at line 278 of file hcg.cxx.

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

◆ choptoken()

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

Definition at line 235 of file hcg.cxx.

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

◆ contains()

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

does a string contain the substring

Definition at line 116 of file hcg.cxx.

116{ 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 926 of file hcg.cxx.

926 {
927
928 std::cerr << "processing ..." << std::endl;
929
930 // std::cerr << "opening root files" << std::endl;
931
932 fptr.resize(files.size());
933
934
935 for ( unsigned i=0 ; i<files.size() ; i++ ) {
936
938
939 std::cerr << "opening " << currentfile << std::endl;
940
941 if ( !contains( files[i], "root://eosatlas") && !file_exists( files[i] ) ){
942 std::cerr << "file " << files[i] << " does not exist" << std::endl;
943 return -1;
944 }
945
947 fptr[i] = TFile::Open( files[i].c_str() );
948
949 if ( fptr[i]==0 || fptr[i]->IsZombie() ) {
950 std::cerr << "file " << files[i] << " cannot be opened" << std::endl;
951 return -1;
952 }
953
954 fptr[i]->cd();
955
956 if ( directory!="" ) fptr[i]->cd(directory.c_str());
957
958 TDirectory* here = gDirectory;
959
960 // global_timer = simpletimer_start();
961
962 // int tcount = 0;
963
966
967 search( gDirectory, "", "", &n );
968
969 here->cd();
970
971
975 if ( deleteref || relocate ) {
976
977 std::cerr << "remapping" << std::endl;
978
979 if ( relocate ) mapped = maphist( savedhistos );
980
981 if ( relocate && !deleteref ) std::cerr << "saving histograms to file .newhist.root ... " << std::endl;
982
983 if ( outref=="" ) outref = ".newhist.root";
984 TFile* fnew = new TFile( outref.c_str(), "recreate" );
985 fnew->cd();
986
987 TDirectory* base = gDirectory;
988
989 if ( mapped.size() != savedhistos.size() ) mapped = savedhistos;
990
991 for ( unsigned ih=0 ; ih<savedhistos.size() ; ih++ ) {
992
993 std::vector<std::string> dirs = split( mapped[ih], delimiter );
994
995 for ( unsigned jh=0 ; jh<dirs.size()-1 ; jh++ ) {
997 TDirectory* renedir = gDirectory->GetDirectory( dirs[jh].c_str() );
998 if ( renedir==0 ) gDirectory->mkdir( dirs[jh].c_str() );
999 gDirectory->cd( dirs[jh].c_str() );
1000 }
1001
1002 TH1* href = (TH1*)fptr[i]->Get( savedhistos[ih].c_str() );
1003 if ( href ) {
1004 // std::cerr << ih << " " << savedhistos[ih] << " 0x" << href << std::endl;
1005 href->Write( dirs.back().c_str() );
1006 }
1007
1008 base->cd();
1009 }
1010
1011
1012 }
1013
1014 std::cerr << "closing files" << std::endl;
1015
1016 fptr[i]->Close();
1017
1018 delete fptr[i];
1019
1020 if ( deleteref ) {
1021 if ( outref==".newhist.root" ) {
1022 std::cerr << "replacing histogram file" << std::endl;
1023 std::string cmd = std::string("mv ") + files[i] + " " + files[i] + ".bak";
1024 std::system( cmd.c_str() );
1025 cmd = std::string("mv .newhist.root ") + files[i];
1026 std::system( cmd.c_str() );
1027 }
1028 }
1029
1030 }
1031
1032 return 0;
1033}
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:53
std::string outref
Definition hcg.cxx:85
std::vector< std::string > maphist(const std::vector< std::string > &v)
Definition hcg.cxx:335
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:52
std::vector< std::string > savedhistos
Definition hcg.cxx:55
std::vector< std::string > mapped
Definition hcg.cxx:56
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:743
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
bool file_exists(const std::string &file)
Definition hcg.cxx:70
static const std::string delimiter("/")
std::string base
Definition hcg.cxx:83
std::map< std::string, int > dirs
list of directories to be explicitly included, together with corresponding depths of subdirectories
Definition hcg.cxx:104
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179
std::string currentfile
Definition hcg.cxx:738
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 148 of file hcg.cxx.

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

◆ date()

std::string date ( )

sadly, includes a return at the end

Definition at line 60 of file hcg.cxx.

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

◆ delimiter()

const std::string delimiter ( "/" )
static

◆ depunctuate()

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

Definition at line 325 of file hcg.cxx.

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

◆ file_exists()

bool file_exists ( const std::string & file)

Definition at line 70 of file hcg.cxx.

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

◆ find()

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

return a remapped string

Definition at line 140 of file hcg.cxx.

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

◆ 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 132 of file hcg.cxx.

132 {
133 TObject* a = tobj->ReadObj()->Clone();
134 static_cast<TH1*>(a)->SetDirectory(0);
135 return static_cast<T*>(a);
136}
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 1070 of file hcg.cxx.

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

◆ maphist()

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

Definition at line 335 of file hcg.cxx.

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

◆ match()

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

match the individual directories of two strings

Definition at line 359 of file hcg.cxx.

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

◆ matchcwd()

bool matchcwd ( const std::string & s)

Definition at line 405 of file hcg.cxx.

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

◆ matchcwditr()

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

Definition at line 428 of file hcg.cxx.

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

◆ matchcwdstr()

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

Definition at line 417 of file hcg.cxx.

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

◆ 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 392 of file hcg.cxx.

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

◆ operator<<() [1/3]

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

Definition at line 507 of file hcg.cxx.

507 {
508 static bool first = true;
509 if ( first ) {
510 s << "##########################\n";
511 s << "# References\n";
512 s << "##########################\n\n";
513 first = false;
514 }
515 s << "reference " << r.name() << " {\n";
516 s << "\t\tfile = " << r.file() << "\n";
517 s << "\t\tpath = run_" << r.run() << "\n";
518 s << "\t\tname = same_name" << "\n";
519 s << "}\n\n";
520 return s;
521}
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 121 of file hcg.cxx.

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

◆ operator<<() [3/3]

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

Definition at line 110 of file hcg.cxx.

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

◆ referenceblock()

void referenceblock ( const std::string & file)

Definition at line 1064 of file hcg.cxx.

1064 {
1065 std::ifstream strm(file.c_str());
1066 for ( std::string line ; getline( strm, line ); ) refblock.push_back( line );
1067}

◆ removespace()

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

Definition at line 302 of file hcg.cxx.

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

◆ replace()

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

Definition at line 312 of file hcg.cxx.

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

◆ 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 743 of file hcg.cxx.

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

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

◆ usage()

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

Definition at line 1039 of file hcg.cxx.

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

Variable Documentation

◆ algorithm

std::string algorithm = "HLT_Histogram_Not_Empty&GatherData"

Definition at line 87 of file hcg.cxx.

◆ allhists

bool allhists = true

Definition at line 81 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 83 of file hcg.cxx.

◆ currentfile

std::string currentfile = ""

Definition at line 738 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 93 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 104 of file hcg.cxx.

◆ exclude

std::set<std::string> exclude

list of directories to be excluded

Definition at line 100 of file hcg.cxx.

◆ files

std::vector<std::string> files

file names and file pointers

Definition at line 52 of file hcg.cxx.

◆ found_dir

bool found_dir = false

Definition at line 736 of file hcg.cxx.

◆ fptr

std::vector<TFile*> fptr

Definition at line 53 of file hcg.cxx.

◆ mapped

std::vector<std::string> mapped

Definition at line 56 of file hcg.cxx.

◆ outp

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

send output to here ...

Definition at line 78 of file hcg.cxx.

◆ outref

std::string outref = ""

Definition at line 85 of file hcg.cxx.

◆ refblock

std::vector<std::string> refblock

Definition at line 1062 of file hcg.cxx.

◆ references

std::vector<reference> references

Definition at line 525 of file hcg.cxx.

◆ remap

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

list of directories to be explicitly remapped

Definition at line 97 of file hcg.cxx.

◆ savedhistos

std::vector<std::string> savedhistos

Definition at line 55 of file hcg.cxx.

◆ tags

std::vector<std::string> tags

Definition at line 107 of file hcg.cxx.

◆ verbose

bool verbose = false

Definition at line 75 of file hcg.cxx.