Creating a TPie graph from PyROOT

Hello,

I’m having trouble creating a TPie graph with this constructor:

TPie::TPie(const char*, const char*, Int_t, Float_t*, Int_t* cols = 0, const char** lbls = 0) =>
    could not convert argument 6

My Python code does the following:

p = ROOT.TPie('%s_Muon_Mother' % name, 'Muon\'s Mother in %s' % title, len(counts), array('f', counts), array('i', [0]), pdgs)

where counts is a list of ints, and pdgs is a list of strs. I’m using the array module, because I believe thats what one has to do when the C++ side of things is expecting an array. Obviously, the last argument, pdgs, is not working. It needs to be an array of character arrays, but the Python array module cannot make arrays of arrays. What can I do?

The other thing I tried was to make a list of character arrays, but that did not work either.

lbls = map(lambda s: array('c', s), pdgs)
p = ROOT.TPie('%s_Muon_Mother' % name, 'Muon\'s Mother in %s' % title, len(counts), array('f', counts), array('i', [0]), lbls)

Thanks for your help.

Ryan,

working with a char** from python is complicated for a variety of reasons. In particular, most of the time char*'s are turned into python strings, and then the actual char* is lost (it’s copied and the copy is kept internally to the str object).

There is a way around, it is ugly, and it looks something like this:from array import array names = [ array( 'c', 'string1\0' ), array( 'c', 'string2\0' ), array( 'c', 'string3\0' ) ] a = array( 'l', map( lambda x: x.buffer_info()[0], names ) )
The result ‘a’ will pass through a char**. It is important to keep ‘names’ and the final array ‘a’ alive long enough so that the addresses and data they keep don’t go away; and to close all strings in the first array with a ‘\0’, since they are character arrays, not strings.

HTH,
Wim