2 =================================================
3 * @file clitkMergeRootFiles.cxx
4 * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
9 =================================================*/
11 #include "clitkMergeRootFiles_ggo.h"
12 #include "clitkCommon.h"
13 #include "GateMergeManager.hh"
16 #include <TPluginManager.h>
19 #include <TFileMerger.h>
35 bool sort_pet_input_file(const PetInputFile& a, const PetInputFile& b)
37 return a.mean_time<b.mean_time;
40 typedef std::vector<PetInputFile> PetInputFiles;
42 //-----------------------------------------------------------------------------
43 int main(int argc, char * argv[]) {
45 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*",
46 "TStreamerInfo", "RIO", "TStreamerInfo()");
49 GGO(clitkMergeRootFiles, args_info);
52 if (args_info.input_given < 2) {
53 FATAL("Error, please provide at least two inputs files");
56 { // Detect Pet output
57 bool all_pet_output = true;
58 PetInputFiles pet_input_files;
59 for (uint i=0; i<args_info.input_given; i++)
61 const char* filename = args_info.input_arg[i];
62 PetInputFile input_file;
63 input_file.filename = filename;
64 TFile* handle = TFile::Open(filename,"READ");
66 TTree* hits = dynamic_cast<TTree*>(handle->Get("Hits"));
67 TTree* singles = dynamic_cast<TTree*>(handle->Get("Singles"));
68 const bool is_pet_output = (hits!=NULL) && (singles!=NULL);
69 cout << "testing " << filename << " is_pet_output " << is_pet_output;
74 double time_accum = 0;
75 singles->SetBranchAddress("time",&time);
76 size_t total = singles->GetEntries();
77 for (size_t kk=0; kk<total; kk++)
79 singles->GetEntry(kk);
83 input_file.mean_time = time_accum/total;
84 pet_input_files.push_back(input_file);
85 cout << " mean_time " << input_file.mean_time;
92 all_pet_output &= is_pet_output;
94 cout << "all_pet_output " << all_pet_output << endl;
98 GateMergeManager manager(args_info.fastmerge_given,args_info.verbose_arg,true,0,"");
100 cout << "sorting input file using singles time" << endl;
101 std::sort(pet_input_files.begin(),pet_input_files.end(),sort_pet_input_file);
103 Strings input_filenames;
104 for (PetInputFiles::const_iterator iter=pet_input_files.begin(); iter!=pet_input_files.end(); iter++)
105 input_filenames.push_back(iter->filename);
107 manager.StartMergingFromFilenames(input_filenames,args_info.output_arg);
114 TFileMerger * merger = new TFileMerger;
115 for (uint i=0; i<args_info.input_given; i++) merger->AddFile(args_info.input_arg[i]);
116 merger->OutputFile(args_info.output_arg);
119 // this is the end my friend
122 //-----------------------------------------------------------------------------