I trying to get a 3 dimensional STL vector to work using python, but get the following error message:
AttributeError: type object ‘ROOT’ has no attribute ‘vector<std::vector<std::vector > >’
The following code snippet shows how this error is produced. The 2 dimensional STL vector is fine, and commenting out vec3 works, so it seems to be an issue with instantiating the class on the python side (as there’s no issue with the ProcessLine). But have I got the correct syntax for vec3? It seems like it should just be an extension of the syntax for vec2, as I have attempted, but it fails to work.
[code]# simple root macro to test vectors in PyROOT
from ROOT import *
gROOT.ProcessLine("#ifdef CINT
#pragma link C++ class std::vector<std::vector >+;
#pragma link C++ class std::vector<std::vector<std::vector > >+;
#endif")
vec1 = std.vector(‘double’)()
vec2 = std.vector(‘std::vector’)()
vec3 = std.vector(‘std::vector<std::vector >’)()[/code]
I’ve also tried to keep the class definition on the C side by using the following structure:
[code]#include
#ifdef CINT
#pragma link C++ class std::vector<std::vector >+;
#pragma link C++ class std::vector<std::vector<std::vector > >+;
#endif
struct myStruct
{
std::vector vec1;
std::vector<std::vector > vec2;
std::vector<std::vector<std::vector > > vec3;
};[/code]
Then using this with python, ie:
[code]from ROOT import *
gROOT.ProcessLine(".L vecs.C+")
from ROOT import myStruct
m=myStruct()
a=m.vec1
b=m.vec2
c=m.vec3[/code]
But the final line causes a segmentation fault. If I comment out this line, it works fine, and I can also manipulate the other vectors, ie, with resize(). Any suggestions would be greatly appreciated. Oh, and I am using root v5r28p00fn00 and python 2.4.3 if that helps.
Cheers,
Callum
useVec.py (121 Bytes)
vecs.C (365 Bytes)
rootVecs.py (450 Bytes)