go-hep.org/x/hep@v0.38.1/groot/rcont/reftable.go (about) 1 // Copyright ©2020 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 rcont 6 7 import ( 8 "fmt" 9 "reflect" 10 11 "go-hep.org/x/hep/groot/rbase" 12 "go-hep.org/x/hep/groot/rbytes" 13 "go-hep.org/x/hep/groot/root" 14 "go-hep.org/x/hep/groot/rtypes" 15 "go-hep.org/x/hep/groot/rvers" 16 ) 17 18 type RefTable struct { 19 obj rbase.Object 20 size int32 // dummy, for backward compatibility 21 parents *ObjArray // array of Parent objects (eg TTree branch) holding the referenced objects 22 owner root.Object // Object owning this TRefTable 23 guids []string // UUIDs of TProcessIDs used in fParentIDs 24 } 25 26 func NewRefTable(owner root.Object) *RefTable { 27 return &RefTable{ 28 obj: *rbase.NewObject(), 29 owner: owner, 30 } 31 } 32 33 func (*RefTable) RVersion() int16 { 34 return rvers.RefTable 35 } 36 37 func (*RefTable) Class() string { 38 return "TRefTable" 39 } 40 41 func (tbl *RefTable) UID() uint32 { 42 return tbl.obj.UID() 43 } 44 45 func (tbl *RefTable) At(i int) root.Object { 46 panic("not implemented") 47 } 48 49 func (tbl *RefTable) UIDs() []string { 50 return tbl.guids 51 } 52 53 func (tbl *RefTable) MarshalROOT(w *rbytes.WBuffer) (int, error) { 54 if w.Err() != nil { 55 return 0, w.Err() 56 } 57 58 hdr := w.WriteHeader(tbl.Class(), tbl.RVersion()) 59 w.WriteObject(&tbl.obj) 60 w.WriteI32(tbl.size) 61 { 62 var obj root.Object 63 if tbl.parents != nil { 64 obj = tbl.parents 65 } 66 w.WriteObjectAny(obj) 67 } 68 { 69 var obj root.Object 70 if tbl.owner != nil { 71 obj = tbl.owner 72 } 73 w.WriteObjectAny(obj) 74 } 75 w.WriteStdVectorStrs(tbl.guids) 76 77 return w.SetHeader(hdr) 78 } 79 80 func (tbl *RefTable) UnmarshalROOT(r *rbytes.RBuffer) error { 81 if r.Err() != nil { 82 return r.Err() 83 } 84 85 hdr := r.ReadHeader(tbl.Class(), tbl.RVersion()) 86 if hdr.Vers < 3 { 87 return fmt.Errorf("rcont: TRefTable version too old (%d < 3)", hdr.Vers) 88 } 89 90 r.ReadObject(&tbl.obj) 91 tbl.size = r.ReadI32() 92 { 93 obj := r.ReadObjectAny() 94 tbl.parents = nil 95 if obj != nil { 96 tbl.parents = obj.(*ObjArray) 97 } 98 } 99 { 100 obj := r.ReadObjectAny() 101 tbl.owner = nil 102 if obj != nil { 103 tbl.owner = obj 104 } 105 } 106 r.ReadStdVectorStrs(&tbl.guids) 107 108 r.CheckHeader(hdr) 109 return r.Err() 110 } 111 112 func init() { 113 f := func() reflect.Value { 114 o := NewRefTable(nil) 115 return reflect.ValueOf(o) 116 } 117 rtypes.Factory.Add("TRefTable", f) 118 } 119 120 var ( 121 _ root.Object = (*RefTable)(nil) 122 _ rbytes.Marshaler = (*RefTable)(nil) 123 _ rbytes.Unmarshaler = (*RefTable)(nil) 124 )