diff --git a/groot/cmd/root-gen-type/main_test.go b/groot/cmd/root-gen-type/main_test.go index 6ed2ac148..9d435e913 100644 --- a/groot/cmd/root-gen-type/main_test.go +++ b/groot/cmd/root-gen-type/main_test.go @@ -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" diff --git a/groot/cmd/root-gen-type/testdata/rvec.txt b/groot/cmd/root-gen-type/testdata/rvec.txt new file mode 100644 index 000000000..40cec3cc9 --- /dev/null +++ b/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"` // Used to call the proper TStreamerInfo case +} + +func (*ROOT__VecOps__RVec_float_) Class() string { + return "ROOT::VecOps::RVec" +} + +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", f) +} + +func init() { + // Streamer for ROOT::VecOps::RVec. + rdict.StreamerInfos.Add(rdict.NewCxxStreamerInfo("ROOT::VecOps::RVec", 6, 0x9d22612c, []rbytes.StreamerElement{ + rdict.NewCxxStreamerSTL(rdict.Element{ + Name: *rbase.NewNamed("This", " 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", + 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"` // Used to call the proper TStreamerInfo case +} + +func (*ROOT__VecOps__RVec_int_) Class() string { + return "ROOT::VecOps::RVec" +} + +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", f) +} + +func init() { + // Streamer for ROOT::VecOps::RVec. + rdict.StreamerInfos.Add(rdict.NewCxxStreamerInfo("ROOT::VecOps::RVec", 6, 0xbc2043d1, []rbytes.StreamerElement{ + rdict.NewCxxStreamerSTL(rdict.Element{ + Name: *rbase.NewNamed("This", " 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", + 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) +) diff --git a/groot/rdict/gen_type.go b/groot/rdict/gen_type.go index 85837e896..8f9fb19f4 100644 --- a/groot/rdict/gen_type.go +++ b/groot/rdict/gen_type.go @@ -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: @@ -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" @@ -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 } @@ -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: @@ -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: