Hi Rooters
I am trying to use std::vector in a python script and I don’t know how to do it.
Namely:
[code]python
import ROOT
from ROOT import std
a = std.vector(int)(10) # ok, vector of 10 int
b = std.vector(float)(10) # ok, vector of 10 float
c = std.vector(double)(10) # !! gloups !!
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘double’ is not defined
[/code]
It looks like that the dictionnary for std::vector is not built. But if I try to do the same thing using the CINT interpreter:
root
root[0] #include <vector>
root[1] std::vector<double> c(10)
It works, I can use “c” as a vector of double. Using CINT, It seems that the dictionnary for std::vector has been built.
On another hand, I tried something scary with Cint
std::vector with “MyClass” been my own class I added with a shared library and a dictionnary. I have never created a dicitionnary of vector, just a dictionnay of MyClass. It looks like Cint is able to create a vector of MyClass on the fly, meaning template instantiation on the fly???
This could explain why it works using Cint and not Python.
So here are my questions:
-
why do we have different beahvior using Cint and Python? Am I right thinking Cint is now able to instantiate templates on the fly as previewed in ROOT Workshop 2007?
-
How can I create a dictionnary (not on the fly) for vector (or vector) so I can use them from the Python interpreter? I tried to add the line:
#pragma link C++ class std::vector<double>+;
in my LinDef.h file but it doesn’t work, it says the dictionnary has already been built?
- Python hasn’t got a “double” type, just a float. This may be the reason why vector doesn’t work even if I have a dictionnary for it. So how can I do the mapping when I call a method which expects a vector (in C++) as an argument and I feed it with a vector(float) (in Python?)
Thank for your help
I am using ROOT 5.18.00 and python-2.5.1 on a Linux box (gcc is 3.3.5)