Skip to content

Commit f9b4365

Browse files
committed
groot/{cmd/root-gen-type,rdict}: add support for generating RVec types
Signed-off-by: Sebastien Binet <binet@cern.ch>
1 parent dc2dcf6 commit f9b4365

File tree

3 files changed

+185
-4
lines changed

3 files changed

+185
-4
lines changed

groot/cmd/root-gen-type/main_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func TestGenerate(t *testing.T) {
4242
want: "testdata/tbase.txt",
4343
types: []string{"Base", "D1", "D2"},
4444
},
45+
{
46+
fname: "../../testdata/rvec.root",
47+
want: "testdata/rvec.txt",
48+
types: []string{"RVec"},
49+
},
4550
} {
4651
t.Run(tc.fname, func(t *testing.T) {
4752
oname := filepath.Base(tc.fname) + ".go"
+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// DO NOT EDIT; automatically generated by root-gen-type
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"reflect"
8+
9+
"go-hep.org/x/hep/groot/rbase"
10+
"go-hep.org/x/hep/groot/rbytes"
11+
"go-hep.org/x/hep/groot/rdict"
12+
"go-hep.org/x/hep/groot/rmeta"
13+
"go-hep.org/x/hep/groot/root"
14+
"go-hep.org/x/hep/groot/rtypes"
15+
)
16+
17+
type ROOT__VecOps__RVec_float_ struct {
18+
This []float32 `groot:"This"` // <Float_t> Used to call the proper TStreamerInfo case
19+
}
20+
21+
func (*ROOT__VecOps__RVec_float_) Class() string {
22+
return "ROOT::VecOps::RVec<float>"
23+
}
24+
25+
func (*ROOT__VecOps__RVec_float_) RVersion() int16 {
26+
return 6
27+
}
28+
29+
// MarshalROOT implements rbytes.Marshaler
30+
func (o *ROOT__VecOps__RVec_float_) MarshalROOT(w *rbytes.WBuffer) (int, error) {
31+
if w.Err() != nil {
32+
return 0, w.Err()
33+
}
34+
35+
hdr := w.WriteHeader(o.Class(), o.RVersion())
36+
37+
w.WriteStdVectorF32(o.This)
38+
39+
return w.SetHeader(hdr)
40+
}
41+
42+
// UnmarshalROOT implements rbytes.Unmarshaler
43+
func (o *ROOT__VecOps__RVec_float_) UnmarshalROOT(r *rbytes.RBuffer) error {
44+
if r.Err() != nil {
45+
return r.Err()
46+
}
47+
48+
hdr := r.ReadHeader(o.Class())
49+
if hdr.Vers > o.RVersion() {
50+
panic(fmt.Errorf(
51+
"rbytes: invalid %s version=%d > %d",
52+
o.Class(), hdr.Vers, o.RVersion(),
53+
))
54+
}
55+
56+
r.ReadStdVectorF32(&o.This)
57+
58+
r.CheckHeader(hdr)
59+
return r.Err()
60+
}
61+
62+
func init() {
63+
f := func() reflect.Value {
64+
var o ROOT__VecOps__RVec_float_
65+
return reflect.ValueOf(&o)
66+
}
67+
rtypes.Factory.Add("ROOT::VecOps::RVec<float>", f)
68+
}
69+
70+
func init() {
71+
// Streamer for ROOT::VecOps::RVec<float>.
72+
rdict.StreamerInfos.Add(rdict.NewCxxStreamerInfo("ROOT::VecOps::RVec<float>", 6, 0x9d22612c, []rbytes.StreamerElement{
73+
rdict.NewCxxStreamerSTL(rdict.Element{
74+
Name: *rbase.NewNamed("This", "<Float_t> Used to call the proper TStreamerInfo case"),
75+
Type: rmeta.Streamer,
76+
Size: 0,
77+
ArrLen: 0,
78+
ArrDim: 0,
79+
MaxIdx: [5]int32{0, 0, 0, 0, 0},
80+
Offset: 0,
81+
EName: "ROOT::VecOps::RVec<float>",
82+
XMin: 0.000000,
83+
XMax: 0.000000,
84+
Factor: 0.000000,
85+
}.New(), 14, 5),
86+
}))
87+
}
88+
89+
var (
90+
_ root.Object = (*ROOT__VecOps__RVec_float_)(nil)
91+
_ rbytes.RVersioner = (*ROOT__VecOps__RVec_float_)(nil)
92+
_ rbytes.Marshaler = (*ROOT__VecOps__RVec_float_)(nil)
93+
_ rbytes.Unmarshaler = (*ROOT__VecOps__RVec_float_)(nil)
94+
)
95+
96+
type ROOT__VecOps__RVec_int_ struct {
97+
This []int32 `groot:"This"` // <Int_t> Used to call the proper TStreamerInfo case
98+
}
99+
100+
func (*ROOT__VecOps__RVec_int_) Class() string {
101+
return "ROOT::VecOps::RVec<int>"
102+
}
103+
104+
func (*ROOT__VecOps__RVec_int_) RVersion() int16 {
105+
return 6
106+
}
107+
108+
// MarshalROOT implements rbytes.Marshaler
109+
func (o *ROOT__VecOps__RVec_int_) MarshalROOT(w *rbytes.WBuffer) (int, error) {
110+
if w.Err() != nil {
111+
return 0, w.Err()
112+
}
113+
114+
hdr := w.WriteHeader(o.Class(), o.RVersion())
115+
116+
w.WriteStdVectorI32(o.This)
117+
118+
return w.SetHeader(hdr)
119+
}
120+
121+
// UnmarshalROOT implements rbytes.Unmarshaler
122+
func (o *ROOT__VecOps__RVec_int_) UnmarshalROOT(r *rbytes.RBuffer) error {
123+
if r.Err() != nil {
124+
return r.Err()
125+
}
126+
127+
hdr := r.ReadHeader(o.Class())
128+
if hdr.Vers > o.RVersion() {
129+
panic(fmt.Errorf(
130+
"rbytes: invalid %s version=%d > %d",
131+
o.Class(), hdr.Vers, o.RVersion(),
132+
))
133+
}
134+
135+
r.ReadStdVectorI32(&o.This)
136+
137+
r.CheckHeader(hdr)
138+
return r.Err()
139+
}
140+
141+
func init() {
142+
f := func() reflect.Value {
143+
var o ROOT__VecOps__RVec_int_
144+
return reflect.ValueOf(&o)
145+
}
146+
rtypes.Factory.Add("ROOT::VecOps::RVec<int>", f)
147+
}
148+
149+
func init() {
150+
// Streamer for ROOT::VecOps::RVec<int>.
151+
rdict.StreamerInfos.Add(rdict.NewCxxStreamerInfo("ROOT::VecOps::RVec<int>", 6, 0xbc2043d1, []rbytes.StreamerElement{
152+
rdict.NewCxxStreamerSTL(rdict.Element{
153+
Name: *rbase.NewNamed("This", "<Int_t> Used to call the proper TStreamerInfo case"),
154+
Type: rmeta.Streamer,
155+
Size: 0,
156+
ArrLen: 0,
157+
ArrDim: 0,
158+
MaxIdx: [5]int32{0, 0, 0, 0, 0},
159+
Offset: 0,
160+
EName: "ROOT::VecOps::RVec<int>",
161+
XMin: 0.000000,
162+
XMax: 0.000000,
163+
Factor: 0.000000,
164+
}.New(), 14, 3),
165+
}))
166+
}
167+
168+
var (
169+
_ root.Object = (*ROOT__VecOps__RVec_int_)(nil)
170+
_ rbytes.RVersioner = (*ROOT__VecOps__RVec_int_)(nil)
171+
_ rbytes.Marshaler = (*ROOT__VecOps__RVec_int_)(nil)
172+
_ rbytes.Unmarshaler = (*ROOT__VecOps__RVec_int_)(nil)
173+
)

groot/rdict/gen_type.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (g *genGoType) genField(si rbytes.StreamerInfo, i int, se rbytes.StreamerEl
196196

197197
case *StreamerSTL:
198198
switch se.STLType() {
199-
case rmeta.STLvector, rmeta.STLmap:
199+
case rmeta.STLvector, rmeta.STLmap, rmeta.STLend:
200200
tname := g.typename(se)
201201
g.printf(docFmt, se.Name(), tname, g.stag(i, se), doc)
202202
default:
@@ -317,7 +317,7 @@ func (g *genGoType) typename(se rbytes.StreamerElement) string {
317317

318318
case *StreamerSTL:
319319
switch se.STLType() {
320-
case rmeta.STLvector:
320+
case rmeta.STLvector, rmeta.STLend:
321321
switch se.ContainedType() {
322322
case rmeta.Bool:
323323
return "[]bool"
@@ -420,6 +420,9 @@ func (g *genGoType) cxx2go(name string, qual qualKind) string {
420420
}
421421
name = f(name)
422422
name = strings.Replace(name, "::", "__", -1) // handle namespaces
423+
name = strings.Replace(name, "<", "_", -1) // handle C++ templates
424+
name = strings.Replace(name, ">", "_", -1) // handle C++ templates
425+
name = strings.Replace(name, ",", "_", -1) // handle C++ templates
423426
return prefix + name
424427
}
425428

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

612615
case *StreamerSTL:
613616
switch se.STLType() {
614-
case rmeta.STLvector:
617+
case rmeta.STLvector, rmeta.STLend:
615618
wfunc := ""
616619
switch se.ContainedType() {
617620
case rmeta.Bool:
@@ -872,7 +875,7 @@ func (g *genGoType) genUnmarshalField(si rbytes.StreamerInfo, i int, se rbytes.S
872875

873876
case *StreamerSTL:
874877
switch se.STLType() {
875-
case rmeta.STLvector:
878+
case rmeta.STLvector, rmeta.STLend:
876879
rfunc := ""
877880
switch se.ContainedType() {
878881
case rmeta.Bool:

0 commit comments

Comments
 (0)