Get Key Class Type (char*)?

Hello,

I’m writing a macro that I want to scan a bunch of files (all with the same exact makeup of data), grab the trees, and make chains out of all of them. But rather than knowing the names of the trees before hand, I’d like my macro to just see what they are and make the chains accordingly.

If I open a Tfile f1 and do:

f1->ls();

I can see all the keys and their class types (TTree for some, TObjArray for others). I can grab the names of them all too, with

for every ith one. But how do I get what it’s class type is? I want something like

if(f1->GetListOfKeys()->At(i)->GetClassType() == "TTree") //do something...

I feel like this should be easy, but I’m just not finding the right function in the documentation. Thanks in advance!

root.cern.ch/root/html/TKey.htm … tClassName

Thank you. Hmm… I did try that one but I always get a

Error: Can't call TObject::GetClassName() in current scope chain_trees.C:78: Possible candidates are... Error: non class,struct,union object At(j) used with . or -> chain_trees.C:78:

I’m probably doing something silly… any ideas?

Got it working. Didn’t realize At(j) returned a TObject* instead of a TKey*. I did a static recast. Thanks for the help, bellenot; you got me pointed in the right direction.