Calling a class method that needs a pointer

Dear (Py)ROOT experts,

This is not really a PyROOT question, but I’m hoping someone will know the answer anyway.

I have a ROOT class, that I can compile and load (using ‘.L blah.cpp+’) from within Python. Now this class has a method that needs a pointer:

Is there any way I can call this method from python? All my attempts so far tell me ‘could not convert argument 3.’ Some web searching tells me there is a way using the ctypes module but I’m stuck with python 2.4 (which does not include ctypes) and I’d rather not go around asking people to install ctypes.

I’m sure this is also relevant for PyROOT, right? It’s nothing unusual. Any ideas on how to tackle this?

Thanks for your help,
Jeroen[/code]

Jeroen,

use of float* has the problem that you have to guarantee (both in C++ and in python) that the array passed through is large enough. A normal python float will therefore not work, and you have to decide on an array instead. Something like:[code]gROOT.LoadMacro( “blah.cpp+” )
m = MyClass()

from array import array
nelem = 5
a = array( ‘f’, [0.] * nelem )
print m.GetValue( 1., 2., a )[/code]

HTH,
Wim

Thanks Wim,

That does the trick. I know the float* is not ideal but it (the ROOT class) is not my own code. (It’s not even really an array, but always a single float.)

Cheers,
Jeroen