Problem putting Strings in a TTree

Pepe,

okay, I see that s.extname is of (python) type str, as the string gets copied over instead of having an object returned. Not sure why I did that; it probably had some boundary cases. Okay, then I’m afraid that this requires some pointer manipulation to convince all the bits and pieces as to what is supposed to be what. How about this:[code]from ROOT import *
gROOT.ProcessLine(".L tempClass.C++")

t = TTree(“t”,“t”)
s = MyClass()
stc = TClass.GetClass(“std::string”)
s_extname = stc.DynamicCast(stc, AddressOf(s, “extname”))

t.Branch(“extname”, s_extname)
for i in range(10):
s.extname = “%d” % i
// or: s_extname.replace(0, std.string.npos, “%d” % i)
t.Fill()

t.Scan()[/code] (with the caveat on replace, as per [url]Leaky strings

As for not knowing the name “extname”, that’d be solved with getattr(s, tag), but yes, that’d still be a str, as you saw. To find out about the type (perhaps needed in the TClass snippet above, if “std::string” can not be hard-wired), something like this will then do: TClass.GetClass("MyClass").GetListOfAllPublicDataMembers().FindObject(tag).GetFullTypeName()
Cheers,
Wim