programmatically create a TClass at runtime

From: Sebastien Binet <binet_at_cern.ch>
Date: Wed, 4 May 2011 19:00:56 +0200

hi there,

I am playing with Go (the language at golang.org) and trying to see if one could use ROOT as an I/O back-end.

Go has built-in reflection capabilities so theoretically any Go struct can be described at runtime/compiletime and converted to a Reflex or CINT metadata.
Moreover, Go-struct usually have the same layout than their C cousin (that's not true for Go-strings and Go-slices (which are views into arrays))

the amount of work on my side to be able to support the below kind of code should be rather minimal:

 // ---
 type MyStruct struct {
   IntData [10]int32
   FloatData [20]float64
 }

 f := ROOT.NewFile("foo.root", "recreate")
 t := ROOT.NewTree("tree", "title")
 s := MyStruct{}

 t.Branch("mystruct", &s) // <---
 // ---

From my end, I would need to create a ROOT::TClass instance for the Go-struct MyStruct leveraging Go's "reflect" package which knows the types and offsets of each data member.

is this possible without reaching to automatically generated code ? (rootcint|genreflex)
that would simplify the amount of infrastructure to provide...

-s

PS: right now, I am just unfolding the struct and register branches like so (in pseudo-code):
  for f := range typ.Fields() {
    s := "mystruct_"+f.Name()
    field_addr := obj.Address()+f.Offset()     branch_typ := s+"/"+go2ctype[f.Type()].Name()     tree.Branch(s, field_addr, branch_typ)   }

-- 
#########################################

# Dr. Sebastien Binet
# Laboratoire de l'Accelerateur Lineaire
# Universite Paris-Sud XI
# Batiment 200
# 91898 Orsay
#########################################

  • application/pgp-signature attachment: stored
Received on Wed May 04 2011 - 19:02:11 CEST

This archive was generated by hypermail 2.2.0 : Wed May 04 2011 - 23:50:01 CEST