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

index out of bound #5

Closed
vkuznet opened this issue Sep 19, 2017 · 4 comments
Closed

index out of bound #5

vkuznet opened this issue Sep 19, 2017 · 4 comments

Comments

@vkuznet
Copy link

vkuznet commented Sep 19, 2017

If I use the following root file /afs/cern.ch/user/v/valya/public/relval-qcd-7.4.root
I get different errors. Some of them related to not implemented support to TList. But others seems to unable to parse particular tree branch. Here is code snippet to reproduce:

import uproot
import traceback

def treeContent(tree):
    print(tree.contents)
    for key in tree.contents:
        branch = key.split(';')[0]
        print("key", key, branch)
        try:
            print(tree[branch])
        except:
            traceback.print_exc()

fname = '/afs/cern.ch/user/v/valya/public/relval-qcd-7.4.root'
tree = uproot.open(fname)
treeContent(tree)

And here is traceback for index of bound error

Traceback (most recent call last):
  File "vk_test.py", line 10, in treeContent
    print(tree[branch])
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/rootio.py", line 130, in __getitem__
    return self.get(name)
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/rootio.py", line 153, in get
    return self.dir.get(name, cycle)
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/rootio.py", line 213, in get
    out = out.keys.get(n, cycle)
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/rootio.py", line 284, in get
    return key.get()
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/rootio.py", line 338, in get
    out = Deserialized.classes[self.classname](self._filewalker, self._walker)
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/tree.py", line 106, in __init__
    self.branches = list(uproot.core.TObjArray(filewalker, walker))
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/core.py", line 40, in __init__
    self.items = [uproot.rootio.Deserialized._deserialize(filewalker, walker) for i in range(nobjs)]
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/rootio.py", line 426, in _deserialize
    obj = fct(filewalker, walker)  # new object
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/tree.py", line 991, in __init__
    TBranch.__init__(self, filewalker, walker)
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/tree.py", line 512, in __init__
    self.branches = list(uproot.core.TObjArray(filewalker, walker))
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/core.py", line 40, in __init__
    self.items = [uproot.rootio.Deserialized._deserialize(filewalker, walker) for i in range(nobjs)]
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/rootio.py", line 426, in _deserialize
    obj = fct(filewalker, walker)  # new object
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/tree.py", line 991, in __init__
    TBranch.__init__(self, filewalker, walker)
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/tree.py", line 506, in __init__
    uproot.core.TNamed.__init__(self, filewalker, walker)
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/core.py", line 72, in __init__
    self.title = walker.readstring()
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/_walker/lazyarraywalker.py", line 89, in readstring
    return super(LazyArrayWalker, self).readstring(index, length)
  File "/Users/vk/Work/Languages/Python/GIT/uproot/uproot/_walker/arraywalker.py", line 91, in readstring
    length = self.data[index]
IndexError: index 84202969 is out of bounds for axis 0 with size 4785388
@jpivarski
Copy link
Member

Thank you for finding a file with long enough branch names to resolve an uncertainty I had about Sebastian's code. (I didn't know whether a particular algorithm worked the way it did because it was a Go thing or a ROOT thing. Turns out, it's a ROOT thing, so I need to read string length prefixes as big-endian numbers.)

I also put in a dummy TList implementation. I just needed to read past some objects I don't use. (Maybe when I encounter a new class, I should default to dummy instead of raising an exception.) This is #7.

So now you can read that file! I don't know how useful it would be, looking at those branch names.

>>> import uproot
>>> t = uproot.open("/afs/cern.ch/user/v/valya/public/relval-qcd-7.4.root")["Events"]
>>> t['recoVertexsedmAssociation_offlinePrimaryVerticesWithBS__RECO.obj.ids_.first.processIndex_'].array()
array([3, 3, 3, 3, 3, 3, 3, 3, 3, 3], dtype=uint16)

(By the way, in your example, you think you're working with a TTree, but actually you're working with a TFile. You need to pick ["Events"] from it.)

@vkuznet
Copy link
Author

vkuznet commented Sep 20, 2017 via email

@jpivarski
Copy link
Member

I came be sure because I couldn't tell if the Go code was reading big or little endian (due to not knowing the language). I have a backlog of small discoveries to send Sebastien. I'll get to it tonight.

@jpivarski
Copy link
Member

"can't be sure"

flome pushed a commit to flome/uproot that referenced this issue May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants