ATLAS Offline Software
Classes | Functions | Variables
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 More...
 
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 More...
 
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?) More...
 
std::string find (const std::string &s)
 return a remapped string More...
 
int count (std::string s, const std::string &regx)
 count how many occurances of a regx are in a string More...
 
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 More...
 
bool matchdir (const std::string &s)
 see whether this directory matches any of the directories we are explicitly being asked to match More...
 
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 More...
 
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 More...
 
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 ... More...
 
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? More...
 
std::map< std::string, std::string > remap
 list of directories to be explicitly remapped More...
 
std::set< std::string > exclude
 list of directories to be excluded More...
 
std::map< std::string, int > dirs
 list of directories to be explicitly included, together with corresponding depths of subdirectories More...
 
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 211 of file hcg.cxx.

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

◆ chomptoken()

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

Definition at line 244 of file hcg.cxx.

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

◆ chop()

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

Definition at line 158 of file hcg.cxx.

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

◆ chopends()

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

Definition at line 287 of file hcg.cxx.

288 {
289  chopfirst(s1, s2);
290  choplast(s1, s2);
291  return s1;
292 }

◆ chopex()

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

Definition at line 194 of file hcg.cxx.

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

◆ chopfirst()

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

Definition at line 257 of file hcg.cxx.

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

◆ choplast()

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

Definition at line 273 of file hcg.cxx.

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

◆ choptoken()

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

Definition at line 230 of file hcg.cxx.

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

◆ contains()

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

does a string contain the substring

Definition at line 111 of file hcg.cxx.

111 { 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 921 of file hcg.cxx.

921  {
922 
923  std::cerr << "processing ..." << std::endl;
924 
925  // std::cerr << "opening root files" << std::endl;
926 
927  fptr.resize(files.size());
928 
929 
930  for ( unsigned i=0 ; i<files.size() ; i++ ) {
931 
932  currentfile = files[i];
933 
934  std::cerr << "opening " << currentfile << std::endl;
935 
936  if ( !contains( files[i], "root://eosatlas") && !file_exists( files[i] ) ){
937  std::cerr << "file " << files[i] << " does not exist" << std::endl;
938  return -1;
939  }
940 
942  fptr[i] = TFile::Open( files[i].c_str() );
943 
944  if ( fptr[i]==0 || fptr[i]->IsZombie() ) {
945  std::cerr << "file " << files[i] << " cannot be opened" << std::endl;
946  return -1;
947  }
948 
949  fptr[i]->cd();
950 
951  if ( directory!="" ) fptr[i]->cd(directory.c_str());
952 
953  TDirectory* here = gDirectory;
954 
955  // global_timer = simpletimer_start();
956 
957  // int tcount = 0;
958 
961 
962  search( gDirectory, "", "", &n );
963 
964  here->cd();
965 
966 
970  if ( deleteref || relocate ) {
971 
972  std::cerr << "remapping" << std::endl;
973 
974  if ( relocate ) mapped = maphist( savedhistos );
975 
976  if ( relocate && !deleteref ) std::cerr << "saving histograms to file .newhist.root ... " << std::endl;
977 
978  if ( outref=="" ) outref = ".newhist.root";
979  TFile* fnew = new TFile( outref.c_str(), "recreate" );
980  fnew->cd();
981 
982  TDirectory* base = gDirectory;
983 
984  if ( mapped.size() != savedhistos.size() ) mapped = savedhistos;
985 
986  for ( unsigned ih=0 ; ih<savedhistos.size() ; ih++ ) {
987 
988  std::vector<std::string> dirs = split( mapped[ih], "/" );
989 
990  for ( unsigned jh=0 ; jh<dirs.size()-1 ; jh++ ) {
992  TDirectory* renedir = gDirectory->GetDirectory( dirs[jh].c_str() );
993  if ( renedir==0 ) gDirectory->mkdir( dirs[jh].c_str() );
994  gDirectory->cd( dirs[jh].c_str() );
995  }
996 
997  TH1* href = (TH1*)fptr[i]->Get( savedhistos[ih].c_str() );
998  if ( href ) {
999  // std::cerr << ih << " " << savedhistos[ih] << " 0x" << href << std::endl;
1000  href->Write( dirs.back().c_str() );
1001  }
1002 
1003  base->cd();
1004  }
1005 
1006 
1007  }
1008 
1009  std::cerr << "closing files" << std::endl;
1010 
1011  fptr[i]->Close();
1012 
1013  delete fptr[i];
1014 
1015  if ( deleteref ) {
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() );
1022  }
1023  }
1024 
1025  }
1026 
1027  return 0;
1028 }

