Segfault when vector(vector(struct)) with Python 2.6.6

Hi,

the following code runs fine under Python 2.7.8 but yields segfault with Python 2.6.6.
However, I have to run on this last version of python. Is there a way I could change
my code so that it runs on both versions?

Thanks,
Eric

test_cluster.py:

import ROOT

INSTALL_DIR = "mypath"

ROOT.gSystem.Load("libPhysics.so")
ROOT.gSystem.Load("libFFTW.so")
ROOT.gSystem.Load("libHtml.so")
ROOT.gSystem.Load("libTreeViewer.so")
ROOT.gSystem.Load("HEALPix.so")
ROOT.gSystem.Load(INSTALL_DIR + "wavelet.so")
ROOT.gSystem.Load(INSTALL_DIR + "wavegraph.so")

from ROOT import pixel

mycluster = ROOT.std.vector("pixel")
myclusters = ROOT.std.vector(mycluster)

with pixel declared as a simple struct

typedef struct {
  int scaleix; // scale index
  int timeix;  // time index
  int freqix;  // freq index
  int log2scale;  // scale
  double time;    // time (sec)
  double freq;    // freq (Hz)
} pixel;

[quote]ipython
Python 2.6.6 (r266:84292, Aug 12 2014, 07:57:07)
Type “copyright”, “credits” or “license” for more information.

IPython 0.10 – An enhanced Interactive Python.
? -> Introduction and overview of IPython’s features.
%quickref -> Quick reference.
help -> Python’s own help system.
object? -> Details about ‘object’. ?object also works, ?? prints more.

In [1]: run test_cluster.py
(Bool_t)1
Note: (file “(tmpfile)”, line 2) File “vector” already loaded
Segmentation fault[/quote]

Hi,

are you certain that when switching to p2.,6, you also switch any and all other libraries that have been compiled with python (PyROOT in particular) to versions that are build/linked against p2.6?

Cheers,
Wim

Hi Wim

I’m not sure to understand your question.

I thought it may help to have a simpler example that works under
python 2.7 but not under python 2.6. (tarball with all codes attached.)

I’m able to load the library in the 1st case

In [2]: ROOT.gSystem.Load(“test_cluster.so”)
Out[2]: 0

but it does not work in the second

In [2]: ROOT.gSystem.Load(“test_cluster.so”)
(Bool_t)1

Cheers,
Eric

cat test_cluster.cc

[code]#include “test_cluster.hh”

void
test_cluster(const int data){

pixel my_pix;
my_pix.data=data;
my_pix.other=0.0;

return my_pix;
}[/code]

cat test_cluster.hh

typedef struct { int data; double other; } pixel;

cat test_cluster_LinkDef.h

[code]#ifdef CINT

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ struct pixel+;

#endif // CINT[/code]

Makefile:

[code]ROOTINC=/home/waveburst/SOFT/ROOT/root-v5-32-04.patched/include

all: test_cluster.so

clean:
rm -f *.so *.sho _dict.

test_cluster_dict.cc: test_cluster_LinkDef.h test_cluster.hh
rootcint -f test_cluster_dict.cc -c -D_USE_ROOT -I${ROOTINC} -D__cplusplus test_cluster.hh test_cluster_LinkDef.h

test_cluster_dict.sho: test_cluster_dict.cc
g++ -O2 -fPIC -c -D_USE_ROOT -I${ROOTINC} test_cluster_dict.cc -o test_cluster_dict.sho

test_cluster.so: test_cluster_dict.sho
g++ -shared -o test_cluster.so test_cluster_dict.sho[/code]

cat test_cluster.py

[code]import ROOT

ROOT.gSystem.Load(“test_cluster.so”)
from ROOT import pixel

mycluster = ROOT.std.vector(“pixel”)
myclusters = ROOT.std.vector(mycluster)
[/code]
test_cluster2.tgz (757 Bytes)

Hi,

what I mean is that you need to have two different builds of ROOT (or at least for the libPyROOT part). I.e., one for p2.7 and one for p2.6. The script you pose seems to have one single directory from which it gets its ROOT sources:ROOTINC=/home/waveburst/SOFT/ROOT/root-v5-32-04.patched/include
Certainly, that can not work for both.

Cheers,
Wim

No, I’m running this code on two different computers with different installations:
my laptop which has python 2.7 and a computing farm which has python 2.6.
The code version I posted is for the latter.

Eric

Eric,

then I’d argue that there’s a problem with the cluster install, rather then there being something between p2.6 and p2.7, as that seems more logical. Again I’d first look to see whether ROOT was indeed compiled with that version of python that is installed on that cluster.

So, since you did provide such an easy test, I’ve went through the steps and tried both p2.6 and p2.7 on my own machine. Both work fine.

Cheers,
Wim

Can it be that it’s an “IPython 0.10” + “Python 2.6.6” specific issue?
Maybe you could try to run your macro with a “bare” python.

Thanks for the advices! I will check. Eric