Hi all,
Quite sometime ago I posted the following, but never got a reply.
Naturally, in the mean time I've come across more problems, so I'll
ask them all once again. ;-)
I'm trying to build a Perl interface over a huge C++ Physics analysis
library called ROOT.
A Python (+ Ruby + Java, but the Python is the best and maintained)
interface already exists
and I want to use that. Thanks to Inline::Python I've already managed to
generate interest
in the ROOT community which I've documented at
http://sarkar.home.cern.ch/sarkar/PerlROOT.
I'm no way an expert of Inline, hence had trouble with
1. Calling static methods from Python
TMath::ATan(x) -> TMath.ATan(x) -> ?
2. Operator overloading of mathematical classes
my $a = new ROOT::TLorentzVector();
my $b = new ROOT::TLorentzVector();
my $c = $a + $b;
3. Handling Python buffer object
Double_t *GetParameters()
which returns a buffer object in Python, and I do not know how to
handle that. At present I do it with a Python subroutine,
use Inline Python => <<'END_OF_PYTHON_CODE';
def getParameters(f):
par = f.GetParameters()
return par[0],par[1],par[2]
END_OF_PYTHON_CODE
4. Possibility of loop optimisation
........
to name a few. This certainly stops me to proceed further with the project.
PyROOT classes (actually generated in memory from libPyROOT.so that
describes the mapping) reside
inside the package/module ROOT such that one can do
from ROOT import gROOT, TH1F
etc. The Perl to Python mapping is described in ROOT.pm as you'll find
in my webpage.
Thanks a lot,
- Subir
Subir Sarkar wrote:
Hi all,
How can I call a static/class Python method from Perl correctly without
having to create an object first? The following simplified example
illustrates
the problem. In reality the MyClass resides in a Python module
along-with many other classes.
use Inline Python;
my $c = new MyClass('TEST');
print $c->aStaticMethod, "\n";
print $c->aClassMethod, "\n";
# How can I do that using a syntax
# similar to MyClass.aStaticMethod()
__END__
__Python__
class MyClass:
def __init__(self, name):
self.name = name
def aStaticMethod():
return 'This is a static method of MyClass.'
def aClassMethod(cls):
return 'This is a class method: %s' % repr(cls)
aStaticMethod = staticmethod(aStaticMethod)
aClassMethod = classmethod(aClassMethod)
Thanks,
- Subir