Skip to content

Commit

Permalink
groot/{cmd/root-gen-type,rdict}: add support for generating RVec types
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastien Binet <binet@cern.ch>
  • Loading branch information
sbinet committed May 12, 2022
1 parent dc2dcf6 commit f9b4365
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 4 deletions.
5 changes: 5 additions & 0 deletions groot/cmd/root-gen-type/main_test.go
Expand Up @@ -42,6 +42,11 @@ func TestGenerate(t *testing.T) {
want: "testdata/tbase.txt",
types: []string{"Base", "D1", "D2"},
},
{
fname: "../../testdata/rvec.root",
want: "testdata/rvec.txt",
types: []string{"RVec"},
},
} {
t.Run(tc.fname, func(t *testing.T) {
oname := filepath.Base(tc.fname) + ".go"
Expand Down
173 changes: 173 additions & 0 deletions groot/cmd/root-gen-type/testdata/rvec.txt
@@ -0,0 +1,173 @@
// DO NOT EDIT; automatically generated by root-gen-type

package main

import (
"fmt"
"reflect"

"go-hep.org/x/hep/groot/rbase"
"go-hep.org/x/hep/groot/rbytes"
"go-hep.org/x/hep/groot/rdict"
"go-hep.org/x/hep/groot/rmeta"
"go-hep.org/x/hep/groot/root"
"go-hep.org/x/hep/groot/rtypes"
)

type ROOT__VecOps__RVec_float_ struct {
This []float32 `groot:"This"` // <Float_t> Used to call the proper TStreamerInfo case
}

func (*ROOT__VecOps__RVec_float_) Class() string {
return "ROOT::VecOps::RVec<float>"
}

func (*ROOT__VecOps__RVec_float_) RVersion() int16 {
return 6
}

// MarshalROOT implements rbytes.Marshaler
func (o *ROOT__VecOps__RVec_float_) MarshalROOT(w *rbytes.WBuffer) (int, error) {
if w.Err() != nil {
return 0, w.Err()
}

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

w.WriteStdVectorF32(o.This)

return w.SetHeader(hdr)
}

// UnmarshalROOT implements rbytes.Unmarshaler
func (o *ROOT__VecOps__RVec_float_) UnmarshalROOT(r *rbytes.RBuffer) error {
if r.Err() != nil {
return r.Err()
}

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

r.ReadStdVectorF32(&o.This)

r.CheckHeader(hdr)
return r.Err()
}

func init() {
f := func() reflect.Value {
var o ROOT__VecOps__RVec_float_
return reflect.ValueOf(&o)
}
rtypes.Factory.Add("ROOT::VecOps::RVec<float>", f)
}

func init() {
// Streamer for ROOT::VecOps::RVec<float>.
rdict.StreamerInfos.Add(rdict.NewCxxStreamerInfo("ROOT::VecOps::RVec<float>", 6, 0x9d22612c, []rbytes.StreamerElement{
rdict.NewCxxStreamerSTL(rdict.Element{
Name: *rbase.NewNamed("This", "<Float_t> Used to call the proper TStreamerInfo case"),
Type: rmeta.Streamer,
Size: 0,
ArrLen: 0,
ArrDim: 0,
MaxIdx: [5]int32{0, 0, 0, 0, 0},
Offset: 0,
EName: "ROOT::VecOps::RVec<float>",
XMin: 0.000000,
XMax: 0.000000,
Factor: 0.000000,
}.New(), 14, 5),
}))
}

var (
_ root.Object = (*ROOT__VecOps__RVec_float_)(nil)
_ rbytes.RVersioner = (*ROOT__VecOps__RVec_float_)(nil)
_ rbytes.Marshaler = (*ROOT__VecOps__RVec_float_)(nil)
_ rbytes.Unmarshaler = (*ROOT__VecOps__RVec_float_)(nil)
)

type ROOT__VecOps__RVec_int_ struct {
This []int32 `groot:"This"` // <Int_t> Used to call the proper TStreamerInfo case
}

func (*ROOT__VecOps__RVec_int_) Class() string {
return "ROOT::VecOps::RVec<int>"
}

func (*ROOT__VecOps__RVec_int_) RVersion() int16 {
return 6
}

// MarshalROOT implements rbytes.Marshaler
func (o *ROOT__VecOps__RVec_int_) MarshalROOT(w *rbytes.WBuffer) (int, error) {
if w.Err() != nil {
return 0, w.Err()
}

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

w.WriteStdVectorI32(o.This)

return w.SetHeader(hdr)
}

// UnmarshalROOT implements rbytes.Unmarshaler
func (o *ROOT__VecOps__RVec_int_) UnmarshalROOT(r *rbytes.RBuffer) error {
if r.Err() != nil {
return r.Err()
}

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

r.ReadStdVectorI32(&o.This)

r.CheckHeader(hdr)
return r.Err()
}

func init() {
f := func() reflect.Value {
var o ROOT__VecOps__RVec_int_
return reflect.ValueOf(&o)
}
rtypes.Factory.Add("ROOT::VecOps::RVec<int>", f)
}

func init() {
// Streamer for ROOT::VecOps::RVec<int>.
rdict.StreamerInfos.Add(rdict.NewCxxStreamerInfo("ROOT::VecOps::RVec<int>", 6, 0xbc2043d1, []rbytes.StreamerElement{
rdict.NewCxxStreamerSTL(rdict.Element{
Name: *rbase.NewNamed("This", "<Int_t> Used to call the proper TStreamerInfo case"),
Type: rmeta.Streamer,
Size: 0,
ArrLen: 0,
ArrDim: 0,
MaxIdx: [5]int32{0, 0, 0, 0, 0},
Offset: 0,
EName: "ROOT::VecOps::RVec<int>",
XMin: 0.000000,
XMax: 0.000000,
Factor: 0.000000,
}.New(), 14, 3),
}))
}

var (
_ root.Object = (*ROOT__VecOps__RVec_int_)(nil)
_ rbytes.RVersioner = (*ROOT__VecOps__RVec_int_)(nil)
_ rbytes.Marshaler = (*ROOT__VecOps__RVec_int_)(nil)
_ rbytes.Unmarshaler = (*ROOT__VecOps__RVec_int_)(nil)
)
11 changes: 7 additions & 4 deletions groot/rdict/gen_type.go
Expand Up @@ -196,7 +196,7 @@ func (g *genGoType) genField(si rbytes.StreamerInfo, i int, se rbytes.StreamerEl

case *StreamerSTL:
switch se.STLType() {
case rmeta.STLvector, rmeta.STLmap:
case rmeta.STLvector, rmeta.STLmap, rmeta.STLend:
tname := g.typename(se)
g.printf(docFmt, se.Name(), tname, g.stag(i, se), doc)
default:
Expand Down Expand Up @@ -317,7 +317,7 @@ func (g *genGoType) typename(se rbytes.StreamerElement) string {

case *StreamerSTL:
switch se.STLType() {
case rmeta.STLvector:
case rmeta.STLvector, rmeta.STLend:
switch se.ContainedType() {
case rmeta.Bool:
return "[]bool"
Expand Down Expand Up @@ -420,6 +420,9 @@ func (g *genGoType) cxx2go(name string, qual qualKind) string {
}
name = f(name)
name = strings.Replace(name, "::", "__", -1) // handle namespaces
name = strings.Replace(name, "<", "_", -1) // handle C++ templates
name = strings.Replace(name, ">", "_", -1) // handle C++ templates
name = strings.Replace(name, ",", "_", -1) // handle C++ templates
return prefix + name
}

Expand Down Expand Up @@ -611,7 +614,7 @@ func (g *genGoType) genMarshalField(si rbytes.StreamerInfo, i int, se rbytes.Str

case *StreamerSTL:
switch se.STLType() {
case rmeta.STLvector:
case rmeta.STLvector, rmeta.STLend:
wfunc := ""
switch se.ContainedType() {
case rmeta.Bool:
Expand Down Expand Up @@ -872,7 +875,7 @@ func (g *genGoType) genUnmarshalField(si rbytes.StreamerInfo, i int, se rbytes.S

case *StreamerSTL:
switch se.STLType() {
case rmeta.STLvector:
case rmeta.STLvector, rmeta.STLend:
rfunc := ""
switch se.ContainedType() {
case rmeta.Bool:
Expand Down

0 comments on commit f9b4365

Please sign in to comment.