Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
This repository was archived by the owner on Jun 21, 2022. It is now read-only.

IndexError while reading a vector of custom class objects from tree #475

@bglenardo

Description

@bglenardo

Hi,

I have a use case in which we have a branch which is a vector of a custom class objects (in our case, the class is called ElecChannel), and I would like to access individual members of this object (which include some vector<short> objects). If I try following the instructions from Issue #371 , I get an IndexError:

elec = TFile['Event/Elec/ElecEvent']
obj = elec['fElecChannels'].array()[0]



---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-17-4e71d5389b06> in <module>
      1 elec = TFile['Event/Elec/ElecEvent']
      2 print(elec.show())
----> 3 obj = elec['fElecChannels'].array()[0]
      4 
      5 #branch = elec['ElecEvent']['fElecChannels']

~/localpythonpackages/lib/python3.7/site-packages/awkward/array/objects.py in __getitem__(self, where)
    191         if self._util_isinteger(head):
    192             if isinstance(tail, tuple) and tail == ():
--> 193                 return self.generator(content, *self._args, **self._kwargs)
    194             else:
    195                 return self.generator(content, *self._args, **self._kwargs)[tail]

~/localpythonpackages/lib/python3.7/site-packages/uproot/interp/objects.py in __call__(self, arg)
    377             source = uproot.source.source.Source(bytes)
    378             cursor = uproot.source.cursor.Cursor(0, origin=origin)
--> 379             return self.cls.read(source, cursor, self.context, None)
    380         def __repr__(self):
    381             if isinstance(self.cls, type):

~/localpythonpackages/lib/python3.7/site-packages/uproot/interp/objects.py in read(self, source, cursor, context, parent)
     68             out = [None] * numitems
     69             for i in range(numitems):
---> 70                 out[i] = self.cls.read(source, cursor, context, parent)
     71             return out
     72 

~/localpythonpackages/lib/python3.7/site-packages/uproot/rootio.py in read(cls, source, cursor, context, parent)
    963             context = context.copy()
    964         out = cls.__new__(cls)
--> 965         out = cls._readinto(out, source, cursor, context, parent)
    966         out._postprocess(source, cursor, context, parent)
    967         return out

~/localpythonpackages/lib/python3.7/site-packages/uproot/rootio.py in _readinto(cls, self, source, cursor, context, parent, asclass)

~/localpythonpackages/lib/python3.7/site-packages/uproot/source/cursor.py in array(self, source, length, dtype)
     59         start = self.index
     60         stop = self.index = start + length*dtype.itemsize
---> 61         return source.data(start, stop, dtype)
     62 
     63     def string(self, source):

~/localpythonpackages/lib/python3.7/site-packages/uproot/source/source.py in data(self, start, stop, dtype)
     39 
     40         if stop > len(self._source):
---> 41             raise IndexError("indexes {0}:{1} are beyond the end of data source of length {2}".format(start, stop, len(self._source)))
     42 
     43         if dtype is None:

IndexError: indexes 611:268436067 are beyond the end of data source of length 4787

Using show tells me that the fElecChannels branch is being interpreted as a generic object, though I'm not sure exactly what that means:

ElecEvent                  TStreamerInfo              None
nEXO::EventObject          TStreamerInfo              asgenobj(nEXO_3a3a_EventObject)
fElecChannels              TStreamerSTL               asgenobj(STLVector(nEXO_3a3a_ElecChannel))
fNTE                       TStreamerBasicType         asdtype('>i4')
fEnergy                    TStreamerBasicType         asdtype('>f4')
fmc_charge                 TStreamerSTL               asjagged(asdtype('>f4'), 10)
fmc_tepos                  TStreamerSTL               None

Is there a way I can read this out into arrays?

An example file can be found here

Thanks so much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions