Hello,
as mentioned in our previous post (JSROOT download ROOT file displayed in a web page) we are very happy that JSROOT now implements the StoreJSON() function, which allows to get the json representation of a Canvas object.
We load a root file (generated server side with root c++ for cosmic-rays data) and then we display it in on our web page with JSROOT, with the URL?file=… syntax.
This works fine and the user experience is really positive.
Then in the web page with JSROOT we access the Canvas object of the displayed drawing and with ProduceJSON() we get its json representation.
We then send this json representation to the server where we try to parse it in root c++ with code like:
TCanvas * ca = nullptr;
ca = (TCanvas *)TBufferJSON::ConvertFromJSON(json)
or else with
TCanvas * ca1 = nullptr;
TBufferJSON::FromJSON(ca1, json)
In both cases the above parse fails, most commonly with the following error:
root [2] TBufferJSON::ConvertFromJSON(json)
Error in TRint::HandleTermInput(): std::out_of_range caught: key ‘fUniqueID’ not found
We would kindly like to ask you:
-
Are we are doing something wrong ?
-
Is the json generated with JSROOT ProduceJSON() ok for the root c++ code to parse it ? If so, why are we getting the above error ?
We tried a number of different root files, in the end for our tests we resorted to non cosmic ray data, but just a simple canvas with a h1 plot.
To debug the matter I compared:
- the json produced server side with c++ the metod TBufferJSON::ConvertToJSON()
with
-the json produced on the web page with JSROOT ProduceJSON()
The server side json generated (TBufferJSON::ConvertToJSON)is much longer, but I was able to remove quite a big part that is non essential at this point (Palettes mainly) and have it successfully re-parsed with the c++ method TBufferJSON::ConvertFromJSON(json)
In the end I found that the main difference for the json c++ generated and the json JSROOT generated (for the same plot) are in the “fLines”: { sections where:
json for the same plot root c++ generated is:
“fLines”: {
“_typename”: “TList”,
“name”: “TList”,
“arr”: [{
“_typename”: “TLatex”,
“fUniqueID”: 0,
“fBits”: 50331648,
“fName”: “”,
“fTitle”: “h1”,
“fTextAngle”: 0,
“fTextSize”: 0.0368,
“fTextAlign”: 0,
“fTextColor”: 0,
“fTextFont”: 0,
“fX”: 0,
“fY”: 0,
“fLineColor”: 1,
“fLineStyle”: 1,
“fLineWidth”: 2,
“fLimitFactorSize”: 3,
“fOriginSize”: 0.0367999991774559
}, {
json for the same plot JSROOT generated is:
"fLines": {
"_typename": "TList",
"name": "TList",
"arr": [{
"_typename": "TLatex",
"fTitle": "h1",
"fTextColor": 1
}, {
Please can you help us out on this matter ?
Can the JSROOT generated json (JSROOT.ProduceJSON()) be parsed back on the server side with root c++ TBufferJSON::ConvertFromJSON(json) ?
Thank you very much !
L.