32 #include "Riostream.h"
40 void hadd(Char_t list[]=
"inputlist", Char_t outputfile[]=
"results.root") {
46 Target = TFile::Open( outputfile,
"RECREATE" );
53 char line[1024], filename[1024];
54 FILE *fp=fopen((
char*) list,
"r");
57 printf(
"<E> File %s could not be opened\n",list);
60 Int_t
cnt=0, maxfiles=986;
61 while ((fgets(line,
sizeof(line),fp)) && cnt<maxfiles)
64 sscanf(line,
"%s\n",filename);
65 printf(
"Opening file %s\n",filename);
66 FileList->Add( TFile::Open(filename) );
75 TString path( (
char*)strstr( target->GetPath(),
":" ) );
78 TFile *first_source = (TFile*)sourcelist->First();
79 first_source->cd( path );
80 TDirectory *current_sourcedir = gDirectory;
83 TChain *globChain = 0;
84 TIter nextkey( current_sourcedir->GetListOfKeys() );
86 while ( (key = (TKey*)nextkey())) {
89 first_source->cd( path );
90 TObject *obj = key->ReadObj();
92 if ( obj->IsA()->InheritsFrom(
"TH1" ) ) {
100 TFile *nextsource = (TFile*)sourcelist->After( first_source );
101 while ( nextsource ) {
104 nextsource->cd( path );
105 TH1 *
h2 = (TH1*)gDirectory->Get( h1->GetName() );
112 nextsource = (TFile*)sourcelist->After( nextsource );
115 else if ( obj->IsA()->InheritsFrom(
"TTree" ) ) {
118 const char* obj_name= obj->GetName();
120 globChain =
new TChain(obj_name);
121 globChain->Add(first_source->GetName());
122 TFile *nextsource = (TFile*)sourcelist->After( first_source );
125 while ( nextsource ) {
127 globChain->Add(nextsource->GetName());
128 nextsource = (TFile*)sourcelist->After( nextsource );
131 }
else if ( obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
134 cout <<
"Found subdirectory " << obj->GetName() << endl;
138 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
148 cout <<
"Unknown object type, name: "
149 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
160 if(obj->IsA()->InheritsFrom(
"TTree" ))
161 globChain->Write( key->GetName() );
163 obj->Write( key->GetName() );
void hadd(Char_t list[]="inputlist", Char_t outputfile[]="results.root")
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Double_t val[nBoxes][nFEBox]
void MergeRootfile(TDirectory *target, TList *sourcelist)