Access to STL Classes of pointers

I have a class (MyClass) which I am trying to interface to via pyroot. The class involves data members which are c++ vectors of pointers to int, unsigned int, double and float. When trying to access these data members via PyROOT I receive the following warnings (see below), which consequently means I cannot access the values stored by the pointers. Is there a way to achieve what I am trying?

What I find a bit odd is that the warnings I receive apply only to ints, doubles and floats but not unsigned ints.

[code]<ROOT.vector<int*> object at 0x1058aa870>
<ROOT.vector<unsigned int*> object at 0x1058aa888>
<ROOT.vector<double*> object at 0x1058aa8a0>
<ROOT.vector<float*> object at 0x1058aa8b8> RuntimeWarning: return type not handled (using void): int*&
print 'int pointers:\t ’ + str(my_class.m_int_ptrs[0])
int pointers: None

unsigned int pointers: <UInt_t buffer, size 2147483647> RuntimeWarning: return type not handled (using void): double*&
print 'double pointers:\t ’ + str(my_class.m_double_ptrs[0])
double pointers: None RuntimeWarning: return type not handled (using void): float*&
print 'float pointers:\t ’ + str(my_class.m_float_ptrs[0])
float pointers: None


[code]#ifndef MyClass_H
#define MyClass_H


class MyClass
// constructors

vector<int*> m_int_ptrs;
vector<unsigned int*> m_uint_ptrs;
vector<double*> m_double_ptrs;
vector<float*> m_float_ptrs;


#endif /* MYHEADER_H */[/code]


[code]#include “MyClass.h”

// constructors
int i(123);
m_int_ptrs.push_back(new int(i));
m_uint_ptrs.push_back(new unsigned int(i));
m_double_ptrs.push_back(new double(i));
m_float_ptrs.push_back(new float(i));

[code]from ROOT import *

gInterpreter.GenerateDictionary(“vector<int*>”, “vector”)
gInterpreter.GenerateDictionary(“vector<unsigned int*>”, “vector”)
gInterpreter.GenerateDictionary(“vector<double*>”, “vector”)
gInterpreter.GenerateDictionary(“vector<float*>”, “vector”)

my_class = MyClass()

print my_class.m_int_ptrs
print my_class.m_uint_ptrs
print my_class.m_double_ptrs
print my_class.m_float_ptrs

print '========================================================='
print 'int pointers:\t ’ + str(my_class.m_int_ptrs[0])
print ‘=========================================================’
print 'unsigned int pointers:\t ’ + str(my_class.m_uint_ptrs[0])
print '========================================================='
print 'double pointers:\t ’ + str(my_class.m_double_ptrs[0])
print '========================================================='
print 'float pointers:\t ’ + str(my_class.m_float_ptrs[0])
print ‘=========================================================’[/code]


seems to be an issue with the generated dictionaries: the ones for double, float, and int have an operator[] returning type*&, the one for unsigned int has only unsigned int*. I’d have expected both versions in all cases (the const and non-const variety), in which case PyROOT should prefer the * variety for getitem and the *& for setitem (albeit that that won’t work).

Note that it’s equally a problem in root.exe:root [0] gInterpreter->GenerateDictionary("vector<unsigned int*>", "vector"); root [1] std::vector< unsigned int* > v; root [2] v.push_back( new unsigned int(5) ); root [3] v[0] (unsigned int*)0x5 root [4] v[0] = new unsigned int(6); Error: improper lvalue (tmpfile):1: *** Interpreter error recovered *** root [5]
versus: root [0] gInterpreter->GenerateDictionary("vector<int*>", "vector"); root [1] std::vector< int* > v; root [2] v.push_back( new int(5) ); root [3] v[0] (int*)0x5 root [4] v[0] = new int(6); root [5]
I’ll submit a bug report; both operators are required.

All that said, trying to use std::vector<builtin*> from python is going to be a world of hurt, even when the dictionaries are proper. You’d have to dereference twice to get to the value, which works through temporary objects. Not pretty, and very slow.



just for reference, bug report is here:



bug is fixed, thanks to Axel. It did change a few things in the lookup though, so I had to make a change to pyroot as well. Is in trunk.