Call C++-Function - Vector of Unsigned Int

Dear Colleauges,

I’m trying to call a C++ function from PyROOOT that takes somewhat annoying arguments:

void foo( std::vector<std::vector >* a, std::vector<std::vector >* b)

The first argument I can build via
li = [3.,5.]
a = ROOT.std.vector( ROOT.std.vector( float ))()
for x in li:
tmp = ROOT.std.vector( float )()
tmp.push_back( x)
a.push_back(tmp)

The second argument however troubles me. Python has no built-in unsigned type (as far as I know), when I try to use ctypes.c_uint the program fails with:
AttributeError: type object ‘ROOT’ has no attribute ‘vector<c_ulong>’ (well - I would not have expected dictionaries for the ctypes).
Trying array.array(“I”) fails for the same reason

Is there any datatype I could use for this?

Thank You!

Cheers,
Gregor

Hi,

the float vector argument that you build isn’t going to work either: the python type “float” is equivalent to the C/C++ type “double”. Just pass the names of the template type arguments as strings, like so: v1 = ROOT.std.vector('float')() v2 = ROOT.std.vector('unsigned int')()
and all should work. Note that you can push_back() normal python ints into the “unsigned int” vector (but the code will raise a TypeError if you try to push_back() a value that is out-of-range, like a negative value).

Cheers,
Wim

Hi Wim,

great - thank You!

Cheers,
Gregor