Access array branches in RDataFrame

When I try to access an array branch using RDataFrame, I get an error:

In [1]: import ROOT

In [2]: df = ROOT.RDataFrame('<treename>', 'root://<path/to/file>.root')

In [3]: h = df.Define('test', 'Lc1_Added_MotherH_M[0]').Histo1D('test')

In [4]: h.Draw()

 *** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[/Applications/root_build/lib/libROOTDataFrame.so] ROOT::Detail::RDF::RLoopManager::RunAndCheckFilters(unsigned int, long long) /Library/Developer/CommandLineTools/usr/include/c++/v1/iterator:1371
[/Applications/root_build/lib/libROOTDataFrame.so] ROOT::Detail::RDF::RLoopManager::RunTreeReader() /Applications/root/tree/dataframe/src/RLoopManager.cxx:282
[/Applications/root_build/lib/libROOTDataFrame.so] ROOT::Detail::RDF::RLoopManager::Run() /Applications/root/tree/dataframe/src/RLoopManager.cxx:468
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[/Applications/root_build/lib/libPyROOT.so] FastCall(long, void*, void*, void*) /Applications/root/bindings/pyroot/src/Cppyy.cxx:407
[/Applications/root_build/lib/libPyROOT.so] Cppyy::CallR(long, void*, void*) /Applications/root/bindings/pyroot/src/Cppyy.cxx:0
[/Applications/root_build/lib/libPyROOT.so] PyROOT::TCppObjectRefExecutor::Execute(long, void*, PyROOT::TCallContext*) /Applications/root/bindings/pyroot/src/Executors.cxx:73
[/Applications/root_build/lib/libPyROOT.so] PyROOT::TMethodHolder::CallFast(void*, long, PyROOT::TCallContext*) /Applications/root/bindings/pyroot/src/TMethodHolder.cxx:110
[/Applications/root_build/lib/libPyROOT.so] PyROOT::TMethodHolder::CallSafe(void*, long, PyROOT::TCallContext*) /Applications/root/bindings/pyroot/src/TMethodHolder.cxx:122
[/Applications/root_build/lib/libPyROOT.so] PyROOT::TMethodHolder::Execute(void*, long, PyROOT::TCallContext*) /Applications/root/bindings/pyroot/src/TMethodHolder.cxx:0
[/Applications/root_build/lib/libPyROOT.so] PyROOT::TMethodHolder::Call(PyROOT::ObjectProxy*&, _object*, _object*, PyROOT::TCallContext*) /Applications/root/bindings/pyroot/src/TMethodHolder.cxx:585
[/Applications/root_build/lib/libPyROOT.so] PyROOT::(anonymous namespace)::mp_call(PyROOT::MethodProxy*, _object*, _object*) /Applications/root/bindings/pyroot/src/MethodProxy.cxx:598
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyObject_CallMethod (no debug info)
[/Applications/root_build/lib/libPyROOT.so] (anonymous namespace)::DeRefGetAttr(_object*, _object*) /Applications/root/bindings/pyroot/src/Pythonize.cxx:116
[/Applications/root_build/lib/libPyROOT.so] PyROOT::im_call(_object*, _object*, _object*) /Applications/root/bindings/pyroot/src/TCustomPyTypes.cxx:244
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyObject_CallFunctionObjArgs (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] slot_tp_getattr_hook (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] fast_function (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] fast_function (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] fast_function (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] fast_function (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] fast_function (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] fast_function (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] function_call (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyObject_Call (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] fast_function (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalFrameEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCodeEx (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyEval_EvalCode (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyRun_FileExFlags (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] PyRun_SimpleFileExFlags (no debug info)
[/Users/michael/anaconda2/lib/libpython2.7.dylib] Py_Main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
[<unknown binary>] (no debug info)
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-4-a6939a795bb1> in <module>()
----> 1 h.Draw()

SystemError: TH1D& ROOT::RDF::RResultPtr<TH1D>::operator*() =>
    problem in C++; program state has been reset

The RDataFrame documentation suggests that I should declare the branch to be of type RVec<T>, but I have not found any examples of this. Conversely, the RVec documentation suggests that RVec is just used implicitly by RDataFrame, i.e., that I should be able to use the array notation directly.

What am I doing wrong?


ROOT Version: 6.17/01
Platform: macOS
Compiler: Not Provided


Hi,

I do not see anything wrong with the code. Could you share the file with us?

Cheers,
D

Not sure what the best way to share it with you would be, but here it is on EOS:

root://eoslhcb.cern.ch//eos/lhcb/user/m/mwilkins/LcLc/data/16/Down/890.0/DVnTuples.root

Hi,

thanks. Unfortunately I do not manage to access the file: does it exist? Is there a typo in the name?

Cheers,
D

Perhaps the permissions are not set up for you to access it. If you have a preferred method, let me know.

$ rootl root://eoslhcb.cern.ch//eos/lhcb/user/m/mwilkins/LcLc/data/16/Down/890.0/DVnTuples.root
root [0] 
Attaching file root://eoslhcb.cern.ch//eos/lhcb/user/m/mwilkins/LcLc/data/16/Down/890.0/DVnTuples.root as _file0...
(TFile *) 0x7fcd73a03f30
root [1] .ls
TNetXNGFile**		root://eoslhcb.cern.ch//eos/lhcb/user/m/mwilkins/LcLc/data/16/Down/890.0/DVnTuples.root	Gaudi Trees
 TNetXNGFile*		root://eoslhcb.cern.ch//eos/lhcb/user/m/mwilkins/LcLc/data/16/Down/890.0/DVnTuples.root	Gaudi Trees
  KEY: TDirectoryFile	LcpTree;1	LcpTree
  KEY: TDirectoryFile	SczTree;1	SczTree
  KEY: TDirectoryFile	ScPTree;1	ScPTree
  KEY: TDirectoryFile	X2LcpLcpTree;1	X2LcpLcpTree
  KEY: TDirectoryFile	X2SczLcpTree;1	X2SczLcpTree
  KEY: TDirectoryFile	X2ScPLcpTree;1	X2ScPLcpTree
  KEY: TDirectoryFile	X2SczSczTree;1	X2SczSczTree
  KEY: TDirectoryFile	X2ScPSczTree;1	X2ScPSczTree
  KEY: TDirectoryFile	X2ScPScPTree;1	X2ScPScPTree
  KEY: TDirectoryFile	X2LcpLcmTree;1	X2LcpLcmTree
  KEY: TDirectoryFile	X2SczLcmTree;1	X2SczLcmTree
  KEY: TDirectoryFile	X2ScPLcmTree;1	X2ScPLcmTree
  KEY: TDirectoryFile	X2SczScZTree;1	X2SczScZTree
  KEY: TDirectoryFile	X2ScPScZTree;1	X2ScPScZTree
  KEY: TDirectoryFile	X2ScPScMTree;1	X2ScPScMTree
  KEY: TDirectoryFile	GetIntegratedLuminosity;1	GetIntegratedLuminosity

Hi,

perhaps you can share with me the file or part of it? For example, you can send me the location where I have access or a CERNBox share privately and not on the public forum.

Cheers,
D

I’ve sent you a link via private message.

Have you had any luck diagnosing the problem?

Hi,

the problem is that sometimes the array contained in the branch has lenght 0. For this reason, we’d need to filter out those events in order to avoid invalid memory accesses:

import ROOT
df = ROOT.RDataFrame("X2LcpLcmTree/DecayTree", "DVnTuples.root")
h = df.Filter('!Lc1_Added_MotherH_M.empty()').Define('test', 'Lc1_Added_MotherH_M[0]').Histo1D('test')
h.Draw()

Cheers,
D

Thank you! That solved it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.