[TBrowser] Access directories programmatically


I have been recently trying to browse a root file programmatically.
I open a TBrowser with a root file and I would like to navigate through directory and draw an histogram from the TBrowser UI.

Is there a simple way to do this ? I found this but I couldn’t figure out how to retrieve something out of this. BrowseObject (TObject *obj) I would have expected a TBrowser::GetListOfKeys() to get a list of directory to access but this is not the case.

Thank you in advance !

Hello @meyerma ,

TBrowser, as a GUI, is meant to be used interactively. For programmatic access to ROOT file contents, the usual way to go would be writing a small C++ or Python script. You can find many examples in our tutorials and here on the forum.

I hope this helps,

Right, I know how to open and draw.
I actually wanted to be able to pre-open and draw as an helper.
This would speed up the process and avoid browsing by myself.

Thank you for your help.

Hi, the purpose of the browser is to be used interactively, but if files are opened before starting the browser, they appear in the list of files. Getting the list of keys can be done outside the browser, and then you can call the Browse method of the browser on one of the object, but it looks like you’re over-complicating the process. Why not doing that outside the browser, it’s much much easier…


I want to use it interactively, but I want the directory structure on the left panel to « auto-open » without manual action, because I have many subdirectories in my root files.

It would just like to make life much easier when doing on-the-fly analysis. It doesn’t sound over complicate to me.

OK, so to summarize, you want to automatically open all subdirectories in all opened files? I guess that can be done. I’ll have to think a bit about it…

Maybe not all… but yes ! If I can pre-open few specific paths that would be great :slight_smile:

I feel like the more obvious function to use was BrowseObject but I didn’t managed to use it… maybe I am having wrong guess here…


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.