Now I would like to declare a vector of unsigned short’s. Knowing that Python does not have short’s natively, I was thinking about using the ROOT UShort_t class, using something like:
The code above does not work; do you know how to access (if it’s possible) that class from Python?
UShort_t isn’t known, so one should use the full name:v = ROOT.std.vector( "unsigned short" )()
(note the extra set of parentheses to instantiate the object; the first just gets the specific template instantiation of the class).
sorry, seems I missed that one (or there might be a good reason for its absense: an int is easier to deal with). A possible python-side solution (albeit that it will be slow):[code]from ROOT import std
def setitem( self, idx, value ):
if idx < self.size():
b = self.begin()
while idx:
b = b.preinc()
idx -= 1
self.insert( b, value )
self.erase( b.preinc() )
else:
raise IndexError( ‘index out of range’ )
std.vector( ‘unsigned short’ ).setitem = setitem
del setitem[/code]
I’ll have a look and see whether I can fix it up on the C++side.
in now. Problem was that for most cases Int_t and UInt_t fell in for Short_t and UShort_t (given that python doesn’t have a short type), but those won’t work for references, and so a special case had to be added.