Design-time specifying hists to draw with ROOTjs class

Dear all, (cc Bertrand Bellenot)

I have been reading over the nice root.cern.ch/js/ code and would like to use it to display monitoring histograms for a web tool I am developing.

I want to specify in javascript (written by PHP) a ROOT file & TDirectory and then plot all histograms within.

My problem is that the gFile class reads the remote data via AJAX, if I send the commands in quick succession in a script or via the JS console then they fail.

What is the best way to approach this? I have tried to use event handlers but haven’t made any good progress.

Thanks,
Tim.

Hi Tim,

[quote=“tamartin”]My problem is that the gFile class reads the remote data via AJAX, if I send the commands in quick succession in a script or via the JS console then they fail.[/quote]I’m not sure I really understand what you mean (JSRootIO itself doesn’t use AJAX) and how you implemented your prototype…
One possible alternative would be to use the dynamic approach, with monitoring option, with the new http server as described in these release notes, and with more details in the HttpServer manual
(and I will reply to your mail too)

Cheers, Bertrand.

Thanks Bertrand,

I think an example is in order.

I was trying to start to modify root.cern.ch/js/ to automatically run the commands

AssertPrerequisites(); gFile.ReadDirectory("summary",1,2); gFile.ReadObject("summary/h_eventsPerLumiblock",1);
However the reading happens asynchronously so this does not work.

One very inelegant solution on tim-martin.co.uk/files/rootjs/JS … index2.htm is to wait for 1s between each command, but I was hoping there is a better and safer solution than this.

window.onload = function () { AssertPrerequisites(); window.setTimeout(doReadDir,1000); } function doReadDir() { gFile.ReadDirectory("summary",1,2); window.setTimeout(doReadPlot,1000); } function doReadPlot() { gFile.ReadObject("summary/h_eventsPerLumiblock",1); }

Thanks,
Tim.

Hi Tim,

OK, in this case, you can use (create your own) userCallback(file); function. This is a user defined callback function, that will be called at the end of the file reading callback (requested by CMS).
HTH

Cheers, Bertrand.

Cheers Bertrand,

That callback has got me opening the directory.

I need to work on then calling the plot to display - but I know where to look now and where I may need to insert some more callbacks.

Will play around with the code some more.
Tim.

Cheers Bertrand,

Just in case of use to others, I had to add two more callbacks, function userReadKeyCallback(file) in JSROOTIO.TDirectory.prototype.ReadKeys -> var callback2 = function(file, buffer, _dir) and function userObjBufferCallback(file) in JSROOTIO.RootFile.prototype.ReadObjBuffer -> var callback1 = function(file, buffer)

I can then draw all histograms in the folder specified in the nav array with the following (note this does not also populate the directory tree as dir_id is not properly passed to ReadDirectory, but this was not important to me).

[code]

[/code]