21 Target = TFile::Open(
"result.root",
"RECREATE" );
24 FileList->Add( TFile::Open(
"hsimple1.root") );
25 FileList->Add( TFile::Open(
"hsimple2.root") );
34 TString path( (
char*)strstr( target->GetPath(),
":" ) );
37 TFile *first_source = (TFile*)sourcelist->First();
38 first_source->cd( path );
39 TDirectory *current_sourcedir = gDirectory;
41 Bool_t status = TH1::AddDirectoryStatus();
42 TH1::AddDirectory(kFALSE);
45 TChain *globChain = 0;
46 TIter nextkey( current_sourcedir->GetListOfKeys() );
48 while ( (key = (TKey*)nextkey())) {
51 if (oldkey && !strcmp(oldkey->GetName(),key->GetName()))
continue;
54 first_source->cd( path );
57 if ( obj->IsA()->InheritsFrom( TH1::Class() ) ) {
65 TFile *nextsource = (TFile*)sourcelist->After( first_source );
66 while ( nextsource ) {
69 nextsource->cd( path );
70 TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
72 TH1 *
h2 = (TH1*)key2->ReadObj();
77 nextsource = (TFile*)sourcelist->After( nextsource );
80 else if ( obj->IsA()->InheritsFrom( TTree::Class() ) ) {
83 const char* obj_name= obj->GetName();
85 globChain =
new TChain(obj_name);
86 globChain->Add(first_source->GetName());
87 TFile *nextsource = (TFile*)sourcelist->After( first_source );
90 while ( nextsource ) {
92 globChain->Add(nextsource->GetName());
93 nextsource = (TFile*)sourcelist->After( nextsource );
96 }
else if ( obj->IsA()->InheritsFrom( TDirectory::Class() ) ) {
99 cout <<
"Found subdirectory " << obj->GetName() << endl;
103 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
113 cout <<
"Unknown object type, name: "
114 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
125 if(obj->IsA()->InheritsFrom( TTree::Class() ))
126 globChain->Merge(target->GetFile(),0,
"keep");
128 obj->Write( key->GetName() );
134 target->SaveSelf(kTRUE);
135 TH1::AddDirectory(status);