-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
groot/rjson: first import #994
Conversation
Signed-off-by: Sebastien Binet <[email protected]>
Signed-off-by: Sebastien Binet <[email protected]>
Fixes go-hep#991. Signed-off-by: Sebastien Binet <[email protected]>
^^ @mrceyhun WDYT ? (I have only implemented a (possibly narrow) subset of // Copyright ©2023 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rjson_test
import (
"bytes"
"encoding/json"
"fmt"
"log"
"go-hep.org/x/hep/groot/rhist"
"go-hep.org/x/hep/groot/rjson"
"go-hep.org/x/hep/hbook"
)
func ExampleMarshal() {
h := hbook.NewH1D(5, 0, 5)
h.Fill(1, 1)
h.Fill(-1, 1)
h.Ann["name"] = "h1"
h.Ann["title"] = "my title"
raw, err := rjson.Marshal(rhist.NewH1FFrom(h))
if err != nil {
log.Fatalf("could not marshal to ROOT JSON: %+v", err)
}
buf := new(bytes.Buffer)
err = json.Indent(buf, raw, "", " ")
if err != nil {
log.Fatalf("could not indent JSON: %+v", err)
}
fmt.Printf("json: %s\n", buf.String())
// Output:
// json: {
// "_typename": "TH1F",
// "fUniqueID": 0,
// "fBits": 50331648,
// "fName": "h1",
// "fTitle": "my title",
// "fLineColor": 602,
// "fLineStyle": 1,
// "fLineWidth": 1,
// "fFillColor": 0,
// "fFillStyle": 1001,
// "fMarkerColor": 1,
// "fMarkerStyle": 1,
// "fMarkerSize": 1,
// "fNcells": 7,
// "fXaxis": {
// "_typename": "TAxis",
// "fUniqueID": 0,
// "fBits": 50331648,
// "fName": "xaxis",
// "fTitle": "",
// "fNdivisions": 510,
// "fAxisColor": 1,
// "fLabelColor": 1,
// "fLabelFont": 42,
// "fLabelOffset": 0.005,
// "fLabelSize": 0.035,
// "fTickLength": 0.03,
// "fTitleOffset": 1,
// "fTitleSize": 0.035,
// "fTitleColor": 1,
// "fTitleFont": 42,
// "fNbins": 5,
// "fXmin": 0,
// "fXmax": 5,
// "fXbins": [
// 0,
// 1,
// 2,
// 3,
// 4,
// 5
// ],
// "fFirst": 0,
// "fLast": 0,
// "fBits2": 0,
// "fTimeDisplay": false,
// "fTimeFormat": "",
// "fLabels": null,
// "fModLabs": null
// },
// "fYaxis": {
// "_typename": "TAxis",
// "fUniqueID": 0,
// "fBits": 50331648,
// "fName": "yaxis",
// "fTitle": "",
// "fNdivisions": 510,
// "fAxisColor": 1,
// "fLabelColor": 1,
// "fLabelFont": 42,
// "fLabelOffset": 0.005,
// "fLabelSize": 0.035,
// "fTickLength": 0.03,
// "fTitleOffset": 1,
// "fTitleSize": 0.035,
// "fTitleColor": 1,
// "fTitleFont": 42,
// "fNbins": 1,
// "fXmin": 0,
// "fXmax": 1,
// "fXbins": [],
// "fFirst": 0,
// "fLast": 0,
// "fBits2": 0,
// "fTimeDisplay": false,
// "fTimeFormat": "",
// "fLabels": null,
// "fModLabs": null
// },
// "fZaxis": {
// "_typename": "TAxis",
// "fUniqueID": 0,
// "fBits": 50331648,
// "fName": "zaxis",
// "fTitle": "",
// "fNdivisions": 510,
// "fAxisColor": 1,
// "fLabelColor": 1,
// "fLabelFont": 42,
// "fLabelOffset": 0.005,
// "fLabelSize": 0.035,
// "fTickLength": 0.03,
// "fTitleOffset": 1,
// "fTitleSize": 0.035,
// "fTitleColor": 1,
// "fTitleFont": 42,
// "fNbins": 1,
// "fXmin": 0,
// "fXmax": 1,
// "fXbins": [],
// "fFirst": 0,
// "fLast": 0,
// "fBits2": 0,
// "fTimeDisplay": false,
// "fTimeFormat": "",
// "fLabels": null,
// "fModLabs": null
// },
// "fBarOffset": 0,
// "fBarWidth": 1000,
// "fEntries": 2,
// "fTsumw": 2,
// "fTsumw2": 2,
// "fTsumwx": 0,
// "fTsumwx2": 2,
// "fMaximum": -1111,
// "fMinimum": -1111,
// "fNormFactor": 0,
// "fContour": [],
// "fSumw2": [
// 1,
// 0,
// 1,
// 0,
// 0,
// 0,
// 0
// ],
// "fOption": "",
// "fFunctions": {
// "_typename": "TList",
// "name": "",
// "arr": [],
// "opt": []
// },
// "fBufferSize": 0,
// "fBuffer": [],
// "fBinStatErrOpt": 0,
// "fStatOverflows": 2,
// "fArray": [
// 1,
// 0,
// 1,
// 0,
// 0,
// 0,
// 0
// ]
// }
} |
^^ @mrceyhun ping ? was this useful ? BTW, do you have a link to the repo that uses |
@sbinet sorry for the delay. I had to finish the project quickly and I could not have much time to use go-hep tools. I implemented required functionalities with PyROOT. May be I can replace PyROOT backend with go, so replace PyROOT with go-root. I'll give it try in my free time. I don't know your future plan, most probably I'll need JSON representations of TH2F, TProfile and THStack too in my tests. Please note that no guarantee that this will go in production. That's why you can drop the request as you wish, no hard feeling :) |
Fixes #991.