23 void hadd(
const char* list,
const char* out){
27 wcsimdirenv = getenv (
"WCSIMDIR");
28 if(wcsimdirenv != NULL){
29 gSystem->Load(
"${WCSIMDIR}/libWCSimRoot.so");
32 cout<<
"Must set WCSIMDIR" << std::endl;
34 Target = TFile::Open( out ,
"RECREATE" );
38 std::ifstream w_file( list );
39 if (w_file.is_open()) {
41 while (getline(w_file, w_line)) {
42 FileList->Add( TFile::Open( w_line.c_str() ));
53 TString path( (
char*)strstr( target->GetPath(),
":" ) );
56 TFile *first_source = (TFile*)sourcelist->First();
57 first_source->cd( path );
58 TDirectory *current_sourcedir = gDirectory;
60 Bool_t status = TH1::AddDirectoryStatus();
61 TH1::AddDirectory(kFALSE);
64 TChain *globChain = 0;
65 TIter nextkey( current_sourcedir->GetListOfKeys() );
67 while ( (key = (TKey*)nextkey())) {
70 if (oldkey && !strcmp(oldkey->GetName(),key->GetName()))
continue;
73 first_source->cd( path );
76 if ( obj->IsA()->InheritsFrom( TH1::Class() ) ) {
84 TFile *nextsource = (TFile*)sourcelist->After( first_source );
85 while ( nextsource ) {
88 nextsource->cd( path );
89 TKey *key2 = (TKey*)gDirectory->GetListOfKeys()->FindObject(h1->GetName());
91 TH1 *h2 = (TH1*)key2->ReadObj();
96 nextsource = (TFile*)sourcelist->After( nextsource );
99 else if ( obj->IsA()->InheritsFrom( TTree::Class() ) ) {
102 const char* obj_name= obj->GetName();
104 globChain =
new TChain(obj_name);
105 globChain->Add(first_source->GetName());
106 TFile *nextsource = (TFile*)sourcelist->After( first_source );
109 while ( nextsource ) {
111 globChain->Add(nextsource->GetName());
112 nextsource = (TFile*)sourcelist->After( nextsource );
115 }
else if ( obj->IsA()->InheritsFrom( TDirectory::Class() ) ) {
118 cout <<
"Found subdirectory " << obj->GetName() << endl;
122 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
132 cout <<
"Unknown object type, name: " 133 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
144 if(obj->IsA()->InheritsFrom( TTree::Class() ))
145 globChain->Merge(target->GetFile(),0,
"keep");
147 obj->Write( key->GetName() );
153 target->SaveSelf(kTRUE);
154 TH1::AddDirectory(status);
void hadd(const char *list, const char *out)
void MergeRootfile(TDirectory *target, TList *sourcelist)