Problem creating tree

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

Hi,

What is the result of mytree->Print(); for your TTree?

Philippe.

Hello,
here it is:


*Tree :mytree : my data *
*Entries : 2123 : Total = 18028 bytes File Size = 0 *

  •    :          : Tree compression factor =   1.00                       *
    

*Br 0 :tickData : CumSize/I:BlueListingId *
*Entries : 2123 : Total Size= 17741 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

thanks for looking into it.
l.

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.

Cheers,
l.

HI,

Use:t.Branch('tickData',AddressOf(tdata),'size/I:list')or better:t.Branch('tickData_size',AddressOf(tdata,'size'),'size/I') t.Branch('tickData_list',AddressOf(tdata,'list'),'list/I)

Cheers,
Philippe.

Hi,

the names from the Print() don’t appear to match the code above, could you provide “datatest.csv” and the exact code being used? Thanks.

Cheers,
Wim

Philippe,

AddressOf() isn’t needed if the full struct is passed. (And staff.py still works, after all :slight_smile: ).

Cheers,
Wim

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:

TDatime UTCtime;\

and I create a branch:

tree.Branch(‘UTCtime’,AddressOf(tdata,‘UTCtime’),‘UTCtime’)

then I get the value using:

tData.UTCtime = t[3]

but I get the following error:

tData.UTCtime = t[3]

RuntimeError: property type mismatch or assignment not allowed

Thanks!
lore

Hi,

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.

Hi,

[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.

Cheers,
Wim

ok thanks Wim,
will try.
l.