Problems when deriving from a ROOT class

Hi all,

I would like to run following code:

[code]import ROOT
from array import array

ROOT.gROOT.Reset()

class MyFun(ROOT.Math.IParametricFunctionMultiDim):
def init(self):
#super(ROOT.Math.IParametricFunctionMultiDim,self).init(self)
self.p = None
print "test = ", self , “; is it null?”

def DoEvalPar(self, x,p):
return 2.*x[0]+p[0]

def NPar(self):
return 1

def NDim(self):
return 2

def Parameters(self):
return self.p

def SetParameters(self,p):
self.p=p

x = array( ‘d’, [ -2.,2.] )
p = array(‘d’,[1.] )

myfun = MyFun()
print myfun(x,p)

fitter = ROOT.Fit.Fitter()
fitdata = ROOT.Fit.BinData(1000,1,ROOT.Fit.BinData.kNoError)
fitdata.Add(0,1)
fitdata.Add(1,2)
fitdata.Add(2,3)
fitter.SetFunction(myfun)
fitter.Fit(fitdata)[/code]

but I get this error:

$ python start.py test = <ROOT.ROOT::Math::IParametricFunctionMultiDim object at 0x(nil)> ; is it null? Traceback (most recent call last): File "start.py", line 32, in <module> print myfun(x,p) ReferenceError: attempt to access a null-pointer

So the script stops at line: print myfun(x,p). It seems that there is a problem with proper creation of MyFun class (""object at 0x(nil) "). Moreover, If one tries to call super(ROOT.Math.IParametricFunctionMultiDim,self).init(self) then the output is following:

$ python start.py Traceback (most recent call last): File "start.py", line 31, in <module> myfun = MyFun() File "start.py", line 8, in __init__ super(ROOT.Math.IParametricFunctionMultiDim,self).__init__(self) TypeError: IBaseFunctionMultiDim is abstract and can not be instantiated

I guess that it is something “obvious” but i can’t figure out what it is :slight_smile:.

What is necessary to do to run this script? What is it the problem?

Cheers,
Jiri

ROOT: 5.26/00b
Python 2.6.5
linux

Hi,

deriving a python class from a ROOT one and then having the resultant instances be used on the C++ side does not work.

The only way to make this work, is to have a class in between to forward the calls from C++ (which need vtable entries setup by the compiler/linker) to python functions (which are created dynamically by the interpreter).

Some while ago I did some prototyping to have this done automagically by generating the intermediate class and letting it be compiled/loaded by ACLiC. This was never fleshed out, however.

Cheers,
Wim

Ok, I see the problem now.

[quote]
The only way to make this work, is to have a class in between to forward the calls from C++ (which need vtable entries setup by the compiler/linker) to python functions (which are created dynamically by the interpreter).

Some while ago I did some prototyping to have this done automagically by generating the intermediate class and letting it be compiled/loaded by ACLiC. This was never fleshed out, however. [/quote]

This automatic generation could be quite interesting. I hope it will be part of PyROOT one day it would symplify/solve many problems.

Thank you,
Jiri