I have some code that makes a tree with variable length arrays of ULong32_t values. When I try to read the tree with PyROOT (ROOT 5 or 6) I don’t get an array out. With ROOT 5, I get the address of the first value (useless) and with ROOT 6 I get the first value, but no more.
Here is some example code to make a tree and read it out:
[code]from ROOT import TFile, TTree
from array import array
f = TFile( ‘ulong64test.root’, ‘recreate’ )
t = TTree( ‘t1’, ‘tree with histos’ )
maxn = 10
n = array( ‘i’, [ 0 ] )
l = array( ‘L’, maxn*[ 0 ] )
print “on this system, an unsigned long is {0} bytes”.format(l.itemsize)
t.Branch( ‘mynum’, n, ‘mynum/I’ )
t.Branch( ‘myval’, l, ‘myval[mynum]/l’ )
for i in range(25):
n[0] = min(i,maxn)
for j in range(n[0]):
l[j] = i+j
t.Fill()
f.Write()
f.Close()
f = TFile( ‘ulong64test.root’,‘read’)
t = f.t1
t.GetEntry(6)
try:
print "mynum is: "+str(t.mynum)
print "myval is: "+str(list(t.myval))
except Exception as e:
print "Oh no!"
print e
print "myval is: "+str(t.myval)
f.Close()
[/code]
Under Python 2.7 and ROOT 5.34 I get:
[quote]on this system, an unsigned long is 8 bytes
mynum is: 6
Oh no!
‘long’ object is not iterable
myval is: 140734763860136[/quote]
and a collaborator used ROOT 6.08/04 and Python 2.7.13 and got
[quote]on this system, an unsigned long is 8 bytes
mynum is: 6
myval is: [6L][/quote]
I would expect that myval should be [6,7,8,9,10,11]
Examining the tree using .Scan() shows the expected values present in the file.
Changing to integers (switching the L to I and l to i) gives the expected result.
I can use rootpy to get the expected result, but that is an additional dependency I would like to avoid. Even if the array is constant length, I have the same problem.
Is there a way I can read my ULong64_t array data with PyROOT?
Thanks,
-Jonathan