Cannot instance cpp class from pyroot script

Hi,
I am trying to instance a ROOT object from a python script. The ROOT object accepts a pointer to another object as a parameter. I thought in pyroot I could just pass the object to the class without any manipulation. I also tried passing the cppyy functions, AddressOf(obj) and addressof(obj) to the constructor.

I have uploaded photos of the constructor, the python script and the error. To reproduce the error is not trivial however if someone would like to I can help with doing that.

Thank you in advance for any help, Andrew



digi_script

ROOT Version: 6.24/00
Platform: Unsure what this is
Compiler: c++ (GCC) 7.3.0


Hello,

Yes you should be able to pass a Python object to a C++ method that expects a pointer to a C++ object (provided that the types match). So no need to use AddressOf here.

What is the result of type(mufilterpoint) in your script?

Hi,

The result of that is: <class cppyy.gbl.MuFilterPoint at 0x2d86298> it is in the terminal output photo I uploaded but I didn’t specify that.
Cheers

The type seems correct, then.

What is the segfault you get? Do you have any information?

One thing to try (if possible) is to comment out all the code in MuFilterHit::MuFilterHit(MuFilterPoint *p), to see if the invocation itself works (there might be a crash inside the code of the function).

Hi, Thanks for that advice. I have located the error, it is coming from line 45 in the constructor. I assume “MuFilter” is not a module known to FairRunSim. Although I then tried to print FairRunSim::Instance()->GetListOfModules but this again caused a segmentation violation.

I see, it seems then an issue on the C++ side. Note that you can still use gdb even if you are launching that code from Python.