Reading TTrees which contain classes returning std:vector in Pyroot

Hello,
I am reading a TTree in pyroot (arborescence attached). I can access all class members which return a constant without problem but I am having issues while accessing a class member that returns a cpp std:: vector. It gives me a segmentation fault (see below).

Here is a code snippet:

rootfile=ROOT.TFile(filename)
mc_particle= rootfile.Get('MCParticle')
pixel_charge= rootfile.Get('PixelCharge')
prop_charge= rootfile.Get('PropagatedCharge')
pixel_hit= rootfile.Get('PixelHit')
mc_particle.Print()

for iev in range(0, pixel_hit.GetEntries()):
    pixel_hit.GetEntry(iev)
    pixel_charge.GetEntry(iev)
    mc_particle.GetEntry(iev)

    pixel_charge_branch= pixel_charge.detector
    pixel_hit_branch= pixel_hit.detector
    mc_particle_branch= mc_particle.detector

    for mc_part in mc_particle_branch:
        print "part:", mc_part.getParticleID()

    for pix_charge in pixel_charge_branch:
        print "charge:", pix_charge.getCharge()

    for pix_hit in pixel_hit_branch:
        print "hit",pix_hit.getSignal() #this works and returns what is expected
        print "local center:",pix_hit.getPixel().getLocalCenter().x() # this also 
        print type(pix_hit.getMCParticles()) # this seg faults (output below)
       #also tried e.g pix_hit.getMCParticles().getParticleID() # this seg faults (output below)

and part of the output is below. As you can see hit and local center are printed out without problem but I get a crash when accessing getMCParticles which returns a std::vector. This getMCParticles method is understood and exists (if I try to access e.g pix_hit.getMCSometthing_not_exsiting it simply gives me an error).

Thanks a lot,
Sebastien


******************************************************************************
*Tree    :MCParticle: Tree of MCParticle                                     *
*Entries :     5000 : Total =         2130296 bytes  File  Size =     363848 *
*        :          : Tree compression factor =   5.87                       *
******************************************************************************
*Br    0 :detector  : vector<allpix::MCParticle*>                            *
*Entries :     5000 : Total  Size=    2129857 bytes  File Size  =     362730 *
*Baskets :       68 : Basket Size=      32000 bytes  Compression=   5.87     *
*............................................................................*
<class 'ROOT.TTree'>
5000
5000
5000
part: 22
part: 11
charge: 1066
hit 1066.0
local center: 0.0

 *** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/Applications/root_v6.10.08/lib/libPyROOT.so] Cppyy::CallO(long, void*, void*, long) (no debug info)
[/Applications/root_v6.10.08/lib/libPyROOT.so] PyROOT::TCppObjectByValueExecutor::Execute(long, void*, PyROOT::TCallContext*) (no debug info)
[/Applications/root_v6.10.08/lib/libPyROOT.so] PyROOT::TMethodHolder::CallFast(void*, long, PyROOT::TCallContext*) (no debug info)
[/Applications/root_v6.10.08/lib/libPyROOT.so] PyROOT::TMethodHolder::CallSafe(void*, long, PyROOT::TCallContext*) (no debug info)
[/Applications/root_v6.10.08/lib/libPyROOT.so] PyROOT::TMethodHolder::Execute(void*, long, PyROOT::TCallContext*) (no debug info)
[/Applications/root_v6.10.08/lib/libPyROOT.so] PyROOT::TMethodHolder::Call(PyROOT::ObjectProxy*&, _object*, _object*, PyROOT::TCallContext*) (no debug info)
[/Applications/root_v6.10.08/lib/libPyROOT.so] PyROOT::(anonymous namespace)::mp_call(PyROOT::MethodProxy*, _object*, _object*) (no debug info)
[/System/Library/Frameworks/Python.framework/Versions/2.7/Python] PyObject_Call (no debug info)
[/System/Library/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalFrameEx (no debug info)
[/System/Library/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalCodeEx (no debug info)
[/System/Library/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalCode (no debug info)
[/System/Library/Frameworks/Python.framework/Versions/2.7/Python] (no debug info)
[/System/Library/Frameworks/Python.framework/Versions/2.7/Python] PyRun_FileExFlags (no debug info)
[/System/Library/Frameworks/Python.framework/Versions/2.7/Python] PyRun_SimpleFileExFlags (no debug info)
[/System/Library/Frameworks/Python.framework/Versions/2.7/Python] Py_Main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
[<unknown binary>] (no debug info)
Traceback (most recent call last):
  File "GetAPDataFile.py", line 89, in <module>
    print type(ROOT.std(pix_hit.getMCParticles()))
SystemError: vector<const allpix::MCParticle*> allpix::PixelHit::getMCParticles() =>
    problem in C++; program state has been reset


ROOT Version: v6-10-08
_Platform:_MAC OS 10.13
Compiler: clang


it would be easier to debug with a test file :slight_smile: (I think)

Hi,
here is the macro and the root file. The problem is that one must load a library from an external program (also attached), so don’t think it will run out of the box. Hope it helps in any case.

thanks,
Sebastien



GetAPDataFile.py (3.5 KB)

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