55bool add(
const std::string& hname, TKey* tobj ) {
57 T* h0 = (T*)tobj->ReadObj();
66 std::cerr <<
"object " << hname <<
" can't be found" << std::endl;
70 if ( h0->GetSumw2N()==0 ) h0->Sumw2();
75 for (
unsigned ifile=1 ; ifile<
fptr.size() ; ifile++ ) {
83 T*
h = (T*)
fptr[ifile]->
Get(hname.c_str());
88 std::cout <<
"h (add) " <<
h <<
" " << hname <<
" can't be opened" << std::endl;
89 if (
count>20 ) exit(-1);
94 if (
h->GetSumw2N()==0 )
h->Sumw2();
110 h0->Write(
"",TObject::kOverwrite);
126void search(TDirectory* td=0,
const std::string& s=
"") {
132 if (
ir>10 ) exit(0);
136 TDirectory* here = gDirectory;
142 if ( ns!=
"" ) ns +=
"/";
145 gDirectory->cd(td->GetName());
149 std::cout <<
"\n" <<
depth <<
"Directory " << ns;
152 std::string savedepth =
depth;
157 TList* tl = gDirectory->GetListOfKeys();
163 for (
int i=tl->GetSize() ; i-- ; ) {
165 TKey* tobj = (TKey*)tl->At(i);
167 if ( tobj==0 )
continue;
173 if ( std::string(tobj->GetClassName()).find(
"TDirectory")!=std::string::npos ) {
176 TDirectory* tnd = (TDirectory*)tobj->ReadObj();
178 if ( tnd )
search( tnd, ns );
183 std::string objname = ns;
184 if ( objname!=
"" ) objname += std::string(
"/") + tobj->GetName();
188 if ( std::string(tobj->GetClassName()).find(
"TH1")!=std::string::npos )
add<TH1>( objname, tobj );
189 if ( std::string(tobj->GetClassName()).find(
"TH2")!=std::string::npos )
add<TH2>( objname, tobj );
190 if ( std::string(tobj->GetClassName()).find(
"TProfile")!=std::string::npos )
add<TProfile>( objname, tobj );
202 std::cout <<
"\tprocessed directory in " << t*0.001 <<
" s from " << global_time*0.001 <<
" s";
205 depth = std::move(savedepth);
221 if ( FILE* testfile=fopen(s.c_str(),
"r") ) {
235 if (
files.size()<2 )
return;
237 std::cout <<
"processing" << std::endl;
241 std::cerr <<
"output file " <<
outputfile <<
" already exists" << std::endl;
245 std::cout <<
"copying file to " <<
outputfile << std::endl;
254 std::cout <<
"opening root files" << std::endl;
259 std::cout <<
"opening " <<
files[0] << std::endl;
265 std::cerr <<
"cannot open " <<
outputfile.c_str() << std::endl;
269 for (
unsigned ifile=1 ; ifile<
files.size() ; ifile++ ) {
270 std::cout <<
"opening " <<
files[ifile] << std::endl;
271 fptr[ifile] =
new TFile(
files[ifile].c_str() );
275 for (
unsigned ifile=0 ; ifile<
files.size() ; ifile++ ) {
276 if (
fptr[ifile]==0 ) {
277 std::cerr <<
"file " <<
files[ifile] <<
" cannot be openened" << std::endl;
284 TDirectory* here = gDirectory;
294 std::cout <<
"closing the files" << std::endl;
297 for (
unsigned ifile=1 ; ifile<
files.size() ; ifile++ ) {
299 fptr[ifile]->Close();
313int usage(std::ostream& s,
int ,
char** argv) {
314 s <<
"Usage: " << argv[0] <<
" [OPTIONS] -o output.root input1.root ... inputN.root\n\n";
315 s <<
" -o filename \tname of output (filename required)\n";
316 s <<
" -h, --help \tdisplay this help\n";
324int main(
int argc,
char** argv) {
327 if ( argc<3 )
return usage( std::cerr, argc, argv );
330 for (
int i=1 ; i<argc ; i++ ) {
331 if ( std::string(argv[i])==
"-h" || std::string(argv[i])==
"--help" )
return usage( std::cout, argc, argv );
336 std::string output_file =
"";
338 for (
int i=1 ; i<argc ; i++ ) {
339 if ( std::string(argv[i])==
"--verbose" )
verbose =
true;
340 else if ( std::string(argv[i])==
"-o" ) {
341 if ( ++i<argc ) output_file = argv[i];
342 else return usage( std::cerr, argc, argv );
345 files.push_back(argv[i]);
351 if ( output_file ==
"" )
return usage( std::cerr, argc, argv );
359 if (
files.size()<1 )
return usage( std::cerr, argc, argv );
361 for (
size_t i=
files.size() ; i-- ; )
if (
files[i]==output_file )
return usage( std::cerr, argc, argv );
365 if (
verbose ) std::cout <<
"timing" << std::endl;
373 std::cout <<
"\ntotal time " << t*0.001 <<
" s (" << (t*0.001/60) <<
" min)" << std::endl;
struct timeval simpletimer_start(void)
double simpletimer_stop(const struct timeval &start_time)
these functions have a precision of about 0.001 ms
Header file for AthHistogramAlgorithm.
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,...
struct timeval global_timer
glabal timer - how long have I taken so far?
int ir
counter of the current depth
bool add(const std::string &hname, TKey *tobj)
void search(TDirectory *td=0, const std::string &s="")
recursive directory search for TH1 and TH2
bool file_exists(const std::string &s)
void cost(const std::string &outputfile)
std::string depth
tag string for intendation
std::vector< TFile * > fptr
std::vector< std::string > files
file names and file pointers
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string