I’m a beginner when it comes to root, and I have a problem.
I’m trying to get the the type of a branch and don’t know how to. I can use the TBrach::Print() function to see it but not get it and i don’t want to parse the string.I have seen that there is a function(GetTypeName) in the TBranchElement class but don’t know how to use it.
So is there a easy way to get the type from a branch?
The means to retrieve the type a branch slightly depends on the type of TTree you have.
More importantly, what are you trying to accomplish (they are many tools that may already provide the functionality you are looking for).
What i’m trying to do is a wrapper to root, so you can search a root file like a database. What i need to do is to have function that takes a tree and return all variable names and types.
[quote]so you can search a root file like a database. [/quote]Did you look at TTree::Query?
[quote]What i need to do is to have function that takes a tree and return all variable names and types. [/quote]To do it in a generic way is not trivial. See the method TTreePlayer::MakeClass and the class ROOT::TTreeProxyGenerator for a couple of example.
Not quite … In your example the leaf is not a TLeafObject and doing
leafobj = (TLeafObject*)leaf;is technically wrong.
On the positive side, you can actually do
leaf->GetTypeName();
directly.
Also you can ask for the list of leaves
t->GetListOfLeaves();You can then iterate through each leaves of the TTree (See User’s Guide collection for details on how to iterate through a collection) and call GetTypeName on each.