37 #include <Riostream.h>
51 int main(
int narg,
char* argv[])
80 cout<<
" root_merge [options] infput_file1 input_file2 input_file3 ..."<<endl;
82 cout<<
"options:"<<endl;
83 cout<<
" -o filename set output filename (def:"<<
OUTPUT_FILENAME<<
")"<<endl;
84 cout<<
" -h Print this usage statement"<<endl;
98 for(
int i=1; i<narg; i++){
99 if(argv[i][0] ==
'-'){
109 cout<<
"Unknown option \""<<argv[i]<<
"\". Aborting."<<endl;
113 FileList->Add( TFile::Open(argv[i]));
125 Target = TFile::Open(
"result.root",
"RECREATE" );
128 FileList->Add( TFile::Open(
"hsimple1.root") );
129 FileList->Add( TFile::Open(
"hsimple2.root") );
142 TString path( (
char*)strstr( target->GetPath(),
":" ) );
145 TFile *first_source = (TFile*)sourcelist->First();
146 first_source->cd( path );
147 TDirectory *current_sourcedir = gDirectory;
150 TChain *globChain = 0;
151 TIter nextkey( current_sourcedir->GetListOfKeys() );
153 while ( (key = (TKey*)nextkey())) {
156 first_source->cd( path );
157 TObject *obj = key->ReadObj();
159 if ( obj->IsA()->InheritsFrom(
"TH1" ) ) {
167 TFile *nextsource = (TFile*)sourcelist->After( first_source );
168 while ( nextsource ) {
171 nextsource->cd( path );
172 TH1 *
h2 = (TH1*)gDirectory->Get( h1->GetName() );
179 nextsource = (TFile*)sourcelist->After( nextsource );
182 else if ( obj->IsA()->InheritsFrom(
"TTree" ) ) {
185 const char* obj_name= obj->GetName();
187 globChain =
new TChain(obj_name);
188 globChain->Add(first_source->GetName());
189 TFile *nextsource = (TFile*)sourcelist->After( first_source );
192 while ( nextsource ) {
194 globChain->Add(nextsource->GetName());
195 nextsource = (TFile*)sourcelist->After( nextsource );
198 }
else if ( obj->IsA()->InheritsFrom(
"TDirectory" ) ) {
201 cout <<
"Found subdirectory " << obj->GetName() << endl;
205 TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
215 cout <<
"Unknown object type, name: "
216 << obj->GetName() <<
" title: " << obj->GetTitle() << endl;
227 if (obj->IsA()->InheritsFrom(
"TTree" ) && globChain)
228 globChain->Write( key->GetName() );
230 obj->Write( key->GetName() );
void MergeRootfile(TDirectory *target, TList *sourcelist)
void ParseCommandLineArguments(int &narg, char *argv[])
void Usage(JApplication &app)
int main(int argc, char *argv[])