-
Notifications
You must be signed in to change notification settings - Fork 35
/
rootio.go
315 lines (263 loc) · 7.22 KB
/
rootio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// Copyright 2017 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 rootio
import (
"reflect"
)
const (
rootVersion = 61206 // ROOT version the Go-HEP/rootio library implements
)
//go:generate go run ./gen-code.go
//go:generate go run ./gendata/gen-evnt-tree.go -f ./testdata/small-evnt-tree-nosplit.root
//go:generate go run ./gendata/gen-evnt-tree.go -f ./testdata/small-evnt-tree-fullsplit.root -split=99
// Class represents a ROOT class.
// Class instances are created by a ClassFactory.
type Class interface {
// GetCheckSum gets the check sum for this ROOT class
CheckSum() int
// Members returns the list of members for this ROOT class
Members() []Member
// Version returns the version number for this ROOT class
Version() int
// ClassName returns the ROOT class name for this ROOT class
ClassName() string
}
// Member represents a single member of a ROOT class
type Member interface {
// GetArrayDim returns the dimension of the array (if any)
ArrayDim() int
// GetComment returns the comment associated with this member
Comment() string
// Name returns the name of this member
Name() string
// Type returns the class of this member
Type() Class
// GetValue returns the value of this member
Value(o Object) reflect.Value
}
// Object represents a ROOT object
type Object interface {
// Class returns the ROOT class of this object
Class() string
}
// Named represents a ROOT TNamed object
type Named interface {
Object
// Name returns the name of this ROOT object
Name() string
// Title returns the title of this ROOT object
Title() string
}
// ClassFactory creates ROOT classes
type ClassFactory interface {
Create(name string) Class
}
// Collection is a collection of ROOT Objects.
type Collection interface {
Object
// Name returns the name of the collection.
Name() string
// Last returns the last element index
Last() int
// At returns the element at index i
At(i int) Object
// Len returns the number of elements in the collection
Len() int
}
// SeqCollection is a sequential collection of ROOT Objects.
type SeqCollection interface {
Collection
}
// List is a list of ROOT Objects.
type List interface {
SeqCollection
}
// ObjArray is an array of ROOT Objects.
type ObjArray interface {
SeqCollection
LowerBound() int
}
// ObjString is a ROOT string that implements ROOT TObject.
type ObjString interface {
Name() string
String() string
isTObjString()
}
// Directory describes a ROOT directory structure in memory.
type Directory interface {
// Get returns the object identified by namecycle
// namecycle has the format name;cycle
// name = * is illegal, cycle = * is illegal
// cycle = "" or cycle = 9999 ==> apply to a memory object
//
// examples:
// foo : get object named foo in memory
// if object is not in memory, try with highest cycle from file
// foo;1 : get cycle 1 of foo on file
Get(namecycle string) (Object, error)
// Put puts the object v under the key with the given name.
Put(name string, v Object) error
// Keys returns the list of keys being held by this directory.
Keys() []Key
}
// StreamerInfo describes a ROOT Streamer.
type StreamerInfo interface {
Named
CheckSum() int
ClassVersion() int
Elements() []StreamerElement
}
// StreamerElement describes a ROOT StreamerElement
type StreamerElement interface {
Named
ArrayDim() int
ArrayLen() int
Type() int
Offset() uintptr
Size() uintptr
TypeName() string
}
// SetFiler is a simple interface to establish File ownership.
type SetFiler interface {
SetFile(f *File)
}
// Tree is a collection of branches of data.
type Tree interface {
Named
Entries() int64
TotBytes() int64
ZipBytes() int64
Branch(name string) Branch
Branches() []Branch
Leaf(name string) Leaf
Leaves() []Leaf
getFile() *File
loadEntry(i int64) error
}
// Branch describes a branch of a ROOT Tree.
type Branch interface {
Named
Branches() []Branch
Leaves() []Leaf
Branch(name string) Branch
Leaf(name string) Leaf
setTree(Tree)
getTree() Tree
loadEntry(i int64) error
getReadEntry() int64
getEntry(i int64)
scan(ptr interface{}) error
setAddress(ptr interface{}) error
setStreamer(s StreamerInfo, ctx StreamerInfoContext)
setStreamerElement(s StreamerElement, ctx StreamerInfoContext)
GoType() reflect.Type
}
// Leaf describes branches data types
type Leaf interface {
Named
ArrayDim() int
Branch() Branch
HasRange() bool
IsUnsigned() bool
LeafCount() Leaf // returns the leaf count if is variable length
Len() int // Len returns the number of fixed length elements
LenType() int // LenType returns the number of bytes for this data type
MaxIndex() []int
Offset() int
Kind() reflect.Kind
Type() reflect.Type
Value(int) interface{}
TypeName() string
setBranch(Branch)
readBasket(r *RBuffer) error
value() interface{}
scan(r *RBuffer, ptr interface{}) error
}
// leafCount describes leaves that are used for array length count
type leafCount interface {
Leaf
ivalue() int // for leaf-count
imax() int
}
// Array describes ROOT abstract array type.
type Array interface {
Len() int // number of array elements
Get(i int) interface{}
Set(i int, v interface{})
}
// Axis describes a ROOT TAxis.
type Axis interface {
Named
XMin() float64
XMax() float64
NBins() int
XBins() []float64
BinCenter(int) float64
BinLowEdge(int) float64
BinWidth(int) float64
}
// H1 is a 1-dim ROOT histogram
type H1 interface {
Named
isH1()
// Entries returns the number of entries for this histogram.
Entries() float64
// SumW returns the total sum of weights
SumW() float64
// SumW2 returns the total sum of squares of weights
SumW2() float64
// SumWX returns the total sum of weights*x
SumWX() float64
// SumWX2 returns the total sum of weights*x*x
SumWX2() float64
// SumW2s returns the array of sum of squares of weights
SumW2s() []float64
}
// H2 is a 2-dim ROOT histogram
type H2 interface {
Named
isH2()
// Entries returns the number of entries for this histogram.
Entries() float64
// SumW returns the total sum of weights
SumW() float64
// SumW2 returns the total sum of squares of weights
SumW2() float64
// SumWX returns the total sum of weights*x
SumWX() float64
// SumWX2 returns the total sum of weights*x*x
SumWX2() float64
// SumW2s returns the array of sum of squares of weights
SumW2s() []float64
// SumWY returns the total sum of weights*y
SumWY() float64
// SumWY2 returns the total sum of weights*y*y
SumWY2() float64
// SumWXY returns the total sum of weights*x*y
SumWXY() float64
}
// Graph describes a ROOT TGraph
type Graph interface {
Named
Len() int
XY(i int) (float64, float64)
}
// GraphErrors describes a ROOT TGraphErrors
type GraphErrors interface {
Graph
// XError returns two error values for X data.
XError(i int) (float64, float64)
// YError returns two error values for Y data.
YError(i int) (float64, float64)
}
// ROOTUnmarshaler is the interface implemented by an object that can
// unmarshal itself from a ROOT buffer
type ROOTUnmarshaler interface {
UnmarshalROOT(r *RBuffer) error
}
// ROOTMarshaler is the interface implemented by an object that can
// marshal itself into a ROOT buffer
type ROOTMarshaler interface {
MarshalROOT(w *WBuffer) (int, error)
}