Thanks!
Yes, I have been playing with that all day (and the night, I just finished and it’s 1am…), but I was missing a small key part, i.e., the (TF1 *) casting in the constructor of Func1.
Just for reference, this is some relevant snipplets:
[code]class Func1: public TF1 {
public:
Func1() : TF1() {};
//This constructor is primarily for the Python wrapper, so that Func1
//can be created starting from an arbitrary ROOT.TF1 object, casted to void*
//by using ROOT.AsCObject and the appropriate SWIG typemap
Func1(const char* name,void* mfcn, Double_t xmin, Double_t xmax, Int_t npar) :
TF1(name,(TF1 *)mfcn,xmin,xmax,npar) {};
Func1(const char* name, const char* formula, double xmin = 0, double xmax = 1):
TF1(name, formula, xmin, xmax) {};
}[/code]
I added this in the interface file (.i):
[code]%typemap(in) void *mfcn {
$1 = PyCObject_AsVoidPtr($input);
}
%rename (Func1_fromVoid) Func1(const char* name, void* mfcn, Double_t xmin, Double_t xmax, Int_t npar);[/code]
And this is how I can use it now:
import ROOT
import mySwigWrapper
tf1 = ROOT.TF1("test","[0]*x+[1]")
myfunc1 = mySwigWrapper.Func1_fromVoid("testFunc1",ROOT.AsCObject(tf1),-10,10,2)
print(myfunc1)
<mySwigWrapper.Func1; proxy of <Swig Object of type 'Func1 *' at 0x7fd5e33d6b40> >
In the Func1 header, note the (TF1 *) casting when initializing the base class TF1: it took me a long time to realize that I had to add that…
Now I can go on and use myfunc1 with all the other classes of the library.
Thanks for the help!