Best way to discover ROOT object type

Hello rooters,

I’ve searched awhile and couldn’t find a specific topic on this thread: what is the best root way to check if object is from specific type?

I know that I can use obj->ClassName and compare it to the string, however it seems that there may be a better way for doing that.

Specially, I want to loop over TList objects and check them if they are of a specific type, say: TDirectory.

Thanks in advance,
Werner.

1 Like

For instance, if you want to test if obj is a TH1D, you can do:

obj->InheritsFrom(TH1D::Class());
1 Like

And to check if the object is a (and not only inherits from) TDirectory:

Cheers, Bertrand.