From 2546511d8aaa6f88c0abe39c84f9bdbce83a04d4 Mon Sep 17 00:00:00 2001 From: Pierre Gueth Date: Mon, 4 Feb 2013 13:18:11 +0100 Subject: [PATCH] variable name set --- tests_dav/clitkMergeRootFiles.cxx | 86 ++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 14 deletions(-) diff --git a/tests_dav/clitkMergeRootFiles.cxx b/tests_dav/clitkMergeRootFiles.cxx index 86887f0..5b62d84 100644 --- a/tests_dav/clitkMergeRootFiles.cxx +++ b/tests_dav/clitkMergeRootFiles.cxx @@ -14,13 +14,60 @@ #include #include #include +#include #include #include +#include +#include #include +#include using std::endl; using std::cout; +typedef std::list Strings; +typedef std::list Handles; +typedef std::set StringsSet; + +void mergePetRoot(const Strings& input_filenames, const std::string& output_filename) +{ + TFile* output_handle = TFile::Open(output_filename.c_str(),"RECREATE"); + + Handles input_handles; + StringsSet tree_names; + StringsSet h1_names; + StringsSet h2_names; + for (Strings::const_iterator iter=input_filenames.begin(); iter!=input_filenames.end(); iter++) + { + TFile* handle = TFile::Open(iter->c_str(),"READ"); + assert(handle); + + TIter key_next(handle->GetListOfKeys()); + while (TKey* key = static_cast(key_next())) + { + const std::string name = key->GetName(); + const bool is_tree = key->ReadObj()->InheritsFrom("TTree"); + const bool is_h1 = key->ReadObj()->InheritsFrom("TH1"); + const bool is_h2 = key->ReadObj()->InheritsFrom("TH2"); + if (is_tree) tree_names.insert(name); + if (is_h1) h1_names.insert(name); + if (is_h2) h2_names.insert(name); + } + + input_handles.push_back(handle); + } + + cout << "found " << tree_names.size() << " tree "<< h1_names.size() << " histo1d " << h2_names.size() << " histo2d" << endl; + + + for (Handles::const_iterator iter=input_handles.begin(); iter!=input_handles.end(); iter++) + { + (*iter)->Close(); + delete *iter; + } +} + + //----------------------------------------------------------------------------- int main(int argc, char * argv[]) { @@ -35,21 +82,32 @@ int main(int argc, char * argv[]) { FATAL("Error, please provide at least two inputs files"); } - // Detect Pet output - bool all_pet_output = true; - 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 << endl; - handle->Close(); - delete handle; - all_pet_output &= is_pet_output; + { // Detect Pet output + bool all_pet_output = true; + Strings input_filenames; + 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 << endl; + handle->Close(); + delete handle; + all_pet_output &= is_pet_output; + } + cout << "all_pet_output " << all_pet_output << endl; + + if (all_pet_output) + { + mergePetRoot(input_filenames,args_info.output_arg); + return 0; + } } - cout << "all_pet_output " << all_pet_output << endl; + // Merge TFileMerger * merger = new TFileMerger; -- 2.47.1