Skip to content

Commit 1fedc8e

Browse files
committed
Update docu
1 parent 3e45171 commit 1fedc8e

File tree

2 files changed

+55
-40
lines changed

2 files changed

+55
-40
lines changed

demo/read_tree.htm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@
3737

3838
selector.Terminate = function(res) {
3939
// function called when processing finishes
40-
if (!res || (cnt===0)) res = "Fail to process TTree";
41-
else res = 'MeanPX = ' + (sumpx/cnt).toFixed(4) + ' MeanPY = ' + (sumpy/cnt).toFixed(4);
40+
if (!res || (cnt===0)) {
41+
res = "Fail to process TTree";
42+
} else {
43+
var meanpx = sumpx/cnt, meanpy = sumpy/cnt;
44+
res = 'MeanPX = ' + meanpx.toFixed(4) + ' MeanPY = ' + meanpy.toFixed(4);
45+
}
46+
4247
document.getElementById('p_ready').innerHTML = res;
4348
}
4449

@@ -56,4 +61,3 @@
5661
</body>
5762

5863
</html>
59-

docs/JSROOT.md

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ Following draw options could be specified (separated by semicolon or ';'):
296296

297297
It is possible to display only part of geometry model. For instance, one could select sub-item like:
298298

299-
- [file=rootgeom.root&item=simple1;1/Nodes/REPLICA_1](https://root.cern/js/latest/?file=../files/geom/rootgeom.root&item=simple1;1/Nodes/REPLICA_1)
299+
- [file=rootgeom.root&item=simple1/TOP/REPLICA_1](https://root.cern/js/latest/?file=../files/geom/rootgeom.root&item=simple1/TOP/REPLICA_1)
300300

301301
Or one can use simple selection syntax (work only with first-level volumes):
302302

@@ -305,8 +305,7 @@ Or one can use simple selection syntax (work only with first-level volumes):
305305
Syntax uses '+' sign to enable visibility flag of specified volume and '-' sign to disable visibility.
306306
One could use wildcard symbol like '+TUBE1*'.
307307

308-
Another way to configure visibility flags is usage of ROOT macros, used to display geometry in ROOT itself.
309-
Example of such macro can be found in root tutorials. Typically it looks like:
308+
Another way to configure visibility flags is usage of ROOT macros, which typically looks like:
310309

311310
{
312311
TGeoManager::Import("http://root.cern/files/alice2.root");
@@ -320,6 +319,8 @@ Example of such macro can be found in root tutorials. Typically it looks like:
320319
new TBrowser;
321320
}
322321

322+
Example of such macro can be found in root tutorials.
323+
323324
From provided macro only following calls will be executed in JSROOT:
324325

325326
* `gGeoManager->DefaultColors()`
@@ -393,17 +394,22 @@ In the `<div>` element with "simpleGUI" id one can specify many custom parameter
393394

394395
## Reading local ROOT files
395396

396-
Due to security reasons it is not allowed to access arbitrary files from local file system.
397-
For instance, for the Chrome browser one could use "--allow-file-access-from-files" option when starting browser
398-
399-
In modern browsers JSROOT can use HTML5 FileReader functionality to access local files.
400-
Major limitation here - user should interactively select files for reading.
397+
JSROOT can read files from local file system using HTML5 FileReader functionality.
398+
Main limitation here - user should interactively select files for reading.
401399
There is button __"..."__ on the main JSROOT page, which starts file selection dialog.
402400
Or one could invoke such dialog with "localfile" parameter in URL string.
403401

404402
- <https://root.cern/js/latest/?localfile>
405403

406-
If valid ROOT file is selected, JSROOT will be able to normally read content of such file.
404+
If valid ROOT file is selected, JSROOT will be able to normally read content of such file.
405+
In some browsers due to security settings automatic popup of file dialog is forbidden, therefore
406+
one may need to press button explicitely.
407+
408+
For debuging purposes one can install JSROOT on local file system and let read ROOT files from the same location. Like:
409+
410+
- <file://home/user/jsroot/index.htm?file=hsimple.root&item=hpx>
411+
412+
But this works only with Firefox.
407413

408414

409415

@@ -441,8 +447,8 @@ The parameter value is the update interval in milliseconds.
441447
### JSON file-based monitoring
442448

443449
Solid file-based monitoring (without integration of THttpServer into application) can be
444-
implemented in JSON format. There is the TBufferJSON class, which is capable to
445-
convert any ROOT object (beside TTree) into JSON. Any ROOT application can use such class to
450+
implemented in JSON format. There is the [TBufferJSON](https://root.cern/doc/master/classTBufferJSON.html) class,
451+
which is capable to convert any (beside TTree) ROOT object into JSON. Any ROOT application can use such class to
446452
create JSON files for selected objects and write such files in a directory,
447453
which can be accessed via web server. Then one can use JSROOT to read such files and display objects in a web browser.
448454

@@ -469,24 +475,14 @@ therefore there is no guarantee that the file content is not changed/replaced be
469475

470476
If somebody still wants to use monitoring of data from ROOT files, could try link like:
471477

472-
- <https://root.cern/js/latest/index.htm?nobrowser&file=../files/hsimple.root+&item=hpx;1&monitoring=2000>
478+
- <https://root.cern/js/latest/?nobrowser&file=../files/hsimple.root+&item=hpx;1&monitoring=2000>
473479

474480
In this particular case, the histogram is not changing.
475481

476482

477-
## Stand-alone usage of JSROOT
478-
479-
Even without any server-side application, JSROOT provides nice ROOT-like graphics,
480-
which could be used in arbitrary HTML pages.
481-
There is [example page](https://root.cern/js/latest/demo/th2.htm),
482-
where a 2-D histogram is artificially generated and displayed.
483-
Details about the JSROOT API can be found in the next chapters.
484-
485-
486483
## JSROOT API
487484

488-
JSROOT can be downloaded from <https://github.com/linev/jsroot>.
489-
It also provided with each ROOT distribution in `etc/http/scripts/` sub-folder.
485+
JSROOT can be used in arbitrary HTML pages and disaplay data, produced without ROOT-based applications.
490486

491487
Many different examples of JSROOT API usage can be found on [JSROOT API examples](https://root.cern/js/latest/api.htm) page.
492488

@@ -527,7 +523,7 @@ When JSROOT installed with bower package manager, one could re-use basic librari
527523

528524
<script type="text/javascript" src="vendor/jsroot/scripts/JSRootCore.js?bower&2d&io"></script>
529525

530-
Bower support will be automatically enabled when script path conatin "bower_components/jsroot/" string.
526+
Bower support will be automatically enabled when script path conatin __"bower_components/jsroot/"__ string.
531527

532528

533529

@@ -538,14 +534,13 @@ THttpServer provides a JSON representation for every registered object with an u
538534

539535
http://your_root_server:8080/Canvases/c1/root.json
540536

541-
Such JSON representation generated using the [TBufferJSON](https://root.cern/root/html/TBufferJSON.html) class. One could create JSON file for any ROOT object directly, just writing in the code:
537+
Such JSON representation generated using the [TBufferJSON](https://root.cern/doc/master/classTBufferJSON.html) class. One could create JSON file for any ROOT object directly, just writing in the code:
542538

543539
...
544540
obj->SaveAs("file.json");
545541
...
546542

547-
To access data from a remote web server, it is recommended to use the [XMLHttpRequest](http://en.wikipedia.org/wiki/XMLHttpRequest) class.
548-
JSROOT provides a special method to create such class and properly handle it in different browsers.
543+
To access data from a remote web server, it is recommended to use the [XMLHttpRequest](http://en.wikipedia.org/wiki/XMLHttpRequest) class. JSROOT provides a special method to create such object and properly handle it in different browsers.
549544
For receiving JSON from a server one could use following code:
550545

551546
var req = JSROOT.NewHttpRequest("http://your_root_server:8080/Canvases/c1/root.json", 'object', userCallback);
@@ -572,6 +567,14 @@ One could use the JSROOT.draw function:
572567
JSROOT.draw("drawing", obj, "colz");
573568

574569
The first argument is the id of the HTML div element, where drawing will be performed. The second argument is the object to draw and the third one is the drawing option.
570+
571+
Here is complete [running example](https://root.cern/js/latest/api.htm#custom_html_read_json) ans [source code](https://github.com/linev/jsroot/blob/master/demo/read_json.htm):
572+
573+
var filename = "https://root.cern/js/files/th2ul.json.gz";
574+
JSROOT.NewHttpRequest(filename, 'object', function(obj) {
575+
JSROOT.draw("drawing", obj, "lego");
576+
}).send();
577+
575578
One is also able to update the drawing with a new version of the object:
576579

577580
// after some interval request object again
@@ -606,13 +609,9 @@ For example, reading an object from a file and displaying it will look like:
606609
JSROOT.draw("drawing", obj, "colz");
607610
});
608611
});
609-
610-
Similar example with JSON file:
611612

612-
var filename = "https://root.cern/js/files/th2ul.json.gz";
613-
JSROOT.NewHttpRequest(filename, 'object', function(obj) {
614-
JSROOT.draw("drawing", obj, "lego");
615-
}).send(null);
613+
Here is [running example](https://root.cern/js/latest/api.htm#custom_html_read_root_file) and [source code](https://github.com/linev/jsroot/blob/master/demo/read_file.htm)
614+
616615

617616

618617
### TTree API
@@ -639,20 +638,32 @@ To get access to selected branches, one should use TSelector class:
639638
selector.AddBranch("px");
640639
selector.AddBranch("py");
641640
641+
var cnt = 0, sumpx = 0, sumpy = 0;
642+
643+
selector.Begin = function() {
644+
// function called before reading of TTree starts
645+
}
646+
642647
selector.Process = function() {
643-
// function called for every read event
644-
console.log(this.tgtobj.px, this.tgtobj.py);
648+
// function called for every entry
649+
sumpx += this.tgtobj.px;
650+
sumpy += this.tgtobj.py;
651+
cnt++;
645652
}
646-
653+
647654
selector.Terminate = function(res) {
648-
// function called when processing finishes
655+
if (!res || (cnt===0)) return;
656+
var meanpx = sumpx/cnt, meanpy = sumpy/cnt;
657+
console.log('Results', meanpx, meanpy);
649658
}
650659
651660
tree.Process(selector);
652661
653662
});
654663
});
655664

665+
Here is [running example](https://root.cern/js/latest/api.htm#custom_html_read_tree) and [source code](https://github.com/linev/jsroot/blob/master/demo/read_tree.htm)
666+
656667
This examples shows how read TTree from binary file and create JSROOT.TSelector object.
657668
Logically it is similar to original TSelector class - for every read entry TSelector::Process() method is called.
658669
Selected branches can be accessed from **tgtobj** data member. At the end of tree reading TSelector::Terminate() method

0 commit comments

Comments
 (0)