diff --git a/groot/rdict/type.go b/groot/rdict/type.go index 1ca7684f2..3bd5b58e4 100644 --- a/groot/rdict/type.go +++ b/groot/rdict/type.go @@ -29,6 +29,21 @@ 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 @@ -36,7 +51,7 @@ func TypeFromSI(ctx rbytes.StreamerInfoContext, si rbytes.StreamerInfo) (reflect 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}, diff --git a/groot/rdict/type_test.go b/groot/rdict/type_test.go index 640d37b33..f09750018 100644 --- a/groot/rdict/type_test.go +++ b/groot/rdict/type_test.go @@ -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 { diff --git a/groot/rdict/z_tstring_streamer.go b/groot/rdict/z_tstring_streamer.go new file mode 100644 index 000000000..e03d7dd59 --- /dev/null +++ b/groot/rdict/z_tstring_streamer.go @@ -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(), + }) +}