Created
December 5, 2014 15:08
-
-
Save KonstantinSchubert/bb586f15b85a06b70869 to your computer and use it in GitHub Desktop.
CERN ROOT: A function that gets the first tree out of a .root -file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TTree* getAnyTree(TDirectory* dirHandle){ | |
// Returns a pointer to a TTree from within the file. Useful if you know there is only one tree in the file, but don't knowe which and where exactly. | |
// within ROOT, a TTree is a TObject and a TDirectory is a TObject. But a Tree is not a TDirectory and vice versa. | |
TObject* objectHandle = NULL; | |
do{ | |
const char* key = dirHandle->GetListOfKeys()->At(0)->GetName(); // Get the first key in the directory | |
objectHandle = dirHandle->Get(key); // Get the first object. | |
dirHandle = dynamic_cast<TDirectory*> (objectHandle); // try to cast object into directory | |
}while( dirHandle!=NULL); // If it can be casted into a TDirectory we didn't yet find what we were looking for. | |
return dynamic_cast<TTree*> (objectHandle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment