Bug in TVector iteration

Dear ROOT and Python experts,

Using python 2.4.3 and ROOT 5.18/00 I believe there’s a problem with the python TVector iterator.

Python 2.4.3 (#1, May  2 2006, 18:45:25) 
[GCC 3.4.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ROOT import TVector
>>> v =TVector(3)
>>> v.GetNrows()
>>> v.Print()

Vector (3)  is as follows

     |        1  |
   0 |0 
   1 |0 
   2 |0 

>>> for i in v:
...   print i
Error in <TVectorT<float>::operator()>: Request index(3) outside vector range of 0 - 3
Error in <TVectorT<float>::operator()>: Request index(4) outside vector range of 0 - 3

and this goes on indefinitely. So for some reason the iterator on the Python side does not know how large the vector is, even though GetNrows() produces the correct result.

Is this fixable, or can the whole TVector class be declared uniterable to prevent me from making this mistake again?

By the way: just curious, but TVector is a templated class, and I saw PyROOT gets the float version

>>> type(v)
<class 'ROOT.TVectorT<float>'>

In which piece of PyROOT should I look to find the details about how these templates are dealt with. (I was a bit too lazy to grep for this myself right now…)



the TVector class is not pythonized … it’s merely a default iterator (which simply indexes the container with 0, 1, 2, 3, … until StopIteration or IndexError is raised) that python uses.

I’ll add some pythonization for it.

The float version of the template came about because TVector is defined as a typedef like so: TVectorfwd.h:typedef TVectorT<Float_t> TVector;
Other classes can be accessed, if dictionaries were created, like so: TVectorT('double')I.e. the template argument as a string, or if string and type are the same (e.g. int), then that can be used instead.