Segmentation violation when passing TChain to RDataFrame in PyRoot

Dear experts,

I am having problems on initializing a RDataFrame passing a TChain in pyroot.
Here is a snippet of the code:

ch = TChain("L0ToPPi_LL_VeryHighPT/DecayTree")
           
ch.Add("/eos/lhcb/grid/prod/lhcb/LHCb/Collision22/PID_TUPLE.ROOT/00186010/0000/00186010_00000001_1.pid_tuple.root")
dataframe = RDataFrame(ch)

When I try to pass the TChain to the RDataFrame I get the following error:

 *** Break *** segmentation violation
 Generating stack trace...
 0x00007f85715a9579 in ROOT::Internal::RDF::GetBranchNames[abi:cxx11](TTree&, bool) + 0xb9 from /eos/home-i02/s/sokamura/miniconda3/envs/rich_perf/lib/libROOTDataFrame.so.6.28.00
 0x00007f85715a96b2 in ROOT::Detail::RDF::RLoopManager::GetBranchNames[abi:cxx11]() + 0x72 from /eos/home-i02/s/sokamura/miniconda3/envs/rich_perf/lib/libROOTDataFrame.so.6.28.00
 0x00007f85e9b221d3 in <unknown function>
 0x00007f85e9b22049 in <unknown function>
 0x00007f8584567a88 in <unknown> from /eos/home-i02/s/sokamura/miniconda3/envs/rich_perf/bin/../lib/libcppyy_backend3_11.so.6.28
 0x00007f85845690db in Cppyy::CallO(long, void*, unsigned long, void*, unsigned long) + 0x9b from /eos/home-i02/s/sokamura/miniconda3/envs/rich_perf/bin/../lib/libcppyy_backend3_11.so.6.28
 0x00007f8583cdf6d9 in <unknown> from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583cc9966 in <unknown> from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583cca689 in CPyCppyy::CPPMethod::Execute(void*, long, CPyCppyy::CallContext*) + 0x59 from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583ccb79d in CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object*, _object*, CPyCppyy::CallContext*) + 0xad from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583cd155f in <unknown> from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583cff06e in <unknown> from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x000056426284ce13 in _PyObject_MakeTpCall + 0x263 from python
 0x000056426285985d in _PyEval_EvalFrameDefault + 0x81d from python
 0x0000564262911326 in <unknown> from python
 0x00005642629109df in PyEval_EvalCode + 0x9f from python
 0x000056426292f36a in <unknown> from python
 0x000056426292b773 in <unknown> from python
 0x0000564262940710 in <unknown> from python
 0x000056426294008e in _PyRun_SimpleFileObject + 0x1ae from python
 0x000056426293fe74 in _PyRun_AnyFileObject + 0x44 from python
 0x000056426293a01f in Py_RunMain + 0x2df from python
 0x00005642628ff4b7 in Py_BytesMain + 0x37 from python
 0x00007f8673593555 in __libc_start_main + 0xf5 from /lib64/libc.so.6
 0x00005642628ff35d in <unknown> from python
 *** Break *** segmentation violation
 Generating stack trace...
 0x00007f85715a9579 in ROOT::Internal::RDF::GetBranchNames[abi:cxx11](TTree&, bool) + 0xb9 from /eos/home-i02/s/sokamura/miniconda3/envs/rich_perf/lib/libROOTDataFrame.so.6.28.00
 0x00007f85715a96b2 in ROOT::Detail::RDF::RLoopManager::GetBranchNames[abi:cxx11]() + 0x72 from /eos/home-i02/s/sokamura/miniconda3/envs/rich_perf/lib/libROOTDataFrame.so.6.28.00
 0x00007f85e9b221d3 in <unknown function>
 0x00007f85e9b22049 in <unknown function>
 0x00007f8584567a88 in <unknown> from /eos/home-i02/s/sokamura/miniconda3/envs/rich_perf/bin/../lib/libcppyy_backend3_11.so.6.28
 0x00007f85845690db in Cppyy::CallO(long, void*, unsigned long, void*, unsigned long) + 0x9b from /eos/home-i02/s/sokamura/miniconda3/envs/rich_perf/bin/../lib/libcppyy_backend3_11.so.6.28
 0x00007f8583cdf6d9 in <unknown> from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583cc9966 in <unknown> from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583cca689 in CPyCppyy::CPPMethod::Execute(void*, long, CPyCppyy::CallContext*) + 0x59 from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583ccb79d in CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object*, _object*, CPyCppyy::CallContext*) + 0xad from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583cd155f in <unknown> from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x00007f8583cff06e in <unknown> from /eos/user/s/sokamura/miniconda3/envs/rich_perf/lib/python3.11/site-packages/libcppyy3_11.so
 0x000056426284ce13 in _PyObject_MakeTpCall + 0x263 from python
 0x000056426285985d in _PyEval_EvalFrameDefault + 0x81d from python
 0x0000564262911326 in <unknown> from python
 0x00005642629109df in PyEval_EvalCode + 0x9f from python
 0x000056426292f36a in <unknown> from python
 0x000056426292b773 in <unknown> from python
 0x0000564262940710 in <unknown> from python
 0x000056426294008e in _PyRun_SimpleFileObject + 0x1ae from python
 0x000056426293fe74 in _PyRun_AnyFileObject + 0x44 from python
 0x000056426293a01f in Py_RunMain + 0x2df from python
 0x00005642628ff4b7 in Py_BytesMain + 0x37 from python
 0x00007f8673593555 in __libc_start_main + 0xf5 from /lib64/libc.so.6
 0x00005642628ff35d in <unknown> from python

I have already checked and file and tree both exist.
I am using root 6.28.

   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/00                        https://root.cern |
  | (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Mar 21 2023, 07:29:00                 |
  | From tag , 3 February 2023                                       |
  | With                                                             |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

Am I missing something simple?

Thanks!

Hello @Shinichi ,

and welcome to the ROOT forum!

The snippet you posted should work just fine, here I’m running it in a conda environment with ROOT v6.28.00:

~ cat foo.py                                                                                                       (root-agc)
import ROOT

ch = ROOT.TChain("L0ToPPi_LL_VeryHighPT/DecayTree")
ch.Add("/eos/lhcb/grid/prod/lhcb/LHCb/Collision22/PID_TUPLE.ROOT/00186010/0000/00186010_00000001_1.pid_tuple.root")
dataframe = ROOT.RDataFrame(ch)
~ python foo.py                               
~                    

I imagine the complete reproducer is more complicated? Could it be you are encountering Invalid RDataFrames returned from functions in pyROOT when constructing from a TChain due to garbage collection · Issue #10965 · root-project/root · GitHub ?

Cheers,
Enrico

Hello @eguiraud,

Thanks for the quick reply!
Indeed it was a problem related to the issue reported here:
https://github.com/root-project/root/issues/10965

I was able to solve it by defining the TChain in C++ via the gInterpreter, as suggested in the post.

ROOT.gInterpreter.Declare(
f"""
    #include <TFile.h>
    TChain chain;
    void fill_chain() {{
        std::vector<std::string> paths = {{\"{'","'.join(list_paths)}\"}};
        std::string tree = "{self.tree}";
        for (const auto& path : paths) {{
            std::unique_ptr<TFile> myFile(TFile::Open(path.c_str()));
            if(myFile->GetDirectory("L0ToPPi_LL_VeryHighPT")){{
                chain.Add((path + "?#" + tree).c_str());
            }}
        }}
    }}
"""
)
ROOT.fill_chain()
self.dataframe = RDataFrame(ROOT.chain)

Many thanks for the support and sorry for the late reply!

Cheers,
Shinichi

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