◆ count()

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

count how many occurances of a regx are in a string

Definition at line 143 of file hcg.cxx.

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

◆ date()

std::string date ( )

sadly, includes a return at the end

Definition at line 55 of file hcg.cxx.

55  {
56  time_t t;
57  time(&t);
58  std::string a = ctime(&t);
59  std::string b = "";
60  for ( unsigned i=0 ; i<a.size()-1 ; i++ ) b+=a[i];
61  return b;
62 }

◆ depunctuate()

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

Definition at line 320 of file hcg.cxx.

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

◆ file_exists()

bool file_exists ( const std::string &  file)

Definition at line 65 of file hcg.cxx.

65  {
66  struct stat buff;
67  return stat(file.c_str(),&buff)==0;
68 }

◆ find()

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

return a remapped string

Definition at line 135 of file hcg.cxx.

135  {
136  std::map<std::string, std::string>::const_iterator itr = remap.find(s);
137  if ( itr!=remap.end() ) return itr->second;
138  else return s;
139 }

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

127  {
128  TObject* a = tobj->ReadObj()->Clone();
129  ((TH1*)a)->SetDirectory(0);
130  return (T*)a;
131 }

◆ main()

int main ( int  argc,
char **  argv 
)

if output file is not defined

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

1065  {
1066 
1067  // std::string cock = "HLT_j150_bperf_split/InDetTrigTrackingxAODCnv_BjetPrmVtx_FTF_SuperRoi/Chain";
1068 
1069  // replace
1070 
1071  // std::cout << replace
1072 
1073  gStyle->SetPadRightMargin(0.05);
1074  gStyle->SetPadTopMargin(0.075);
1075 
1076  // TCanvas* tg = new TCanvas("tg", "tg", 650, 900 );
1077  TCanvas* tg = new TCanvas("tg", "tg", 700, 600 );
1078  tg->cd();
1079 
1080  gStyle->SetStatY(0.4);
1081  // Set y-position (fraction of pad size)
1082  gStyle->SetStatX(0.89);
1083  // Set x-position (fraction of pad size)
1084  gStyle->SetStatW(0.25);
1085  // Set width of stat-box (fraction of pad size)
1086  gStyle->SetStatH(0.16);
1087 
1088 
1089  // if ( argc<3 ) usage( std::cerr << "not enough command options", argc, argv );
1090  if ( argc<2 ) return usage( std::cerr, argc, argv );
1091 
1092 
1093  for ( int i=1 ; i<argc ; i++ ) {
1094  if ( std::string(argv[i])=="-h" || std::string(argv[i])=="--help" ) return usage( *outp, argc, argv, 0 );
1095  }
1096 
1097  std::string dir = "";
1098 
1099  std::vector<std::string> subdirs;
1100 
1101 
1102  bool deleteref = false;
1103  bool relocate = false;
1104 
1105  std::string outfile = "";
1106 
1107  int offset = 1;
1108 
1109 
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" ) {
1113  ++i;
1114  if ( i<argc-offset ) outfile = argv[i];
1115  else return usage( std::cerr, argc, argv );
1116  }
1117  else if ( std::string(argv[i])=="-or" || std::string(argv[i])=="--outrefr" ) {
1118  ++i;
1119  if ( i<argc-offset ) outref = argv[i];
1120  else return usage( std::cerr, argc, argv );
1121  }
1122  else if ( std::string(argv[i])=="-ref" || std::string(argv[i])=="--reference" ) {
1123  std::string reftag;
1124  std::string reffile;
1125  ++i;
1126  if ( i<argc-offset ) reftag = argv[i];
1127  else return usage( std::cerr, argc, argv );
1128  ++i;
1129  if ( i<argc-offset ) reffile = argv[i];
1130  else return usage( std::cerr, argc, argv );
1131  references.push_back( reference( reftag, reffile ) );
1132  // std::cerr << references.back() << std::endl;
1133  }
1134  else if ( std::string(argv[i])=="-rc" || std::string(argv[i])=="-refconf" ) {
1135  ++i;
1136  if ( i<argc-offset ) referenceblock( argv[i] );
1137  else return usage( std::cerr, argc, argv );
1138  }
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" ) {
1143  ++i;
1144 
1145  if ( i<argc-offset ) {
1146  std::string stringdir(argv[i]);
1147  dirs.insert( std::map<std::string,int>::value_type( stringdir, std::count( stringdir.begin(), stringdir.end(), '/' ) ) );
1148 
1149  std::string tdir = argv[i];
1150 
1151  // std::cerr << "dirs " << argv[i] << std::endl;
1152 
1153  do {
1154  subdirs.push_back( chop( tdir, "/" ) );
1155  // std::cerr << "chop " << subdirs.back() << std::endl;
1156  }
1157  while ( tdir.size() );
1158  }
1159  else return usage( std::cerr, argc, argv );
1160  }
1161  else if ( std::string(argv[i])=="-x" ) {
1162  ++i;
1163  if ( i<argc-offset ) exclude.insert( argv[i] );
1164  else return usage( std::cerr, argc, argv );
1165  }
1166  else if ( std::string(argv[i])=="-ds" || std::string(argv[i]).find("--desc")==0 ) {
1167  ++i;
1168  if ( i<argc-offset ) description = argv[i];
1169  else return usage( std::cerr, argc, argv );
1170  }
1171  else if ( std::string(argv[i])=="-b" || std::string(argv[i])=="--base" ) {
1172  ++i;
1173  if ( i<argc-offset ) base = argv[i] ;
1174  else return usage( std::cerr, argc, argv );
1175  }
1176  else if ( std::string(argv[i])=="-a" || std::string(argv[i])=="--algorithm" ) {
1177  ++i;
1178  if ( i<argc-offset ) algorithm = argv[i] ;
1179  else return usage( std::cerr, argc, argv );
1180  }
1181  // else if ( std::string(argv[i])=="-o" ) {
1182  // ++i;
1183  // if ( i<argc ) output_file = argv[i];
1184  // else return usage( std::cerr, argc, argv );
1185  // }
1186  else if ( std::string(argv[i])=="-t" || std::string(argv[i])=="--tag" ) {
1187  ++i;
1188  if ( i<argc-offset ) tags.push_back( argv[i] );
1189  else return usage( std::cerr, argc, argv );
1190  }
1191  else if ( std::string(argv[i])=="-r" ) {
1192  std::string src;
1193  std::string dest;
1194  if ( i<argc+2-offset ) {
1195  src = argv[++i];
1196  dest = argv[++i];
1197  remap.insert( std::map<std::string,std::string>::value_type( src, dest ) );
1198  } else return usage( std::cerr, argc, argv );
1199  }
1200  else {
1201  offset = 0;
1202  files.push_back(argv[i]);
1203  }
1204  }
1205 
1206  // std::cout << "tags " << tags.size() << " " << tags << std::endl;
1207 
1208  if ( base == "" ) base = dir;
1209 
1211  // if ( output_file == "" ) return usage( std::cerr, argc, argv );
1212 
1213  // dataset data("test_EF");
1214  // files = data.datafiles();
1215 
1217 
1218  if ( files.size()<1 ) return usage( std::cerr, argc, argv );
1219 
1220 
1221  // time the actual running of the cost() routine
1222 
1223  if ( verbose ) std::cerr << "timing" << std::endl;
1224 
1225  struct timeval tv = simpletimer_start();
1226 
1228 
1229  node n(0, "" );
1230  n.name( "top_level" );
1231 
1232  int status = cost( files, n, "", deleteref, relocate );
1233 
1234  // std::cerr << "\n\nnodes " << n << std::endl;
1235 
1236  if ( status ) return status;
1237 
1238  if ( outfile!="" ) outp = new std::ofstream(outfile.c_str());
1239 
1240  header h;
1241 
1242  for ( unsigned ir=0 ; ir<references.size() ; ir++ ) (*outp) << references[ir] << std::endl;
1243 
1244  if ( refblock.size() ) (*outp) << refblock << std::endl;
1245 
1247  menu m( n );
1248 
1250  ass( n, allhists );
1251 
1253  (*outp) << std::endl;
1254 
1255  double t = simpletimer_stop(tv);
1256 
1257  if ( t>1000 ) std::cerr << "total time " << t*0.001 << " s" << std::endl;
1258  else std::cerr << "total time " << t << " ms" << std::endl;
1259 
1260  return 0;
1261 }

