You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
542
538
543
539
...
544
540
obj->SaveAs("file.json");
545
541
...
546
542
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.
549
544
For receiving JSON from a server one could use following code:
550
545
551
546
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:
572
567
JSROOT.draw("drawing", obj, "colz");
573
568
574
569
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";
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
+
616
615
617
616
618
617
### TTree API
@@ -639,20 +638,32 @@ To get access to selected branches, one should use TSelector class:
639
638
selector.AddBranch("px");
640
639
selector.AddBranch("py");
641
640
641
+
var cnt = 0, sumpx = 0, sumpy = 0;
642
+
643
+
selector.Begin = function() {
644
+
// function called before reading of TTree starts
645
+
}
646
+
642
647
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++;
645
652
}
646
-
653
+
647
654
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);
649
658
}
650
659
651
660
tree.Process(selector);
652
661
653
662
});
654
663
});
655
664
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
+
656
667
This examples shows how read TTree from binary file and create JSROOT.TSelector object.
657
668
Logically it is similar to original TSelector class - for every read entry TSelector::Process() method is called.
658
669
Selected branches can be accessed from **tgtobj** data member. At the end of tree reading TSelector::Terminate() method
0 commit comments