Hi,
I am just starting to use PyROOT, so this is probably a very basic question. I am trying to store string variables in a Tree and read them back.
So far the best I could do is:
[code] gROOT.ProcessLine(
“struct invar_t {
Int_t num;
Char_t str;
};”);
from ROOT import invar_t
var = invar_t()
num = 7
st = 'something’
var.num = num
var.st = st
rfile = TFile(“test.root”, “recreate”)
treename = “tree"
tree = TTree(treename,”")
bname = "sbranch"
leaf = "num/I:st/C"
tree.Branch(bname, var, leaf)
tree.Fill()
rfile.Write()
rfile.Close()
rfile = TFile(“test.root”, “read”)
mytree = gDirectory.Get(‘tree’)
mytree.GetEntry(0)
print “num=”,mytree.num
print “str=”,mytree.st[/code]
However I don’t get my original string back from mytree.st. Could someone tell me what I am doing wrong?
Also, is there a more direct way of storing a string variable without having to create a class through gROOT.ProcessLine?
Thanks.