#include #include "Riostream.h" #include #include #include "TDirectory.h" #include "TKey.h" #include "TList.h" #include "TObject.h" void test_navigator(TKey* top_key) { TObject* top_obj = top_key->ReadObj(); TDirectory *top_dir = 0; if (top_obj->InheritsFrom("TDirectory")) { top_dir = dynamic_cast(top_obj); } else { cout << "Wrong top Key !!" << endl; return; } string dir_name = top_dir->GetTitle(); if (dir_name.find("module_") != string::npos) { cout << "TDirectory " << top_dir->GetName() << " found" << endl; // do what as to be done with the content of this TDirectory whose name is "module_*" } else { TList* list = top_dir->GetListOfKeys(); for (int i = 0; i < list->GetSize(); i++) { TKey *key = dynamic_cast(list->At(i)); TObject* obj = key->ReadObj(); if (obj->InheritsFrom("TDirectory")) { // delete obj; <----- Should I add this ??? This should delete TDirectory objects // since navigation is done with TKey's test_navigator(key); } else { delete obj; // <--- This delete objects which are NOT TDirectory's (histograms,...) } } } // delete top_obj; <----- Should I add this ??? This should delete the TDirectory when all the TDirectory downstream // have been explored }