-
Notifications
You must be signed in to change notification settings - Fork 35
/
tree.go
256 lines (213 loc) · 4.98 KB
/
tree.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
// 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 (
"fmt"
"reflect"
)
// A ttree object is a list of Branch.
// To Create a TTree object one must:
// - Create the TTree header via the TTree constructor
// - Call the TBranch constructor for every branch.
//
// To Fill this object, use member function Fill with no parameters
// The Fill function loops on all defined TBranch
type ttree struct {
f *File // underlying file
named tnamed
entries int64 // Number of entries
totbytes int64 // Total number of bytes in all branches before compression
zipbytes int64 // Total number of bytes in all branches after compression
branches []Branch // list of branches
leaves []Leaf // direct pointers to individual branch leaves
}
func (tree *ttree) Class() string {
return "TTree"
}
func (tree *ttree) Name() string {
return tree.named.Name()
}
func (tree *ttree) Title() string {
return tree.named.Title()
}
func (tree *ttree) Entries() int64 {
return tree.entries
}
func (tree *ttree) TotBytes() int64 {
return tree.totbytes
}
func (tree *ttree) ZipBytes() int64 {
return tree.zipbytes
}
func (tree *ttree) Branches() []Branch {
return tree.branches
}
func (tree *ttree) Branch(name string) Branch {
for _, br := range tree.branches {
if br.Name() == name {
return br
}
}
return nil
}
func (tree *ttree) Leaves() []Leaf {
return tree.leaves
}
func (tree *ttree) SetFile(f *File) {
tree.f = f
}
func (tree *ttree) getFile() *File {
return tree.f
}
func (tree *ttree) loadEntry(entry int64) error {
for _, b := range tree.branches {
err := b.loadEntry(entry)
if err != nil {
return err
}
}
return nil
}
// ROOTUnmarshaler is the interface implemented by an object that can
// unmarshal itself from a ROOT buffer
func (tree *ttree) UnmarshalROOT(r *RBuffer) error {
beg := r.Pos()
vers, pos, bcnt := r.ReadVersion()
for _, a := range []ROOTUnmarshaler{
&tree.named,
&attline{},
&attfill{},
&attmarker{},
} {
err := a.UnmarshalROOT(r)
if err != nil {
return err
}
}
if vers < 16 {
return fmt.Errorf(
"rootio.Tree: tree [%s] with version [%v] is not supported (too old)",
tree.Name(),
vers,
)
}
r.ReadI64(&tree.entries)
r.ReadI64(&tree.totbytes)
r.ReadI64(&tree.zipbytes)
if vers >= 19 { // FIXME
var savedBytes int64
r.ReadI64(&savedBytes) // fSavedBytes
}
if vers >= 18 {
var flushedBytes int64
r.ReadI64(&flushedBytes) // flushed bytes
}
var f64 float64
r.ReadF64(&f64) // fWeight
var i32 int32
r.ReadI32(&i32) // fTimerInterval
r.ReadI32(&i32) // fScanField
r.ReadI32(&i32) // fUpdate
if vers >= 18 {
r.ReadI32(&i32) // fDefaultEntryOffsetLen
}
nclus := 0
if vers >= 19 { // FIXME
r.ReadI32(&i32)
nclus = int(i32) // fNClusterRange
}
var i64 int64
r.ReadI64(&i64) // fMaxEntries
r.ReadI64(&i64) // fMaxEntryLoop
r.ReadI64(&i64) // fMaxVirtualSize
r.ReadI64(&i64) // fAutoSave
if vers >= 18 {
r.ReadI64(&i64) // fAutoFlush
}
r.ReadI64(&i64) // fEstimate
if vers >= 19 { // FIXME
var i8 int8
i64s := make([]int64, nclus)
r.ReadI8(&i8)
r.ReadFastArrayI64(i64s) // fClusterRangeEnd
r.ReadI8(&i8)
r.ReadFastArrayI64(i64s) // fClusterSize
}
var branches objarray
if err := branches.UnmarshalROOT(r); err != nil {
return err
}
tree.branches = make([]Branch, branches.last+1)
for i := range tree.branches {
tree.branches[i] = branches.At(i).(Branch)
tree.branches[i].setTree(tree)
}
var leaves objarray
if err := leaves.UnmarshalROOT(r); err != nil {
return err
}
tree.leaves = make([]Leaf, leaves.last+1)
for i := range tree.leaves {
tree.leaves[i] = leaves.At(i).(Leaf)
// FIXME(sbinet)
//tree.leaves[i].SetBranch(tree.branches[i])
}
for range []string{
"fAliases", "fIndexValues", "fIndex", "fTreeIndex", "fFriends",
"fUserInfo", "fBranchRef",
} {
_ = r.ReadObjectAny()
}
r.CheckByteCount(pos, bcnt, beg, "TTree")
return r.Err()
}
type tntuple struct {
ttree
nvars int
}
func (nt *tntuple) Class() string {
return "TNtuple"
}
func (nt *tntuple) UnmarshalROOT(r *RBuffer) error {
if r.err != nil {
return r.err
}
beg := r.Pos()
/*vers*/ _, pos, bcnt := r.ReadVersion()
if err := nt.ttree.UnmarshalROOT(r); err != nil {
r.err = err
return r.err
}
var i32 int32
r.ReadI32(&i32)
nt.nvars = int(i32)
r.CheckByteCount(pos, bcnt, beg, "TNtuple")
return r.err
}
func init() {
{
f := func() reflect.Value {
o := &ttree{}
return reflect.ValueOf(o)
}
Factory.add("TTree", f)
Factory.add("*rootio.ttree", f)
}
{
f := func() reflect.Value {
o := &tntuple{}
return reflect.ValueOf(o)
}
Factory.add("TNtuple", f)
Factory.add("*rootio.tntuple", f)
}
}
var _ Object = (*ttree)(nil)
var _ Named = (*ttree)(nil)
var _ Tree = (*ttree)(nil)
var _ ROOTUnmarshaler = (*ttree)(nil)
var _ Object = (*tntuple)(nil)
var _ Named = (*tntuple)(nil)
var _ Tree = (*tntuple)(nil)
var _ ROOTUnmarshaler = (*tntuple)(nil)