I have a piece of code that use PyROOT and it looks like this:
trackid = ROOT.Long()
energy_dep = ROOT.Double()
mcLink = {}
for i in range( aClus.Size() ):
for n in range( mccell.TrackEnergySize()):
mccell.GetTrackEnergySlow(n, trackid, energy_dep) #<- problem here
It raise a runtime error:
TypeError: void ecalCellMC::GetTrackEnergySlow(int n, int& trackid, double& energy_dep) =>
could not convert argument 2 (use ctypes.c_int for pass-by-ref of ints)
If I read the error code correctly the issue is the trackid parameter.
Yes, no such thing in cppyy. Note that ROOT.Double and ROOT.Long predate ctypes and p3 by a good margin, and they’ve simply become obsolete.
What ROOT.Long did/does is take advantage of the fact that the payload of a Python ‘int’ is a C long, and sizeof(int) == sizeof(long) on many systems. So, it creates a fresh Python int and accesses the underlying by reference. On p3, int objects are more complex, so can not passed by-reference this way.
The ctypes.c_int approach will work on both p2 and p3, with the old PyROOT and with cppyy. And although it’s from after the topic that you reference, that solution has been around for several years now, so should be safe to use unless you still have to deal with ROOT5.