22 #include "Riostream.h"
33 void hadd(TString detector) {
39 int nCopies = successfulJobs;
41 if(gSystem->AccessPathName(
"EvalFiles/Eval_" + detector +
"_0.root")) {
42 for(
int i = 1; i < nCopies; i++){
43 gSystem->CopyFile(
"hsimple.root",
"EvalFiles/Eval_" + detector +
"_" + TString::Itoa(i,10) +
".root");
52 Target = TFile::Open(
"merged_Eval_" + detector +
".root",
"RECREATE" );
55 for(
int i = 0; i < nCopies; i++){
56 FileList->Add( TFile::Open(
"EvalFiles/Eval_" + detector +
"_" + TString::Itoa(i,10) +
".root"));
67 TString path( (
char*)strstr( target->GetPath(),
":" ) );
70 TFile *first_source = (TFile*)sourcelist->First();
71 first_source->cd( path );
72 TDirectory *current_sourcedir = gDirectory;
74 Bool_t status = TH1::AddDirectoryStatus();
75 TH1::AddDirectory(kFALSE);
78 TChain *globChain = 0;
79 TIter nextkey( current_sourcedir->GetListOfKeys() );
81 while ( (key = (TKey*)nextkey())) {
84 if (oldkey && !strcmp(oldkey->GetName(),key->GetName()))
continue;
87 first_source->cd( path );
90 if ( obj->IsA()->InheritsFrom( TH1::Class() ) ) {
98 TFile *nextsource = (TFile*)sourcelist->After( first_source );
99 while ( nextsource ) {
102 nextsource->cd( path );
103 TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
105 TH1 *
h2 = (TH1*)key2->ReadObj();
110 nextsource = (TFile*)sourcelist->After( nextsource );
113 else if ( obj->IsA()->InheritsFrom( TTree::Class() ) ) {
116 const char* obj_name= obj->GetName();
118 globChain =
new TChain(obj_name);
119 globChain->SetMaxTreeSize(200000000000LL);
120 globChain->Add(first_source->GetName());
121 TFile *nextsource = (TFile*)sourcelist->After( first_source );
124 while ( nextsource ) {
126 globChain->Add(nextsource->GetName());
127 nextsource = (TFile*)sourcelist->After( nextsource );
130 }
else if ( obj->IsA()->InheritsFrom( TDirectory::Class() ) ) {
133 cout <<
"Found subdirectory " << obj->GetName() << endl;
137 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
147 cout <<
"Unknown object type, name: "
148 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
159 if(obj->IsA()->InheritsFrom( TTree::Class() ))
160 globChain->Merge(target->GetFile(),0,
"keep");
162 obj->Write( key->GetName() );
168 target->SaveSelf(kTRUE);
169 TH1::AddDirectory(status);