TFile *f = new TFile(filename);
TTree* tree = (TTree*)gDirectory->Get("EventDump");
what happens if the name “EventDump” change? How can I write a code that open the only TTree that is inside f without the knowledge of the name (“EventDump”)?
Simply loop on the list of keys (TKeys) on this file, check if the class corresponding to the key is a TTree, if yes the Tree name is the name of the key, eg
TTree *tree=0;
TKey *key;
TIter next(f->GetListOfKeys());
while ((key=(TKey*)next())) {
if (!strcmp(key->GetClassName(),"TTree")) {
//I have found the first Tree
tree = (TTree*)f->Get(key->GetName());
break;
}
}
Rene