Open .root file with double click

I need to inspect a lot of .root files for my thesis.

So far my procedure to open .root files is the following:

  1. open terminal
  2. type “root”
  3. press enter
  4. type “new TBrowser”
  5. Search file in the TBrowser
  6. Double click on the root file in the TBrowser.

This is very tedious and time-consuming.
Does anyone know how to make this process more efficient?
My ideal case would be that the TBrowser opens the .root file automatically when I double click it in the Ubuntu file explorer.
Does anyone know what I could do to open the TBrowser by double clicking on a .root file?

_ROOT Version: 6.24/00
_Platform: Ubuntu 20.10
Compiler: Not Provided

Hi,
from the commandline, rootbrowse filename.root should do the job.

You can probably configure your environment so that rootbrowse is launched when you double-click on a root file, e.g. via mimetype etc.

You might also be interested in this blog post (" View ROOT Files directly in VS Code!")

Cheers,
Enrico

When I try the command rootbrowse output.root
I get the error:
/usr/bin/env: '/root/stage/bin/python3': Permission denied

" You can probably configure your environment so that rootbrowse is launched when you double-click on a root file, e.g. via mimetype etc."

This is exactly what I am asking for, because I have no clue how to do it.
Has anyone been able to do that?
I am a Linux beginner and don’t even know what I have to google to get help with this.

I just tried the command mimeopen:
This is the error I get:

Opening "output.root" with ROOT  (application/x-root)
Error: Failed to execute child process “/usr/bin/root”: Failed to execve: No such file or directory

That looks like a problem with the snap package for ROOT, I’ll take a look at it!

The snap version of ROOT is usually found at /snap/bin/root, so you’d need to point it there instead (or /snap/bin/rootbrowse, once it’s working).

Unfortunately I’m not sure how exactly how to manually change the associations on Ubuntu, though it might be possible for the snap to do it automatically in the future.

2 Likes

Would it help if I try a different Root version?
Which one should I try?

The conda and official precompiled binary packages rootbrowse should work, but to get them to work with MIME types you’d also need to add them to .bashrc at a minimum, and possibly more involved depending just on how the desktop environment interactions work.

If you’re willing to wait, I’ll likely have a patched version of the snap released and distributed within a few hours.

1 Like

About this, it’s 100% possible. I don’t know the full procedure off the top of my head but you can certainly find tutorials on the internet, e.g. 18.04 - How to associate a file extension to a non-GUI app in Ubuntu 18 Nautilus? - Ask Ubuntu or How do I (persistently) change default file/program associations in Ubuntu 18.04+? - Ask Ubuntu

So locally I’ve managed to fix rootbrowse, however I also accidentally built the nightly build rather than 6-24-00 so I’ll have to spend some time compiling it again.

What I did notice, the nightly release opens up RBrowser rather than TBrowser, which is unfortunate because the HTTP server RBrowser utilises is killed instantly and means that the web browser opens with nothing to connect to. Is this something that upstream is aware of/has a solution to? It works as expected when invoked in the terminal properly and only fails if set to open with double clicks.

Otherwise sorry for the wait but it shouldn’t be too long now.

We switched to using RBrowser by default in master to expose expert/brave users to the feature and get some usage feedback. “RBrowser is broken on snap” is great such feedback! :smiley: Can you please open a github issue where we can follow up on that properly?

Cheers,
Enrico

Having tried again on 6-24, it doesn’t appear the problem is with RBrowser , rootbrowse even with the TBrowser backend will also close itself before being usable, it seems the problem is simply there’s a “Press enter to exit” prompt that doesn’t get triggered when run via double clicking, meaning it’s not as simple as making a mime type and associating rootbrowse to *.root files.

@Fetz
If you run sudo snap refresh now, you should update to the latest package where rootbrowse will work in the terminal properly. Unfortunately I’m unsure how to recommend making *.root files open with just a double click.

Thank you @James-Carroll for the amazing support!

I am now on Root 6.24 and the rootbrowse command opens the browser directly, which already simplifies my workflow.

There is a workaround for Linux users. If you add Terminal=true to the desktop launcher then ROOT session will run in a Terminal window and TBrowser window will stay open.

It is rather useful to run TBrowser in terminal window because you can right-click and dump ROOT objects in the Terminal output. My rootbrowse launcher looks like this:

[Desktop Entry]
Type=Application
Name=ROOT Browser
Comment=Open CERN ROOT files
Icon=gnome-cernroot
Exec=rootbrowse %F
Terminal=true
Categories=Science

Please refer to the freedesktop launcher specification here. This should work in KDE and GNOME desktop environments and derivatives.

2 Likes

Thanks for the useful contribution, @petrstepanov.

1 Like

Thank you @petrstepanov
Now I have a desktop icon that launches a TBrowser.
But is there also a way to associate this launcher with the filetype .root?
Because now I still have to navigate to the root file that I want to open inside the TBrowser.
More convenient would be to have the TBrowser directly open a .root file when double clicking on it.
But I don’t know how to add the TBrowser to the “Open With” menu.

Hi @Fetz ,

The XDG standard allows a user to add custom MIME-type associations. Quite probably, your system’s file browser (nautilus?) should allow you to do it via the GUI.

If that is not the case, you can always add a new file association to the .config/mimeapps.list file. In particular, you should add a new line under the [Added Associations] section, as follows:

application/x-root=/path/to/the/xdg-desktop-file-that-you-have.desktop

Depending on your desktop environment you might need to logout/re-login for the file browser to pick your changes.

Cheers,
J.

1 Like

Indeed, program associations for registered MIME types are edited in .config/mimeapps.list. However, this requires the ROOT MIME type application/x-root to be registered in your linux MIME database.

For instance, on my computer (Fedora 33, GNOME 3.38 , ROOT v.6.22.08 built from source) the above MIME type is not registered by default. In this case one would have to first add corresponding MIME type to the system. There is a guide on GNOME help page.

I could not find out how to do it via the GUI, but I added the line to the mimeaps.list and now the TBrowser actually launches when I double click on a .root file!
This is what I was asking for!
Thank you very much @jalopezg and @petrstepanov

I am only wondering why this is not a default feature.
What does the workflow of other people look like that this feature is not set up by default?

I definitely support this idea. On Linux platform default command for installing the launcher is xdg-desktop-menu install <launcher-location>. Launcher’s icon can be installed with xdg-icon-resource install .... Both of these commands can be added to the install target of CMakeLists.txt and launcher will work.

But since ROOT is a cross-platform toolkit, technically this feature must be addressed for other platforms like MacOS, Windows. To my understanding on MacOS you can create an AppleScript launcher that will run a Terminal command. Then package and install it as an application. I have no idea how this works on Windows though.

Thanks for the hints above with the desktop file, knowing it works with Terminal=True means I’ll be sure to keep an eye out for the blocker in the future!

Snaps can add .desktop files to the system (e.g., I do add root itself to the start menu already), but adding new MIMEtypes entirely isn’t facilitated yet. It’s on the backlog of work upstream but until it’s done upstream the security models in place don’t give a choice, and testing on Ubuntu, x-root isn’t a default MIME there either, and so presumably also isn’t in its derivatives.

I couldn’t say why it isn’t in other peoples packages, but if in the future it becomes possible to do it automatically in a snap I will, but this future might be years away because it’s unfortunately low ranking on upstreams todo list.

1 Like