◆ maphist()

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

Definition at line 330 of file hcg.cxx.

330  {
331  mapped.clear();
332  for ( unsigned i=0 ; i<v.size() ; i++ ) {
333  if ( contains( v[i], "Expert" ) ){
334  std::string tmp = v[i];
335  std::string path = chop( tmp, "Expert/" );
336  path += "Chains/";
337  // std::cerr << " " << v[i] << "\np:" << path << "\t-> " << tmp << std::endl;
338  tmp = replace( tmp, "/", "__" );
339  path += tmp;
340  mapped.push_back( path );
341  // std::cerr << i << "\t" << mapped.back() << std::endl;
342  }
343  else {
344  mapped.push_back( v[i] );
345  }
346  }
347 
348  return mapped;
349 }

◆ match()

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

match the individual directories of two strings

Definition at line 356 of file hcg.cxx.

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

◆ matchcwd()

bool matchcwd ( const std::string &  s)

Definition at line 402 of file hcg.cxx.

402  {
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;
407  ++itr;
408  }
409  return false;
410 }

◆ matchcwditr()

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

Definition at line 425 of file hcg.cxx.

425  {
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;
430  ++itr;
431  }
432  return dirs.end();
433 }

◆ matchcwdstr()

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

Definition at line 414 of file hcg.cxx.

