Skip to content

Commit

Permalink
groot/rdict: add r/w-streamer+type handling for TString
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Feb 16, 2022
1 parent 480971d commit b467854
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
17 changes: 16 additions & 1 deletion groot/rdict/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,29 @@ func TypeFromSI(ctx rbytes.StreamerInfoContext, si rbytes.StreamerInfo) (reflect
}

switch {
case name == "TString":
if len(si.Elements()) == 0 {
sinfo := si.(*StreamerInfo)
sinfo.elems = append(sinfo.elems, &StreamerBasicType{
StreamerElement: Element{
Name: *rbase.NewNamed("This", ""),
Type: rmeta.TString,
Size: 25,
MaxIdx: [5]int32{0, 0, 0, 0, 0},
EName: "TString",
}.New(),
})
}
return gotypes[reflect.String], nil

case name == "string", name == "std::string":
if len(si.Elements()) == 0 {
// fix for old (v=2) streamer for string
sinfo := si.(*StreamerInfo)
sinfo.elems = append(sinfo.elems, &StreamerSTLstring{
StreamerSTL: StreamerSTL{
StreamerElement: Element{
Name: *rbase.NewNamed("This", ""),
Name: *rbase.NewNamed("This", "Used to call the proper TStreamerInfo case"),
Type: rmeta.STLstring,
Size: 32,
MaxIdx: [5]int32{0, 0, 0, 0, 0},
Expand Down
12 changes: 12 additions & 0 deletions groot/rdict/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ func TestTypeFromSI(t *testing.T) {
}(),
want: reflect.TypeOf((*rbase.Object)(nil)).Elem(),
},
{
name: "TString",
si: func() rbytes.StreamerInfo {
const name = "TString"
si, ok := rdict.StreamerInfos.Get(name, -1)
if !ok {
t.Fatalf("could not load streamer for %q", name)
}
return si
}(),
want: reflect.TypeOf((*string)(nil)).Elem(),
},
{
name: "TNamed",
si: func() rbytes.StreamerInfo {
Expand Down
36 changes: 36 additions & 0 deletions groot/rdict/z_tstring_streamer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright ©2022 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package rdict

import (
"fmt"

"go-hep.org/x/hep/groot/rbase"
"go-hep.org/x/hep/groot/rmeta"
)

func init() {
si, ok := StreamerInfos.Get("TString", -1)
if !ok {
panic(fmt.Errorf("rdict: could not get streamer info for TString"))
}
if len(si.Elements()) != 0 {
return
}

// FIXME(sbinet): the ROOT/C++ streamer for TString is a simple placeholder.
// but groot relies on the actual list of StreamerElements to generate the r/w-streaming code.
// So, apply this "regularization" and hope for the best.
sinfo := si.(*StreamerInfo)
sinfo.elems = append(sinfo.elems, &StreamerBasicType{
StreamerElement: Element{
Name: *rbase.NewNamed("This", "Used to call the proper TStreamerInfo case"),
Type: rmeta.TString,
Size: 25,
MaxIdx: [5]int32{0, 0, 0, 0, 0},
EName: "TString",
}.New(),
})
}

0 comments on commit b467854

Please sign in to comment.