12 void MergeRootfile( TDirectory *target, TList *sourcelist );
14 void hadd(
int flag=0) {
15 TString iPath=
"out1/";
19 Target = TFile::Open( out+
".hist.root",
"RECREATE" );
25 char *runL=
"R7098001 R7098024 R7098038 R7098065 R7098082 R7099025 R7099047 R7100072 R7098002 R7098025 R7098039 R7098066 R7098083 R7099026 R7100052 R7100075 ";
27 FileList =
new TList();
29 char *run=strtok(runL,
" ");
32 printf(
"add run %d '%s' \n",i++,run);
33 TString fullName=iPath+run+
".hist.root";
34 FileList->Add( TFile::Open(fullName));
35 }
while(run=strtok(0,
" "));
37 MergeRootfile( Target, FileList );
41 void MergeRootfile( TDirectory *target, TList *sourcelist ) {
44 TString path( (
char*)strstr( target->GetPath(),
":" ) );
47 TFile *first_source = (TFile*)sourcelist->First();
48 first_source->cd( path );
49 TDirectory *current_sourcedir = gDirectory;
53 TChain *globChain = 0;
54 TIter nextkey( current_sourcedir->GetListOfKeys() );
56 while ( (key = (TKey*)nextkey())) {
57 const char *name=key->GetName();
59 if(nh%10==0) printf(
"nh=%d addingX %s\n",nh,name);
62 first_source->cd( path );
63 TObject *obj = key->ReadObj();
65 if ( obj->IsA()->InheritsFrom(
"TH1" ) ) {
73 TFile *nextsource = (TFile*)sourcelist->After( first_source );
74 while ( nextsource ) {
77 nextsource->cd( path );
78 TH1 *h2 = (TH1*)gDirectory->Get( h1->GetName() );
85 nextsource = (TFile*)sourcelist->After( nextsource );
88 else if ( obj->IsA()->InheritsFrom(
"TTree" ) ) {
91 const char* obj_name= obj->GetName();
93 globChain =
new TChain(obj_name);
94 globChain->Add(first_source->GetName());
95 TFile *nextsource = (TFile*)sourcelist->After( first_source );
98 while ( nextsource ) {
100 globChain->Add(nextsource->GetName());
101 nextsource = (TFile*)sourcelist->After( nextsource );
104 }
else if ( obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
107 cout <<
"Found subdirectory " << obj->GetName() << endl;
111 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
116 MergeRootfile( core,newdir, sourcelist );
121 cout <<
"Unknown object type, name: "
122 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
133 if(obj->IsA()->InheritsFrom(
"TTree" ))
134 globChain->Write( key->GetName() );
136 obj->Write( key->GetName() );