Use JSROOT viewer to read a local file

@linev , I am creating a web application which will render a .root file in client application, when the user chooses to open the file. For this I have to use JSROOT. The server is written in golang. How can I send request to JSROOT from server, to read a local file and send the response which will then be rendered on client side.
I tried to create a golang FileServer and use JSROOT to read a remote file, but it doesn’t seem to work.
Please suggest how I can achieve this?

Regards,
Mohit

hi @Mohit,

alternatively, there’s a Go package that can expose HTTP/2 endpoints to read ROOT files (local or remote over xrootd):

and a Go binary that packages everything up:

(CMS is using parts of that for one of their DL/ML projects)

hth,
-s

Hi @Mohit ,

First of all, you need to provide HTTP or HTTPs server, which can serve your ROOT files.
Check how it works, just using wget or curl utility.
Once your server is working, you could try to open file with normal JSROOT webpage like this is doing:
https://root.cern/js/latest/?nobrowser&file=https://root.cern/js/files/hsimple.root&item=hpxpy;1&opt=colz

But in this case you must be aware about CORS limitations: https://github.com/root-project/jsroot/blob/master/docs/JSROOT.md#reading-root-files-from-other-servers

In principal, you could avoid CORS problem by installing JSROOT on your server and using it like:
http://your_server/jsroot/?file=http://your_server/files/abc.root&item=...

Last your question - how to trigger reading and drawing from the server?
Here you need to implement some HTML/JavaScript code yourself.
In this code your should request server when data is there - this is fully application-specific.
Once data can be displayed, just use small JSROOT-based code to load and displayed data as described here: https://github.com/root-project/jsroot/blob/master/docs/JSROOT.md#file-api

Regards,
Sergey

@sbinet Thank you for your opinion, but I need to use JSROOT only. I have to demonstrate something using it :slightly_smiling_face:

Thanks @linev The first solution works. I created a file server. I tried that before as well but I was not specifying the item parameter in url earlier, that’s why nothing was showing up.
Regards,
Mohit

@linev I face another problem using this. I have a golang web service which is hosted at something like http://localhost:9998/open/file.root. In the service code I make an http request to jsroot using http.Get as follows:
resp, err := http.Get("https://root.cern/js/latest/?file=http://localhost:8100/file.root&item=c1;1").
http://localhost:8100 is the location of file server.So I use the filename provided in the first url (the service endpoint) and make a get request to jsroot.
When I navigate to the url: https://root.cern/js/latest/?file=http://localhost:8100/file.root&item=c1;1 in the browser, it loads the file. But when I make a request in golang as above it doesn’t load. When I looked in the network console, the jsroot application redirects to different urls which uses the same origin and path as the one in browser (the service endpoint) and not the one in get request. So, in my case the following are the redirected urls:
http://localhost:9998/open/scripts/JSRootCore.min.js?gui
and similar. When I navigate to the same url in browser the corresponding url is
https://root.cern/js/latest/scripts/JSRootCore.min.js?gui
The origin is the one in browser and not the code.
How do I get around with this?
Thanks,
Mohit

Hi,

resp, err := http.Get("https://root.cern/js/latest/?file=http://localhost:8100/file.root&item=c1;1")

That kind of result you expect to get by such action?

Hi, Please suggest other ideas. I need to create a service that returns the response to be loaded on the client side, which is to read a root file. Is it not possible without installing jsroot on the server?

Installing of JSROOT on the server is trivial - just unpack tarball in any sub-directory, which is accessible through web server.

Typically web server returns html pages. You can do custom HTML page inserting there reference to actual ROOT file. Like in this example: Reading object from the ROOT file
More examples you will find here: JavaScript ROOT API examples

Hi @linev , one more thing. What if the remote file server uses authentication for allowing to read the file. How can jsroot send authentication token along with the request to open file?

Hi,

Up to now there is not special functionality in JSROOT to handle authentication - there are too many different methods. If you do have special requirement, probably one can add extra feature to JSROOT.

Regards,
Sergey