go-hep.org/x/hep@v0.38.1/groot/riofs/streamers.go (about) 1 // Copyright ©2017 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package riofs 6 7 import ( 8 "fmt" 9 "reflect" 10 11 "go-hep.org/x/hep/groot/rbytes" 12 "go-hep.org/x/hep/groot/rdict" 13 "go-hep.org/x/hep/groot/rmeta" 14 "go-hep.org/x/hep/groot/root" 15 ) 16 17 func stdvecSIFrom(name, ename string, ctx rbytes.StreamerInfoContext) rbytes.StreamerInfo { 18 if etyp, ok := rmeta.CxxBuiltins[ename]; ok { 19 return rdict.StreamerOf(ctx, reflect.SliceOf(etyp)) 20 } 21 esi, err := ctx.StreamerInfo(ename, -1) 22 if esi == nil || err != nil { 23 return nil 24 } 25 etyp, err := rdict.TypeFromSI(ctx, esi) 26 if err != nil || etyp == nil { 27 return nil 28 } 29 return rdict.StreamerOf(ctx, reflect.SliceOf(etyp)) 30 } 31 32 type streamerInfoStore interface { 33 addStreamer(si rbytes.StreamerInfo) 34 } 35 36 func streamerInfoFrom(obj root.Object, sictx streamerInfoStore) (rbytes.StreamerInfo, error) { 37 var ( 38 typename = obj.Class() 39 cxxtype = rdict.GoName2Cxx(typename) 40 vers = -1 41 ) 42 43 if o, ok := obj.(rbytes.RVersioner); ok { 44 vers = int(o.RVersion()) 45 } 46 47 si, ok := rdict.StreamerInfos.Get(cxxtype, vers) 48 if !ok { 49 return nil, fmt.Errorf("riofs: could not find streamer for %q (version=%d)", cxxtype, vers) 50 } 51 sictx.addStreamer(si) 52 return si, nil 53 }