X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=tests_dav%2FclitkMergeRootFiles.cxx;h=4bd0634a763afd5e84cc234a4b0e5613472d6b9a;hb=61f1b1d325c260565db5ff8942826a25faf58ec4;hp=4c86c57068185856f6d83fa4eecc5419e2044646;hpb=30d053d7332a384c7b80dc0c2e9da89ed822f503;p=clitk.git diff --git a/tests_dav/clitkMergeRootFiles.cxx b/tests_dav/clitkMergeRootFiles.cxx index 4c86c57..4bd0634 100644 --- a/tests_dav/clitkMergeRootFiles.cxx +++ b/tests_dav/clitkMergeRootFiles.cxx @@ -10,17 +10,35 @@ #include "clitkMergeRootFiles_ggo.h" #include "clitkCommon.h" +#include "GateMergeManager.hh" #include #include #include #include +#include #include #include +#include +#include +#include #include using std::endl; using std::cout; +struct PetInputFile +{ + string filename; + double mean_time; +}; + +bool sort_pet_input_file(const PetInputFile& a, const PetInputFile& b) +{ + return a.mean_time PetInputFiles; + //----------------------------------------------------------------------------- int main(int argc, char * argv[]) { @@ -35,19 +53,62 @@ int main(int argc, char * argv[]) { FATAL("Error, please provide at least two inputs files"); } - // Detect Pet output - bool is_pet_output = true; - for (uint i=0; i(handle->Get("Hits")); - cout << "testing " << filename << " " << hits << endl; - handle->Close(); - delete handle; - is_pet_output &= (hits==NULL); + { // Detect Pet output + bool all_pet_output = true; + PetInputFiles pet_input_files; + for (uint i=0; i(handle->Get("Hits")); + TTree* singles = dynamic_cast(handle->Get("Singles")); + const bool is_pet_output = (hits!=NULL) && (singles!=NULL); + cout << "testing " << filename << " is_pet_output " << is_pet_output; + + if (is_pet_output) + { + double time; + double time_accum = 0; + singles->SetBranchAddress("time",&time); + size_t total = singles->GetEntries(); + for (size_t kk=0; kkGetEntry(kk); + time_accum += time; + } + + input_file.mean_time = time_accum/total; + pet_input_files.push_back(input_file); + cout << " mean_time " << input_file.mean_time; + } + + cout << endl; + + handle->Close(); + delete handle; + all_pet_output &= is_pet_output; + } + cout << "all_pet_output " << all_pet_output << endl; + + if (all_pet_output) + { + GateMergeManager manager(args_info.fastmerge_given,args_info.verbose_arg,true,0,""); + + cout << "sorting input file using singles time" << endl; + std::sort(pet_input_files.begin(),pet_input_files.end(),sort_pet_input_file); + + Strings input_filenames; + for (PetInputFiles::const_iterator iter=pet_input_files.begin(); iter!=pet_input_files.end(); iter++) + input_filenames.push_back(iter->filename); + + manager.StartMergingFromFilenames(input_filenames,args_info.output_arg); + return 0; + } } - cout << "is_pet_output " << is_pet_output << endl; + // Merge TFileMerger * merger = new TFileMerger;