go-hep.org/x/hep@v0.38.1/fwk/hsvc.go (about) 1 // Copyright ©2017 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package fwk 6 7 import ( 8 "go-hep.org/x/hep/hbook" 9 ) 10 11 // Hist is a histogram, scatter or profile object that can 12 // be saved or loaded by the HistSvc. 13 type Hist interface { 14 Name() string 15 Value() any 16 } 17 18 // HID is a histogram, scatter or profile identifier 19 type HID string 20 21 // H1D wraps a hbook.H1D for safe concurrent access 22 type H1D struct { 23 ID HID // unique id 24 Hist *hbook.H1D 25 } 26 27 func (h H1D) Name() string { 28 return string(h.ID) 29 } 30 31 func (h H1D) Value() any { 32 return h.Hist 33 } 34 35 // H2D wraps a hbook.H2D for safe concurrent access 36 type H2D struct { 37 ID HID // unique id 38 Hist *hbook.H2D 39 } 40 41 func (h H2D) Name() string { 42 return string(h.ID) 43 } 44 45 func (h H2D) Value() any { 46 return h.Hist 47 } 48 49 // P1D wraps a hbook.P1D for safe concurrent access 50 type P1D struct { 51 ID HID // unique id 52 Profile *hbook.P1D 53 } 54 55 func (p P1D) Name() string { 56 return string(p.ID) 57 } 58 59 func (p P1D) Value() any { 60 return p.Profile 61 } 62 63 // S2D wraps a hbook.S2D for safe concurrent access 64 type S2D struct { 65 ID HID // unique id 66 Scatter *hbook.S2D 67 } 68 69 func (s S2D) Name() string { 70 return string(s.ID) 71 } 72 73 func (s S2D) Value() any { 74 return s.Scatter 75 } 76 77 // HistSvc is the interface providing access to histograms 78 type HistSvc interface { 79 Svc 80 81 // BookH1D books a 1D histogram. 82 // name should be of the form: "/fwk/streams/<stream-name>/<path>/<histogram-name>" 83 BookH1D(name string, nbins int, xmin, xmax float64) (H1D, error) 84 85 // BookH2D books a 2D histogram. 86 // name should be of the form: "/fwk/streams/<stream-name>/<path>/<histogram-name>" 87 BookH2D(name string, nx int, xmin, xmax float64, ny int, ymin, ymax float64) (H2D, error) 88 89 // BookP1D books a 1D profile. 90 // name should be of the form: "/fwk/streams/<stream-name>/<path>/<profile-name>" 91 BookP1D(name string, nbins int, xmin, xmax float64) (P1D, error) 92 93 // BookS2D books a 2D scatter. 94 // name should be of the form: "/fwk/streams/<stream-name>/<path>/<scatter-name>" 95 BookS2D(name string) (S2D, error) 96 97 // FillH1D fills the 1D-histogram id with data x and weight w. 98 FillH1D(id HID, x, w float64) 99 100 // FillH2D fills the 2D-histogram id with data (x,y) and weight w. 101 FillH2D(id HID, x, y, w float64) 102 103 // FillP1D fills the 1D-profile id with data (x,y) and weight w. 104 FillP1D(id HID, x, y, w float64) 105 106 // FillS2D fills the 2D-scatter id with data (x,y). 107 FillS2D(id HID, x, y float64) 108 } 109 110 var _ Hist = (*H1D)(nil) 111 var _ Hist = (*H2D)(nil) 112 var _ Hist = (*P1D)(nil) 113 var _ Hist = (*S2D)(nil)