TArrayD Conversion to List Fails

Hi, if I have this code with a TVectorD:

import ROOT
tv = ROOT.TVectorD(3)
for i in range(3):
  tv[i] = i
L = list(tv)

then L contains a python list of the contents of the TVectorD. If I try the same thing with a TArrayD, I get an infinite-scrolling error message about out-of-bounds access. Try it yourself:

import ROOT
ta = ROOT.TArrayD(3)
for i in range(3):
  ta[i] = i
L = list(ta)

I have to kill the terminal to end the error messages, so I couldn’t easily copy & paste the error message.

Interestingly, if I create a 0-length default-constructed TVectorD/TArrayD, I still get errors with the TArrayD, but they are more readable and Ctrl+C-able (this is in IPython:)

In [4]: ta = ROOT.TArrayD()

In [5]: list(ta)
Error in <TArrayD::operator[]>: index 0 out of bounds (size: 0, this: 0x7fb366a1e6c0)

 *** Break *** segmentation violation
 Generating stack trace...
 0x0000000107676d64 in PyROOT::TDoubleRefExecutor::Execute(Cint::G__CallFunc*, void*, bool) (in libPyROOT.so) + 228
 0x000000010767da17 in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::CallFast(void*, bool) (in libPyROOT.so) + 39
 0x000000010767db72 in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::CallSafe(void*, bool) (in libPyROOT.so) + 178
 0x000000010767d931 in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::Execute(void*, bool) (in libPyROOT.so) + 177
 0x000000010767ca71 in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::operator()(PyROOT::ObjectProxy*, _object*, _object*, long, bool) (in libPyROOT.so) + 353
 0x000000010767e6c9 in PyROOT::(anonymous namespace)::mp_call(PyROOT::MethodProxy*, _object*, _object*) (in libPyROOT.so) + 697
 0x000000010638a665 in PyObject_Call (in Python) + 101
 0x00000001063e4504 in slot_sq_item (in Python) + 212
 0x00000001063b1cd5 in iter_iternext (in Python) + 37
 0x00000001063b2ef9 in listextend (in Python) + 649
 0x00000001063b452e in list_init (in Python) + 174
 0x00000001063dbfe2 in type_call (in Python) + 338
 0x000000010638a665 in PyObject_Call (in Python) + 101
 0x000000010641f0b4 in PyEval_EvalFrameEx (in Python) + 16068
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x000000010641f752 in PyEval_EvalFrameEx (in Python) + 17762
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x00000001063ae0c6 in function_call (in Python) + 342
 0x000000010638a665 in PyObject_Call (in Python) + 101
 0x000000010641f4e6 in PyEval_EvalFrameEx (in Python) + 17142
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x000000010641a9a6 in PyEval_EvalCode (in Python) + 54
 0x0000000106442611 in PyRun_FileExFlags (in Python) + 161
 0x000000010644215e in PyRun_SimpleFileExFlags (in Python) + 718
 0x0000000106456002 in Py_Main (in Python) + 3314
 0x00007fff95f0c5fd in start (in libdyld.dylib) + 1
 0x0000000000000002 in <unknown function>
Error in <TArrayD::operator[]>: index 0 out of bounds (size: 0, this: 0x7fb366a1e6c0)

 *** Break *** segmentation violation
 Generating stack trace...
 0x000000010767642c in PyROOT::TDoubleExecutor::Execute(Cint::G__CallFunc*, void*, bool) (in libPyROOT.so) + 124
 0x000000010767da17 in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::CallFast(void*, bool) (in libPyROOT.so) + 39
 0x000000010767db72 in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::CallSafe(void*, bool) (in libPyROOT.so) + 178
 0x000000010767d931 in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::Execute(void*, bool) (in libPyROOT.so) + 177
 0x000000010767ca71 in PyROOT::TMethodHolder<PyROOT::TScopeAdapter, PyROOT::TMemberAdapter>::operator()(PyROOT::ObjectProxy*, _object*, _object*, long, bool) (in libPyROOT.so) + 353
 0x000000010767e6c9 in PyROOT::(anonymous namespace)::mp_call(PyROOT::MethodProxy*, _object*, _object*) (in libPyROOT.so) + 697
 0x000000010638a665 in PyObject_Call (in Python) + 101
 0x00000001063e4504 in slot_sq_item (in Python) + 212
 0x00000001063b1cd5 in iter_iternext (in Python) + 37
 0x00000001063b2ef9 in listextend (in Python) + 649
 0x00000001063b452e in list_init (in Python) + 174
 0x00000001063dbfe2 in type_call (in Python) + 338
 0x000000010638a665 in PyObject_Call (in Python) + 101
 0x000000010641f0b4 in PyEval_EvalFrameEx (in Python) + 16068
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x000000010641f752 in PyEval_EvalFrameEx (in Python) + 17762
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x00000001063ae0c6 in function_call (in Python) + 342
 0x000000010638a665 in PyObject_Call (in Python) + 101
 0x000000010641f4e6 in PyEval_EvalFrameEx (in Python) + 17142
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x0000000106421f36 in fast_function (in Python) + 294
 0x000000010641e28b in PyEval_EvalFrameEx (in Python) + 12443
 0x000000010641b076 in PyEval_EvalCodeEx (in Python) + 1734
 0x000000010641a9a6 in PyEval_EvalCode (in Python) + 54
 0x0000000106442611 in PyRun_FileExFlags (in Python) + 161
 0x000000010644215e in PyRun_SimpleFileExFlags (in Python) + 718
 0x0000000106456002 in Py_Main (in Python) + 3314
 0x00007fff95f0c5fd in start (in libdyld.dylib) + 1
 0x0000000000000002 in <unknown function>
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-694b9219665f> in <module>()
----> 1 list(ta)

TypeError: none of the 2 overloaded methods succeeded. Full details:
  problem in C++; program state has been reset
  problem in C++; program state has been reset

In [6]: 
KeyboardInterrupt

Jean-François

Jean-François,

is b/c TVectorT is pythonized, TArray is not. Is a trivial fix, and is now in:[code]>>> import ROOT

ta = ROOT.TArrayD(3)
ta[4]
Traceback (most recent call last):
File “”, line 1, in
IndexError: index out of range

[/code]
Thanks,
Wim