TPythia6::Initialize unbound method?

Dear experts,

Any idea what could lead to the following?

[code]Python 2.3.5 (#1, Mar 20 2005, 20:38:20)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

from ROOT import TPythia6
p = TPythia6
p.Initialize(“cms”,“p”,“p”,200)
Traceback (most recent call last):
File “”, line 1, in ?
TypeError: void TPythia6(const char* frame, const char* beam, const char* target, float win) =>
unbound method TPythia6::Initialize must be called with a TPythia6 instance as first argument
[/code]

My naive guess:

>>> TPythia6.Initialize(p,"cms","p","p",200)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: void TPythia6(const char* frame, const char* beam, const char* target, float win) =>
    unbound method TPythia6::Initialize must be called with a TPythia6 instance as first argument

also did not work.

This is running ROOT v5.14.00c built against the Apple Python 2.3.5 on a Mac with OS X 10.4.8.

Thanks,
Jeroen

Hmmm, I just managed to have Google explain me what the ‘unbound method’ message really means. (Still not quite sure but I think the main difference is that ‘pythia’ is resolved as the class type ‘TPythia6’ whereas ‘pythia()’ is resolved as the ‘pythia’ object.)

However, now I seem to be missing some symbol somewhere:

dyld: lazy symbol binding failed: Symbol not found: _s_wsfi
  Referenced from: /sw/share/root/current_gcc4.0/lib/libEGPythia6.so
  Expected in: dynamic lookup

Any ideas would be welcome again :slight_smile: (says the struggling Python newbie)

Thanks,
Jeroen

The following two lines work without any problem from the CINT/C++ side:

TPythia6 p; p.Initialize("cms","p","p",200);
Rene

Actually, even in ROOT itself I’m missing the same symbol: ‘_s_wsfi’. It looks like for some reason it does not want to load libg2c. I checked it and /sw/lib/libg2c.a exists, and /usr/lib/libg2c.a is linked to that.

Jeroen

Okay, this could be considered a newbie mistake :frowning: but I found it. When you build libPythia6.dylib using the makePythia6.macosx makefile it hard-codes $HOME/pythia6/libPythia6.dylib as the library’s install_name. But my lib lives in $HOME/pythia6/lib/libPythia6.dylib…

Anyway, that also explains why the prebuilt binary works using the same Pythia lib, since I’ve got a symlink /Users/rdm/pythia6/libPythia6.dylib pointing to the correct place.

Jeroen

Jeroen,

[quote]>>> p = TPythia6[/quote]this takes a reference to the TPythia6 class (classes are proper objects in python). It does not create an instance. For that one has to call the contructor on the class, for example:

As for unbound methods: this means that a method that is looked up through a class has not yet been associated with an instance. That is:TPythia6.Initializeis unbound, whereasp.Initialize is bound (the bound instance being ‘p’). The advantage of bound methods is that they, too, are proper objects and can be passed around through arguments where otherwise free functions are expected. For example, to the contructor of TFn objects.

HTH,
Wim

Thanks Wim,

Slowly things are dawning on me. Growing into C++ I never really gave much thought to the difference between

TObject obj;

and

TObject obj();

(so it may be that some C++ wizard will now reply about that) but I now understand that at least in Python I should.

I’ll stick a note to my screen reminding me that ‘everything is an object, also class definitions’.

Thanks,
Jeroen

Jeroen,

in C++, this:TObject obj();is a declaration of a function “obj” that returns a TObject, not the instantation of an object with the default constructor. This is why the ‘()’ had to be dropped from the syntax, as opposed to calls to a non-default ctor, such as TString s("aa"); where you do have to provide them. Then, when using the keyword new, there is no ambiguity, and you can use both with and without ‘()’ for the default ctor.

Cheers,
Wim