]> Creatis software - clitk.git/blob - tests_dav/clitkMergeRootFiles.cxx
4c86c57068185856f6d83fa4eecc5419e2044646
[clitk.git] / tests_dav / clitkMergeRootFiles.cxx
1 /**
2    =================================================
3    * @file   clitkMergeRootFiles.cxx
4    * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
5    * @date   01 Apr 2009
6    * 
7    * @brief  
8    * 
9    =================================================*/
10
11 #include "clitkMergeRootFiles_ggo.h"
12 #include "clitkCommon.h"
13 #include <string> 
14 #include <TROOT.h>
15 #include <TPluginManager.h>
16 #include <TFile.h>
17 #include <TFileMerger.h>
18 #include <TTree.h>
19 #include <iostream>
20
21 using std::endl;
22 using std::cout;
23
24 //-----------------------------------------------------------------------------
25 int main(int argc, char * argv[]) {
26
27   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*",
28       "TStreamerInfo", "RIO", "TStreamerInfo()");
29
30   // init command line
31   GGO(clitkMergeRootFiles, args_info);
32
33   // Check parameters
34   if (args_info.input_given < 2) {
35     FATAL("Error, please provide at least two inputs files");
36   }
37
38   // Detect Pet output
39   bool is_pet_output = true;
40   for (uint i=0; i<args_info.input_given; i++) 
41   {
42           const char* filename = args_info.input_arg[i];
43           TFile* handle = TFile::Open(filename,"READ");
44           TTree* hits = dynamic_cast<TTree*>(handle->Get("Hits"));
45           cout << "testing " << filename << " " << hits << endl;
46           handle->Close();
47           delete handle;
48           is_pet_output &= (hits==NULL);
49   }
50   cout << "is_pet_output " << is_pet_output << endl;
51
52   // Merge
53   TFileMerger * merger = new TFileMerger;
54   for (uint i=0; i<args_info.input_given; i++) merger->AddFile(args_info.input_arg[i]);
55   merger->OutputFile(args_info.output_arg);
56   merger->Merge();
57
58   // this is the end my friend  
59   return 0;
60 }
61 //-----------------------------------------------------------------------------