Filling branch with PyRoot limited

hello, I’m trying to create a ttree with PyRoot from a list but when I’m filling the tree ,only a part of the data are putted in the tree(the 20 first data only)
for example :

from ROOT import TFile, TTree
    from array import array

    L=[[1,2,[3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]],[28,29,[30,32,33,43,54,23,67,64]],[2,4,[11,54,85,64,25,97,4,23]],[18,34,[98,468,43,86,98,29,57]],[74,58,[73,58,87,34,678,43,78]]]
    f = TFile( 'test.root', 'recreate' )
    t = TTree( 't1', 'tree ' )
    maxn = 40
    n = array( 'i', [ 0 ] )
    m = array( 'i', [ 0 ] )
    o = array( 'i', [ 0 ] )
    d = array( 'i', maxn*[ 0] )
    t.Branch( 'L1', n, 'L1/I' )
    t.Branch( 'L2', m, 'L2/I' )
    t.Branch( 'L4', o, 'L4/I' )
    t.Branch( 'list', d, 'list[L4]/i' )

     
    for k in range(0,len(L)):
       n[0] = L[k][0]
       m[0] =L[k][1]
       o[0]=len(L[k][2])

       for i in range(0,o[0]):
           d[i] =L[k][2][i]
       print(d)
       t.Fill()
     
    f.Write()
    f.Close()
    print("done")

the program run without problem but when I open the root file only a part is inside:

root [1] t1->Show(0)
======> EVENT:0
 L1              = 1
 L2              = 2
 L4              = 25
 list            = 3, 
                  4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
                  14, 15, 16, 17, 18, 19, 20, 21, 22

Thanks,
Neimolim


ROOT Version: 6.16
Platform: Ubuntu 18.04


@etejedor can you help here?

1 Like

Hi @Neimolim,

I ran your script to generate the test.root file and when I read, I get the 25 expected elements for the array branch. You can use the following script to read them:

from ROOT import TFile

f = TFile( 'test.root')
t = f.t1

for e in t:
  print("INTS")
  print(e.L1)
  print(e.L2)
  print(e.L4)
  print("ARRAY OF INTS of SIZE {}".format(len(e.list)))
  for elem in e.list:
    print(elem)
  break # just to read first entry
1 Like

Hi @etejedor ,
Thank you for your answer. Indeed with your script I can see all the element so may be it’s just a wrong parameter or a display problem on ROOT function Show() in the terminal ?

Indeed Show has a lenmax parameter:

https://root.cern.ch/doc/master/classTTree.html#a10e5e7424059bc7d17502331b41b0c16

which defaults to 20 and sets the maximum number of elements of an array branch that are printed.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.