12 void MergeRootfile( TDirectory *target, TList *sourcelist );
14 void hadd(
int sectID) {
15 TString iPath=
"iter5-pp/";
17 TString out=
"iter5-pp/sect";
18 if(sectID<10) out+=
"0";
19 out+=sectID; out+=
"/sum-sect"; out+=sectID;
21 Target = TFile::Open( out+
".hist.root",
"RECREATE" );
24 char *runL=
" R7089008 R7089013 R7089014 R7089015 R7089021 R7089022 R7089024 R7089025 R7089091 R7090008 ";
26 FileList =
new TList();
28 char *run=strtok(runL,
" ");
31 printf(
"add run %d '%s' \n",i++,run);
32 TString fullName=iPath+run+
".hist.root";
33 FileList->Add( TFile::Open(fullName));
34 }
while(run=strtok(0,
" "));
37 sprintf(core,
"%02d",sectID);
38 MergeRootfile( core, Target, FileList );
42 void MergeRootfile(
char *core, TDirectory *target, TList *sourcelist ) {
43 printf(
"merging only histos with core=%s=\n",core);
46 TString path( (
char*)strstr( target->GetPath(),
":" ) );
49 TFile *first_source = (TFile*)sourcelist->First();
50 first_source->cd( path );
51 TDirectory *current_sourcedir = gDirectory;
55 TChain *globChain = 0;
56 TIter nextkey( current_sourcedir->GetListOfKeys() );
58 while ( (key = (TKey*)nextkey())) {
59 const char *name=key->GetName();
60 char * c1=strstr(name,core);
62 if(c1-name>2)
continue;
64 if(nh%100==0) printf(
"nh=%d addingX %s\n",nh,name);
67 first_source->cd( path );
68 TObject *obj = key->ReadObj();
70 if ( obj->IsA()->InheritsFrom(
"TH1" ) ) {
78 TFile *nextsource = (TFile*)sourcelist->After( first_source );
79 while ( nextsource ) {
82 nextsource->cd( path );
83 TH1 *h2 = (TH1*)gDirectory->Get( h1->GetName() );
90 nextsource = (TFile*)sourcelist->After( nextsource );
93 else if ( obj->IsA()->InheritsFrom(
"TTree" ) ) {
96 const char* obj_name= obj->GetName();
98 globChain =
new TChain(obj_name);
99 globChain->Add(first_source->GetName());
100 TFile *nextsource = (TFile*)sourcelist->After( first_source );
103 while ( nextsource ) {
105 globChain->Add(nextsource->GetName());
106 nextsource = (TFile*)sourcelist->After( nextsource );
109 }
else if ( obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
112 cout <<
"Found subdirectory " << obj->GetName() << endl;
116 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
121 MergeRootfile( core,newdir, sourcelist );
126 cout <<
"Unknown object type, name: "
127 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
138 if(obj->IsA()->InheritsFrom(
"TTree" ))
139 globChain->Write( key->GetName() );
141 obj->Write( key->GetName() );