Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-2811

proper support for ndim numerical arrays

    XMLWordPrintable

Details

    • Bug
    • Status: Reopened (View Workflow)
    • Medium
    • Resolution: Unresolved
    • < v5-28-00
    • None
    • PyROOT
    • None
    • GNU/Linux

    Description

      hi,

      running the following python script:

      import ROOT
       
      f = ROOT.TFile.Open('foo.root', 'recreate')
      t = ROOT.TTree('t','t')
       
      from array import array
      import numpy as np
      d1 = array('i', [0]*10)
      d2 = np.zeros((10,),dtype=np.int32)
      d11 = array('i',[0]*(3*10))
      d22 = np.zeros((3,10),dtype=np.int32)
       
      t.Branch('d1',d1,'d1[10]/I')
      t.Branch('d2',d2,'d2[10]/I')
      t.Branch('d11',d11,'d11[3][10]/I')
      t.Branch('d22',d22,'d22[3][10]/I')
       
      def fill_evt(ievt=0):
      imax = 10
      for i in xrange(imax):
      d1[i] = \-ievt*i
      d2[i] = \-ievt*i
       
      imax,jmax = 3,10
      for i in xrange(imax):
      for j in xrange(jmax):
      d11[i*jmax \+ j] = ievt*(-i-j)
      d22[i][j] = ievt*(-i-j)
      t.Fill()
       
      for i in xrange(10):
      fill_evt(i)
       
      t.Write()
      f.Write()
      f.Close()

      will work and produce a foo.root file, which, when read-back:

      $ pyroot.py
      pyroot&amp;gt; f = ROOT.TFile.Open('foo.root')
      pyroot&amp;gt; t = f.Get('t')
      pyroot&amp;gt; t.GetEntries()
      10L
      pyroot&amp;gt; t.GetEntry(1)
      320
      pyroot&amp;gt; t.d1[:]
      '\x00\x00\x00\x00\xff\xff\xff\xff\xfe\xff'
      pyroot&amp;gt; t.d1
      &amp;lt;read-write buffer ptr 0x1feb180, size 10 at 0x159b130&amp;gt;
      pyroot&amp;gt; list(t.d1)
      [0, \-1, \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9]
      pyroot&amp;gt; list(t.d2)
      [0, \-1, \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9]
      pyroot&amp;gt; list(t.d22)
      [ 0, \-1, \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9,
      \-1, \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9, \-10,
      \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9, \-10, \-11]
      pyroot&amp;gt; list(t.d11)
      [ 0, \-1, \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9,
      \-1, \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9, \-10,
      \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9, \-10, \-11]
      pyroot&amp;gt; t.d22
      &amp;lt;read-write buffer ptr 0x1fec7a0, size 30 at 0x159b130&amp;gt;
      pyroot&amp;gt; list(t.d22)
      [ 0, \-1, \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9,
      \-1, \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9, \-10,
      \-2, \-3, \-4, \-5, \-6, \-7, \-8, \-9, \-10, \-11]

      ie: the d22 array has lost its rank and shape informations.

      probably some support of the &quot;new&quot; PEP 3118 buffer protocol would improve the state of things...
      http://www.python.org/dev/peps/pep-3118/

      cheers,
      sebastien.

      Attachments

        Activity

          People

            etejedor Enric Tejedor Saavedra
            binet Sebastien Binet
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: