scikit-hep/root_numpy

Selection keyword arguments leads to malloc

graipher opened this issue · 12 comments

Whenever I try to use the selection keyword in either root2array or tree2array, it produces a segfault:

In [0]: from root_numpy import root2array
~/.local/lib/python2.7/site-packages/root_numpy/__init__.py:34: RuntimeWarning: ROOT 6.10/04 is currently active but you installed root_numpy against ROOT 6.10/00. Please consider reinstalling root_numpy for this ROOT version.
  RuntimeWarning)
In [1]: root2array("file_name.root", "Directory/Tree", branches=["Z0_MM"], selection="Z0_MM > 80000")
python: malloc.c:3759: _int_malloc: Assertion `(unsigned long) (size) >= (unsigned long) (nb)' failed.

The branch the selection needs to act on is included in the active branches, as you can see.

The RuntimeWarning has been there for some time (over a few re-compiles of ROOT), even after re-compiling and re-installing root_numpy from github master, but I don't think this is the cause of the bug.

Just on the off chance, what type of branch is Z0_MM? It looks like, based on this warning, it's a vector<vector<T>> which means each event has multiple values. Do you have problems when you do something like TTree::Draw("Z0_MM", "Z0_MM > 80000")?

It is a simple double. The Draw works perfectly fine:

In [1]: import ROOT
In [2]: data_file = ROOT.TFile.Open("file_name.root")
In [3]: data_tree = data_file.Get("Directory/Tree")
In [4]: data_tree.Print()
...
*............................................................................*
*Br    8 :Z0_MM     : Z0_MM/D                                                *
*Entries :  1386117 : Total  Size=   11096712 bytes  File Size  =    6504783 *
*Baskets :       74 : Basket Size=     320000 bytes  Compression=   1.71     *
*............................................................................*
...
In [5]: data_tree.Draw("Z0_MM", "Z0_MM > 80000")
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
Out[5]: 43731L

Just to eliminate whether the warning is part of the cause or not, can you send me the ROOT file somehow? (Is it on lxplus?)

ndawe commented

Also note the warning: "RuntimeWarning: ROOT 6.10/04 is currently active but you installed root_numpy against ROOT 6.10/00. Please consider reinstalling root_numpy for this ROOT version.
RuntimeWarning)" This problem could be a binary incompatibility between those releases.

ndawe commented

You will often see strange problems when updating ROOT while using root_numpy compiled against an older version of ROOT.

ndawe commented

Just pip install --user --ignore-installed root_numpy

@ndawe Yes, I see it as well and have been unable to get rid of it.

I tried doing this, after re-compiling ROOT:

sudo -H ROOTSYS=$ROOTSYS pip2 install -U --force-reinstall --user https://github.com/scikit-hep/root_numpy/zipball/master

And I now also tried using your command. In both cases I still get the warning.

ndawe commented

Hmm... try pip uninstall root_numpy a few times (answering "y" each time) to remove any duplicates. Then pip install --user root_numpy.

@ndawe This does not change anything, either. I found out, I had both a python3 and a python2 version installed, but even after removing both, I still get the warning.

@ndawe Ah, maybe I found the culprit. After uninstalling all pip versions, I can still import root_numpy...

Ok, after manually rm'ing all root_numpy versions lying around, this seems to work now.

It also solved the problem with selection.
Thanks for your quick help!

ndawe commented

Nice! I've had the same issue too after managing to get multiple copies of root_numpy installed...