Hello,
I am running pyroot in a similar way to the staff.py example but I am getting crazy numbers in my tree. Here is the code:
#!/usr/bin/env python
import sys
from ROOT import *
import numpy
gROOT.ProcessLine(
"struct data_t {\
Int_t size;\
Int_t list;\
};" );
def fillTree():
tdata = data_t()
ff = TFile('data.root','RECREATE')
tree = TTree('mytree','my data')
tree.Branch('tdata',tdata,'size/I:list')
cc=0
for line in open('datatest.csv').readlines():
cc=cc+1
if(cc>1):
t = line.split(',')
tdata.size = int(t[0])
tdata.list = int(t[1])
print tdata.size // THIS GIVES CORRECT NUMBERS!
tree.Fill()
ff.Write()
ff.Close()
#### run fill function if invoked on CLI
if __name__ == '__main__':
fillTree()
When I open my tree and plot tdata.size I get a spike at 10^6. The file I am reading has the format:
10039,237450020
…
thet two numbers are both integers. The print statement just before filling the tree returns cotrrect numbers. Why my tree is filled with garbage?
Any help would be appreciated.
Cheers,
lore
As a matter of fact, I have tried to cut down the staff.py example and just reading my file, I get the same problem. One thing I should add is that I am running on cygwin from a windows machine.
Hello,
I fixed the problem and it was my mistake (sorry), the code works fine now, I was just using the line
tree.Branch('tdata',tdata.size,'size/I')
rather than
tree.Branch('tdata',tdata,'size/I')
I have a question now though, how can I store a UTC time in the tree? I read it from the same file in the UTCformat. What I did is to declare the variable in my data structure (just added to what i already posted) like:
For object, you need to either specify the real type:tree.Branch('UTCtime',,'TDatime',AddressOf(tdata,'UTCtime'))or better yet, do not specify the type explicitly:tree.Branch('UTCtime',AddressOf(tdata,'UTCtime'))
Cheers,
Philippe.
[quote=“lore”]tData.UTCtime = t[3]
RuntimeError: property type mismatch or assignment not allowed[/quote]
is t[3] still a string at that point? If so, what is needed first is a conversion of the string to an UTCtime object before the assignment can succeed.