414  {
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;
419  ++itr;
420  }
421  return "";
422 }

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

389  {
390  bool matched = false;
391  // int idepth = count( s, "/" );
392  std::map<std::string,int>::const_iterator itr = dirs.begin();
393  while ( itr!=dirs.end() ) {
394  if ( match( s, itr->first) ) matched = true;
395  // std::cerr << "\tmatchdir :" << s << "::" << itr->first << ": " << itr->second << std::endl;
396  if ( matched ) return true;
397  ++itr;
398  }
399  return false;
400 }

◆ operator<<() [1/3]

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

Definition at line 504 of file hcg.cxx.

504  {
505  static bool first = true;
506  if ( first ) {
507  s << "##########################\n";
508  s << "# References\n";
509  s << "##########################\n\n";
510  first = false;
511  }
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";
516  s << "}\n\n";
517  return s;
518 }

◆ operator<<() [2/3]

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

Definition at line 116 of file hcg.cxx.

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

◆ operator<<() [3/3]

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

Definition at line 105 of file hcg.cxx.

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

◆ referenceblock()

void referenceblock ( const std::string &  file)

Definition at line 1059 of file hcg.cxx.

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

◆ removespace()

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

Definition at line 297 of file hcg.cxx.

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

◆ replace()

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

Definition at line 307 of file hcg.cxx.

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

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

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

