I would like to loop on the data objects of a TFile, and handle histograms and subdirectories differently:
This example - which I tested with a file with many direstories in it - supposed to read in a file and print out the content type. However, it fails to do so and prints 0-s for the directory entries.
I think you got it right. You can speed up the dynamic_cast, but here we are talking about 2nd order refinements, especially at this level, exploiting ROOT reflection (key->GetClassName() - see for example Finding all objects in a root file, regardless of directries)
But it does not work, is_directory is 0 even for directories. Also, I get this error for the GetKeyName() approach: 'class TObject' has no member named 'GetClassName'
I am not sure how ROOT handles the memory in this case, i.e., if each call to ReadObj returns a new object, or whether the old one is recycled. In any case, as you first have to get the complete object from file, and not just some metadata, this approach will perform worse than what Danilo proposed.