From: David Sarrut Date: Fri, 26 Jul 2013 06:33:53 +0000 (+0200) Subject: Moved from repository clitk.private to tools X-Git-Tag: v1.4.0~164^2~24 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=61f1b1d325c260565db5ff8942826a25faf58ec4;p=clitk.git Moved from repository clitk.private to tools --- diff --git a/tools/clitkMergeRootFiles.cxx b/tools/clitkMergeRootFiles.cxx new file mode 100644 index 0000000..4bd0634 --- /dev/null +++ b/tools/clitkMergeRootFiles.cxx @@ -0,0 +1,122 @@ +/** + ================================================= + * @file clitkMergeRootFiles.cxx + * @author David Sarrut + * @date 01 Apr 2009 + * + * @brief + * + =================================================*/ + +#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[]) { + + gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", + "TStreamerInfo", "RIO", "TStreamerInfo()"); + + // init command line + GGO(clitkMergeRootFiles, args_info); + + // Check parameters + if (args_info.input_given < 2) { + FATAL("Error, please provide at least two inputs files"); + } + + { // 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; + } + } + + + // Merge + TFileMerger * merger = new TFileMerger; + for (uint i=0; iAddFile(args_info.input_arg[i]); + merger->OutputFile(args_info.output_arg); + merger->Merge(); + + // this is the end my friend + return 0; +} +//----------------------------------------------------------------------------- diff --git a/tools/clitkMergeRootFiles.ggo b/tools/clitkMergeRootFiles.ggo new file mode 100644 index 0000000..7baa396 --- /dev/null +++ b/tools/clitkMergeRootFiles.ggo @@ -0,0 +1,13 @@ +# -------------------------------------------- +# file clitkMergeRootFiles.ggo +package "clitkMergeRootFiles" +version "1.0" +purpose "Merge several ROOT files" +# -------------------------------------------- + +option "config" - "Config file" string no +option "input" i "Input ROOT filenames" string multiple yes +option "output" o "Output ROOT filename" string yes +option "fastmerge" f "Fast merge" optional +option "verbose" v "Verbose level" int optional +