Closed mrceyhun closed 12 months ago
hi,
(apologies for the belated answer)
wrt question 1, in groot we have riofs.Dir
that returns a recursive-able riofs.Directory
value:
https://pkg.go.dev/go-hep.org/x/hep@v0.33.0/groot/riofs#Dir
f, err := groot.Open("dqm.root")
handle(err)
o, err := riofs.Dir(f).Get("DQMData/Run 366713/EcalPreshower/Run summary/ESRecoSummary/recHits_ES_energyMax")
handle(err)
h, ok := o.(rhist.H1)
or, using Go generics (w/ Go>=1.18):
f, err := groot.Open("dqm.root")
handle(err)
h, err := riofs.Get[rhist.H1].Get(riofs.Dir(f), "DQMData/Run 366713/EcalPreshower/Run summary/ESRecoSummary/recHits_ES_energyMax")
handle(err)
As for question 2, groot doesn't have such a thing (yet?).
if all you want is to be able to plot a couple of histograms from a couple of ROOT files, you could perhaps reuse some of the functions used by root-srv
:
https://pkg.go.dev/go-hep.org/x/hep@v0.33.0/groot/rsrv
let me know if you need more guidance.
is it for integration with a CMS monitoring tool (K8s-based ?)
one could perhaps implement a ROOT-TH{1,2}x
to JSON
facility
Very life saving info of riofs.Dir
feature.
This is not for CMS monitoring actually. I am evaluating Go option for a project of CMS PPD, not a big project. PyROOT and C++ options are working fine but since I'll run it in K8s , I wanted to give it a try to go-hep libs.
If I can find free time, I can try to convert ROOT-TH{1,2}x
to JSON
. If I it works, I can open an issue to discuss it.
Because this is a question issue and I don't have any further questions, issue is closable. Thanks a lot @sbinet !
the rhist.H{1,2}x
code is heavily generated (as you may have guessed).
but once you get, say, rhist.H1D
implemented, we can port it to the generation code scaffolding.
I'd suggest to implement this as a MarshalJSON/UnmarshalJSON
pair of methods.
(but that would only tackle the histogram part. not the styles, colors, points, plot title, etc...)
alternatively, one could address the problem one level down: at the gonum/plot layer. there is a "canvas recorder" tool that can record canvas in "ASCII" form:
one could use a similar implementation (say, vgjson
or something) to save the whole thing in JSON.
(this could be tucked under go-hep.org/x/hep/hplot
)
closing in favour of https://github.com/go-hep/hep/issues/982
I have 2 questions which are related with each other. I have a local root file, let's say
dqm.root
, and it includes so many objects/plots.Q-1 How can I get the object using
goroot
?In PyROOT, we can get it like:
In goroot, I could not find an easy way and write my function like below. I think that there should be a better way. And I am open your suggestions for type casting for ROOT objects.
Q-2 How can I convert or save a plot/object as a JSON?
In PyROOT, there is a SaveAs functionality and saves a plot as JSON. However, I searched almost all go-hep and could not find any hint.
What I want to do is finding a plot inside many ROOT files and run a Go web server as a backend to serve them. I cannot use root-srv (AFAIU) because I am only interested with a couple of plots from different big ROOT files instead of plots of a single ROOT file.
P.s.: Sorry for my ROOT Jargon which I'm not that familiar.
Many thanks in advance!