]> Creatis software - clitk.git/blob - tests_dav/clitkMergeRootFiles.cxx
switched to gjm merger for pet
[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 "GateMergeManager.hh"
14 #include <string> 
15 #include <TROOT.h>
16 #include <TPluginManager.h>
17 #include <TFile.h>
18 #include <TKey.h>
19 #include <TFileMerger.h>
20 #include <TTree.h>
21 #include <TChain.h>
22 #include <TH1.h>
23 #include <TH2.h>
24 #include <iostream>
25
26 using std::endl;
27 using std::cout;
28
29 typedef std::list<std::string> Strings;
30
31
32 //-----------------------------------------------------------------------------
33 int main(int argc, char * argv[]) {
34
35   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*",
36       "TStreamerInfo", "RIO", "TStreamerInfo()");
37
38   // init command line
39   GGO(clitkMergeRootFiles, args_info);
40
41   // Check parameters
42   if (args_info.input_given < 2) {
43     FATAL("Error, please provide at least two inputs files");
44   }
45
46   { // Detect Pet output
47           bool all_pet_output = true;
48           Strings input_filenames;
49           for (uint i=0; i<args_info.input_given; i++) 
50           {
51                   const char* filename = args_info.input_arg[i];
52                   input_filenames.push_back(filename);
53                   TFile* handle = TFile::Open(filename,"READ");
54                   assert(handle);
55                   TTree* hits = dynamic_cast<TTree*>(handle->Get("Hits"));
56                   TTree* singles = dynamic_cast<TTree*>(handle->Get("Singles"));
57                   const bool is_pet_output = (hits!=NULL) && (singles!=NULL);
58                   cout << "testing " << filename << " is_pet_output " << is_pet_output << endl;
59                   handle->Close();
60                   delete handle;
61                   all_pet_output &= is_pet_output;
62           }
63           cout << "all_pet_output " << all_pet_output << endl;
64
65           if (all_pet_output)
66           {
67                   GateMergeManager* manager = new GateMergeManager(args_info.fastmerge_given,args_info.verbose_arg,true,0,".");
68                   delete manager;
69                   return 0;
70           }
71   }
72
73
74   // Merge
75   TFileMerger * merger = new TFileMerger;
76   for (uint i=0; i<args_info.input_given; i++) merger->AddFile(args_info.input_arg[i]);
77   merger->OutputFile(args_info.output_arg);
78   merger->Merge();
79
80   // this is the end my friend  
81   return 0;
82 }
83 //-----------------------------------------------------------------------------