Skip to content

Commit

Permalink
groot: introduce rbytes.Header
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Feb 16, 2022
1 parent e16891d commit 0a85f50
Show file tree
Hide file tree
Showing 55 changed files with 1,063 additions and 943 deletions.
12 changes: 6 additions & 6 deletions groot/cmd/root-gen-streamer/testdata/rdatatest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (o *Event) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}

pos := w.WriteVersion(o.RVersion())
hdr := w.WriteHeader(o.Class(), o.RVersion())

w.WriteString(o.name)
w.WriteU8(o.u8)
Expand Down Expand Up @@ -314,7 +314,7 @@ func (o *Event) MarshalROOT(w *rbytes.WBuffer) (int, error) {
w.WriteObject(&o.SliHLV)
w.WriteArrayF64(o.ArrF64[:])

return w.SetByteCount(pos, o.Class())
return w.SetHeader(hdr)
}

func init() {
Expand Down Expand Up @@ -365,14 +365,14 @@ func (o *HLV) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}

pos := w.WriteVersion(o.RVersion())
hdr := w.WriteHeader(o.Class(), o.RVersion())

w.WriteF64(o.px)
w.WriteF64(o.py)
w.WriteF64(o.pz)
w.WriteF64(o.e)

return w.SetByteCount(pos, o.Class())
return w.SetHeader(hdr)
}

func init() {
Expand Down Expand Up @@ -411,11 +411,11 @@ func (o *Particle) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}

pos := w.WriteVersion(o.RVersion())
hdr := w.WriteHeader(o.Class(), o.RVersion())

w.WriteString(o.name)
w.WriteI64(int64(o.pid))
w.WriteObject(&o.mom)

return w.SetByteCount(pos, o.Class())
return w.SetHeader(hdr)
}
26 changes: 12 additions & 14 deletions groot/cmd/root-gen-type/testdata/small-evnt-tree-fullsplit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (o *Event) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}

pos := w.WriteVersion(o.RVersion())
hdr := w.WriteHeader(o.Class(), o.RVersion())

w.WriteString(o.Beg)
w.WriteI16(o.I16)
Expand Down Expand Up @@ -120,7 +120,7 @@ func (o *Event) MarshalROOT(w *rbytes.WBuffer) (int, error) {
w.WriteStdVectorStrs(o.StlVecStr)
w.WriteString(o.End)

return w.SetByteCount(pos, o.Class())
return w.SetHeader(hdr)
}

// UnmarshalROOT implements rbytes.Unmarshaler
Expand All @@ -129,12 +129,11 @@ func (o *Event) UnmarshalROOT(r *rbytes.RBuffer) error {
return r.Err()
}

start := r.Pos()
vers, pos, bcnt := r.ReadVersion(o.Class())
if vers > o.RVersion() {
hdr := r.ReadHeader(o.Class())
if hdr.Vers > o.RVersion() {
panic(fmt.Errorf(
"rbytes: invalid %s version=%d > %d",
o.Class(), vers, o.RVersion(),
o.Class(), hdr.Vers, o.RVersion(),
))
}

Expand Down Expand Up @@ -194,7 +193,7 @@ func (o *Event) UnmarshalROOT(r *rbytes.RBuffer) error {
r.ReadStdVectorStrs(&o.StlVecStr)
o.End = r.ReadString()

r.CheckByteCount(pos, bcnt, start, o.Class())
r.CheckHeader(hdr)
return r.Err()
}

Expand Down Expand Up @@ -746,13 +745,13 @@ func (o *P3) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}

pos := w.WriteVersion(o.RVersion())
hdr := w.WriteHeader(o.Class(), o.RVersion())

w.WriteI32(o.Px)
w.WriteF64(o.Py)
w.WriteI32(o.Pz)

return w.SetByteCount(pos, o.Class())
return w.SetHeader(hdr)
}

// UnmarshalROOT implements rbytes.Unmarshaler
Expand All @@ -761,20 +760,19 @@ func (o *P3) UnmarshalROOT(r *rbytes.RBuffer) error {
return r.Err()
}

start := r.Pos()
vers, pos, bcnt := r.ReadVersion(o.Class())
if vers > o.RVersion() {
hdr := r.ReadHeader(o.Class())
if hdr.Vers > o.RVersion() {
panic(fmt.Errorf(
"rbytes: invalid %s version=%d > %d",
o.Class(), vers, o.RVersion(),
o.Class(), hdr.Vers, o.RVersion(),
))
}

o.Px = r.ReadI32()
o.Py = r.ReadF64()
o.Pz = r.ReadI32()

r.CheckByteCount(pos, bcnt, start, o.Class())
r.CheckHeader(hdr)
return r.Err()
}

