Matching python wrapped objects

dear pyROOT experts,

I would like to match the python binding of ROOT objects with external libraries (for example, functions) using pointers to those objects.
To give the idea, I prepared 2 examples:
matchedWrappers.tgz contains an example in which a class is defined, compiled in a so library; a second library is prepared, which links to the first one, and wrappers are generated using swig for both. Then a test is run, by importing the wrapper libraries.

unmatchedWrappers.tgz behaves similarly, but the fact that the first library this time is taken from ROOT.
basically, I would like to call the functions in the libMC.so from python, importing ROOT and the _MC.so wrapper.

This is not working, I assume because ROOT bindings to python are more complicated and not compatible with auto-generated swig ones. I see the error is in the swig pointer conversion method inside the wrapper .cc file, which return NULL.
Using swig %typemaps is not helping me here, all I am able to do is to conver a PyObject * to 0x0, and therefore a segfault crash.

Of course, all of this works if one generate the dictionaries and load them in python using ROOT.
The example in the second tgz file covers these 2 cases, showing that when using the dictionaries everything works fine.

I would like however to grant access to the libraries using the auto-generated swig wrappers, in order to introduce no changes to already existing code, and at the same time expanding it with ROOT functionalities. Is there any possibility to do this?
I think I should instruct the swig wrapper to use the already-existing ROOT bindings; but how?

thank you very much in advance.

regards,
federico
unmatchedWrappers.tgz (1.49 KB)
matchedWrappers.tgz (1.1 KB)

Hi,

PyROOT does not know SWIG internals and vice-versa. Both do know CObjects. To convert a PyROOT-bound object to a CObject, do:cobj= ROOT.AsCObject(obj)and back like so:klass = type(obj) # or use ROOT.SomeClass, or a string "classname" obj = ROOT.BindObject(cobj, klass)
Cheers,
Wim

Dear Wim,

thank you very much for your answer.
This trick did the work from python side, thanks.

cheers,
federico