scikit-hep / root_numpy

The interface between ROOT and NumPy

Home Page:http://scikit-hep.org/root_numpy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when duplicated branch is found

rdisipio opened this issue · comments

Hi,

I tried to convert a ROOT tree into an array using root_numpy. However, I've found a behaviour that was probably unexpected. The ntuples I'm using have a sort of bug, i.e. one branch appears twice. In such a case, I get this error:

Traceback (most recent call last):
File "", line 1, in
File "/afs/cern.ch/work/d/disipio/public/ttbar_diffxs_13TeV/local/lib/python2.7/site-packages/root_numpy-4.5.0.dev0-py2.7-linux-x86_64.egg/root_numpy/_tree.py", line 203, in root2array
warn_missing_tree)
File "root_numpy/src/tree.pyx", line 446, in _librootnumpy.root2array_fromfile (root_numpy/src/_librootnumpy.cpp:446)
File "root_numpy/src/tree.pyx", line 354, in _librootnumpy.tree2array (root_numpy/src/_librootnumpy.cpp:354)
ValueError: two fields with the same name

I understand you may prefer to raise an exception in a situation like this, but producing new (fixed) ntuples can take several days. Is there any workaround? Or do you want to fix this in root_numpy, and print a warning that something weird is going on wit the tree?

Interesting. Yes, root_numpy can raise an exception in this case. You should be able to work around it for now by explicitly specifying the list of branches you want:

from root_numpy import list_branches, root2array
root2array('root_numpy/testdata/single1.root', branches=list_branches('root_numpy/testdata/single1.root'))

list_branches will always be the unique branches since it internally builds a dictionary mapping names to structures.

I'll have root_numpy show a warning if it finds duplicate branch names, and in the case of duplicates only the first occurrence of the duplicated branches in the tree's list of branches will be used.

Fixed in #253. Thanks for reporting this!