Expand Down
26 changes: 12 additions & 14 deletions groot/cmd/root-gen-type/testdata/streamers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (o *Event) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}

pos := w.WriteVersion(o.RVersion())
hdr := w.WriteHeader(o.Class(), o.RVersion())

w.WriteString(o.Beg)
w.WriteI16(o.I16)
Expand Down Expand Up @@ -138,7 +138,7 @@ func (o *Event) MarshalROOT(w *rbytes.WBuffer) (int, error) {
w.WriteStdVectorStrs(o.StlVecStr)
w.WriteString(o.End)

return w.SetByteCount(pos, o.Class())
return w.SetHeader(hdr)
}

// UnmarshalROOT implements rbytes.Unmarshaler
Expand All @@ -147,12 +147,11 @@ func (o *Event) UnmarshalROOT(r *rbytes.RBuffer) error {
return r.Err()
}

start := r.Pos()
vers, pos, bcnt := r.ReadVersion(o.Class())
if vers > o.RVersion() {
hdr := r.ReadHeader(o.Class())
if hdr.Vers > o.RVersion() {
panic(fmt.Errorf(
"rbytes: invalid %s version=%d > %d",
o.Class(), vers, o.RVersion(),
o.Class(), hdr.Vers, o.RVersion(),
))
}

Expand Down Expand Up @@ -233,7 +232,7 @@ func (o *Event) UnmarshalROOT(r *rbytes.RBuffer) error {
r.ReadStdVectorStrs(&o.StlVecStr)
o.End = r.ReadString()

r.CheckByteCount(pos, bcnt, start, o.Class())
r.CheckHeader(hdr)
return r.Err()
}

Expand Down Expand Up @@ -876,13 +875,13 @@ func (o *P3) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}

pos := w.WriteVersion(o.RVersion())
hdr := w.WriteHeader(o.Class(), o.RVersion())

w.WriteI32(o.Px)
w.WriteF64(o.Py)
w.WriteI32(o.Pz)

return w.SetByteCount(pos, o.Class())
return w.SetHeader(hdr)
}

// UnmarshalROOT implements rbytes.Unmarshaler
Expand All @@ -891,20 +890,19 @@ func (o *P3) UnmarshalROOT(r *rbytes.RBuffer) error {
return r.Err()
}

start := r.Pos()
vers, pos, bcnt := r.ReadVersion(o.Class())
if vers > o.RVersion() {
hdr := r.ReadHeader(o.Class())
if hdr.Vers > o.RVersion() {
panic(fmt.Errorf(
"rbytes: invalid %s version=%d > %d",
o.Class(), vers, o.RVersion(),
o.Class(), hdr.Vers, o.RVersion(),
))
}

o.Px = r.ReadI32()
o.Py = r.ReadF64()
o.Pz = r.ReadI32()

r.CheckByteCount(pos, bcnt, start, o.Class())
r.CheckHeader(hdr)
return r.Err()
}

Expand Down
9 changes: 4 additions & 5 deletions groot/exp/rntup/rntup.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (nt *NTuple) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}

pos := w.WriteVersion(nt.RVersion())
hdr := w.WriteHeader(nt.Class(), nt.RVersion())

w.WriteU32(nt.rvers)
w.WriteU32(nt.size)
Expand All @@ -64,16 +64,15 @@ func (nt *NTuple) MarshalROOT(w *rbytes.WBuffer) (int, error) {

w.WriteU64(nt.reserved)

return w.SetByteCount(pos, nt.Class())
return w.SetHeader(hdr)
}

func (nt *NTuple) UnmarshalROOT(r *rbytes.RBuffer) error {
if r.Err() != nil {
return r.Err()
}

beg := r.Pos()
_ /*vers*/, pos, bcnt := r.ReadVersion(nt.Class())
hdr := r.ReadHeader(nt.Class())

nt.rvers = r.ReadU32()
nt.size = r.ReadU32()
Expand All @@ -88,7 +87,7 @@ func (nt *NTuple) UnmarshalROOT(r *rbytes.RBuffer) error {

nt.reserved = r.ReadU64()

r.CheckByteCount(pos, bcnt, beg, nt.Class())
r.CheckHeader(hdr)
return r.Err()
}

Expand Down
18 changes: 9 additions & 9 deletions groot/gen.rbytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ func (r *RBuffer) ReadStdVector{{.Name}}(sli *[]{{.Type}}) {
if r.err != nil {
return
}
const typename = "vector<{{.Type}}>"
beg := r.Pos()
vers, pos, bcnt := r.ReadVersion(typename)
if vers != rvers.StreamerInfo {
hdr := r.ReadHeader("vector<{{.Type}}>")
if hdr.Vers != rvers.StreamerInfo {
r.err = fmt.Errorf(
"rbytes: invalid %s version: got=%d, want=%d",
typename, vers, rvers.StreamerInfo,
hdr.Name, hdr.Vers, rvers.StreamerInfo,
)
return
}
Expand All @@ -179,7 +178,8 @@ func (r *RBuffer) ReadStdVector{{.Name}}(sli *[]{{.Type}}) {
for i := range *sli {
(*sli)[i] = r.Read{{.Name}}()
}
r.CheckByteCount(pos, bcnt, beg, typename)
r.CheckHeader(hdr)
}
`

Expand Down Expand Up @@ -316,8 +316,8 @@ func (w *WBuffer) WriteStdVector{{.Name}}(sli []{{.Type}}) {
if w.err != nil {
return
}
const typename = "vector<{{.Type}}>"
pos := w.WriteVersion(rvers.StreamerInfo)
hdr := w.WriteHeader("vector<{{.Type}}>", rvers.StreamerInfo)
w.WriteI32(int32(len(sli)))
w.w.grow(len(sli)*{{.Size}})
Expand All @@ -337,6 +337,6 @@ func (w *WBuffer) WriteStdVector{{.Name}}(sli []{{.Type}}) {
if w.err != nil {
return
}
_, w.err = w.SetByteCount(pos, typename)
_, w.err = w.SetHeader(hdr)
}
`
29 changes: 15 additions & 14 deletions groot/gen.rhist.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,29 +208,28 @@ func (h *{{.Name}}) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}
pos := w.WriteVersion(h.RVersion())
hdr := w.WriteHeader(h.Class(), h.RVersion())
w.WriteObject(&h.th1)
w.WriteObject(&h.arr)
return w.SetByteCount(pos, h.Class())
return w.SetHeader(hdr)
}
func (h *{{.Name}}) UnmarshalROOT(r *rbytes.RBuffer) error {
if r.Err() != nil {
return r.Err()
}
beg := r.Pos()
vers, pos, bcnt := r.ReadVersion(h.Class())
if vers > rvers.{{.Name}} {
panic(fmt.Errorf("rhist: invalid {{.Name}} version=%d > %d", vers, rvers.{{.Name}}))
hdr := r.ReadHeader(h.Class())
if hdr.Vers > rvers.{{.Name}} {
panic(fmt.Errorf("rhist: invalid {{.Name}} version=%d > %d", hdr.Vers, rvers.{{.Name}}))
}
r.ReadObject(&h.th1)
r.ReadObject(&h.arr)
r.CheckByteCount(pos, bcnt, beg, h.Class())
r.CheckHeader(hdr)
return r.Err()
}
Expand Down Expand Up @@ -758,28 +757,30 @@ func (h *{{.Name}}) MarshalROOT(w *rbytes.WBuffer) (int, error) {
return 0, w.Err()
}
pos := w.WriteVersion(h.RVersion())
hdr := w.WriteHeader(h.Class(), h.RVersion())
w.WriteObject(&h.th2)
w.WriteObject(&h.arr)
return w.SetByteCount(pos, h.Class())
return w.SetHeader(hdr)
}
func (h *{{.Name}}) UnmarshalROOT(r *rbytes.RBuffer) error {
if r.Err() != nil {
return r.Err()
}
beg := r.Pos()
vers, pos, bcnt := r.ReadVersion(h.Class())
if vers < 1 {
return fmt.Errorf("rhist: T{{.Name}} version too old (%d<1)", vers)
hdr := r.ReadHeader(h.Class())
if hdr.Vers > rvers.{{.Name}} {
panic(fmt.Errorf("rhist: invalid {{.Name}} version=%d > %d", hdr.Vers, rvers.{{.Name}}))
}
if hdr.Vers < 1 {
return fmt.Errorf("rhist: T{{.Name}} version too old (%d<1)", hdr.Vers)
}
r.ReadObject(&h.th2)
r.ReadObject(&h.arr)
r.CheckByteCount(pos, bcnt, beg, h.Class())
r.CheckHeader(hdr)
return r.Err()
}
Expand Down
Loading

0 comments on commit 0a85f50

Please sign in to comment.