◆ split()

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

Definition at line 174 of file hcg.cxx.

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

◆ usage()

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

Definition at line 1034 of file hcg.cxx.

1034  {
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";
1052  s << std::endl;
1053  return status;
1054 }

Variable Documentation

◆ algorithm

std::string algorithm = "HLT_Histogram_Not_Empty&GatherData"

Definition at line 82 of file hcg.cxx.

◆ allhists

bool allhists = true

Definition at line 76 of file hcg.cxx.

◆ ATLAS_NO_CHECK_FILE_THREAD_SAFETY

ATLAS_NO_CHECK_FILE_THREAD_SAFETY

Definition at line 44 of file hcg.cxx.

◆ base

std::string base = "HLT"

Definition at line 78 of file hcg.cxx.

◆ currentfile

std::string currentfile = ""

Definition at line 733 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 88 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 99 of file hcg.cxx.

◆ exclude

std::set<std::string> exclude

list of directories to be excluded

Definition at line 95 of file hcg.cxx.

◆ files

std::vector<std::string> files

file names and file pointers

Definition at line 47 of file hcg.cxx.

◆ found_dir

bool found_dir = false

Definition at line 731 of file hcg.cxx.

◆ fptr

std::vector<TFile*> fptr

Definition at line 48 of file hcg.cxx.

◆ mapped

std::vector<std::string> mapped

Definition at line 51 of file hcg.cxx.

◆ outp

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

send output to here ...

Definition at line 73 of file hcg.cxx.

◆ outref

std::string outref = ""

Definition at line 80 of file hcg.cxx.

◆ refblock

std::vector<std::string> refblock

Definition at line 1057 of file hcg.cxx.

◆ references

std::vector<reference> references

Definition at line 522 of file hcg.cxx.

◆ remap

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

list of directories to be explicitly remapped

Definition at line 92 of file hcg.cxx.

◆ savedhistos

std::vector<std::string> savedhistos

Definition at line 50 of file hcg.cxx.

◆ tags

std::vector<std::string> tags

Definition at line 102 of file hcg.cxx.

◆ verbose

bool verbose = false

Definition at line 70 of file hcg.cxx.

outp
std::ostream * outp
send output to here ...
Definition: hcg.cxx:73
verbose
bool verbose
Definition: hcg.cxx:70
matchcwdstr
std::string matchcwdstr(const std::string &s)
Definition: hcg.cxx:414
base
std::string base
Definition: hcg.cxx:78
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
get_hdefs.buff
buff
Definition: get_hdefs.py:61
beamspotman.r
def r
Definition: beamspotman.py:676
cost
int cost(std::vector< std::string > &files, node &n, const std::string &directory="", bool deleteref=false, bool relocate=false)
Definition: hcg.cxx:921
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
algorithm
std::string algorithm
Definition: hcg.cxx:82
header
Definition: hcg.cxx:526
matchcwditr
std::map< std::string, int >::const_iterator matchcwditr(const std::string &s)
Definition: hcg.cxx:425
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
simpletimer_start
struct timeval simpletimer_start(void)
Definition: DataQuality/HanConfigGenerator/src/simpletimer.h:23
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
rerun_display.cmd
string cmd
Definition: rerun_display.py:67
found_dir
bool found_dir
Definition: hcg.cxx:731
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
chop
std::string chop(std::string &s1, const std::string &s2)
Definition: hcg.cxx:158
refblock
std::vector< std::string > refblock
Definition: hcg.cxx:1057
perfmonmt-printer.dest
dest
Definition: perfmonmt-printer.py:189
GetEntries
TGraphErrors * GetEntries(TH2F *histo)
Definition: TRTCalib_makeplots.cxx:4019
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
exclude
std::set< std::string > exclude
list of directories to be excluded
Definition: hcg.cxx:95
addnode
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:25
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
PlotPulseshapeFromCool.np
np
Definition: PlotPulseshapeFromCool.py:64
references
std::vector< reference > references
Definition: hcg.cxx:522
search
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:738
spacer
const std::string spacer
Definition: spacer.h:24
menu
make the sidebar many part of the config
Definition: hcg.cxx:551
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
chopfirst
std::string chopfirst(std::string &s1, const std::string &s2)
Definition: hcg.cxx:257
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Get
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,...
Definition: comparitor.cxx:178
maphist
std::vector< std::string > maphist(const std::vector< std::string > &v)
Definition: hcg.cxx:330
outref
std::string outref
Definition: hcg.cxx:80
DeMoScan.directory
string directory
Definition: DeMoScan.py:80
matchdir
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:389
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
beamspotman.n
n
Definition: beamspotman.py:731
files
std::vector< std::string > files
file names and file pointers
Definition: hcg.cxx:47
extractSporadic.h
list h
Definition: extractSporadic.py:97
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition: hcg.cxx:174
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
referenceblock
void referenceblock(const std::string &file)
Definition: hcg.cxx:1059
file
TFile * file
Definition: tile_monitor.h:29
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
count
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition: hcg.cxx:143
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
fptr
std::vector< TFile * > fptr
Definition: hcg.cxx:48
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
node::HISTOGRAM
@ HISTOGRAM
Definition: node.h:25
beamspotman.stat
stat
Definition: beamspotman.py:266
python.CaloCellMakerConfig.reffile
reffile
Definition: CaloCellMakerConfig.py:105
beamspotman.dir
string dir
Definition: beamspotman.py:623
simpletimer_stop
double simpletimer_stop(const struct timeval &start_time)
Definition: DataQuality/HanConfigGenerator/src/simpletimer.h:29
ReadCellNoiseFromCoolCompare.s3
s3
Definition: ReadCellNoiseFromCoolCompare.py:380
currentfile
std::string currentfile
Definition: hcg.cxx:733
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
choplast
std::string choplast(std::string &s1, const std::string &s2)
Definition: hcg.cxx:273
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
dirs
std::map< std::string, int > dirs
list of directories to be explicitly included, together with corresponding depths of subdirectories
Definition: hcg.cxx:99
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
cwd
std::string cwd
Definition: listroot.cxx:38
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
python.PyAthena.v
v
Definition: PyAthena.py:154
a
TList * a
Definition: liststreamerinfos.cxx:10
remap
std::map< std::string, std::string > remap
list of directories to be explicitly remapped
Definition: hcg.cxx:92
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
DeMoScan.first
bool first
Definition: DeMoScan.py:536
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:44
savedhistos
std::vector< std::string > savedhistos
Definition: hcg.cxx:50
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
mapped
std::vector< std::string > mapped
Definition: hcg.cxx:51
allhists
bool allhists
Definition: hcg.cxx:76
usage
int usage(std::ostream &s, int, char **argv, int status=-1)
Definition: hcg.cxx:1034
merge.status
status
Definition: merge.py:17
dqt_zlumi_alleff_HIST.tl
tl
Definition: dqt_zlumi_alleff_HIST.py:73
python.envutil.fulldir
fulldir
Definition: envutil.py:153
python.LumiCalcRecover.subdir
subdir
Definition: LumiCalcRecover.py:25
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
file_exists
bool file_exists(const std::string &file)
Definition: hcg.cxx:65
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
node
Definition: memory_hooks-stdcmalloc.h:74
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
matchcwd
bool matchcwd(const std::string &s)
Definition: hcg.cxx:402
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88
ass
make the histogram assessment part of the config
Definition: hcg.cxx:626