Hi Florian,
To create a branch of strings use CharArrayCol(n) where n is the length including the null termination. CharArrayCol(1) will raise a ValueError since there is no room for the null termination. Also, CharCol will actually make the same thing as CharArrayCol with length 2 where the second byte is the null byte.
I just fixed a serious bug in how rootpy treated char branches. It wasn't guaranteeing a null-termination and the error you found is from a buggy attempt to convert your string to an int (it should have used the built-in ord() function).
While fixing this bug I redesigned the char types to inherit from Python's built-in bytearray instead of array.array. This allows for a more transparent treatment of a CharArray like a python string.
I've updated the example to include a CharCol and CharArrayCol. See here:
Now, in the event loop you can do:
tree.string = 'abcd'
tree.string = 'ab' # can set with a shorter string than the declared length, and remaining bytes will be zeroed out.
tree.s = 'a'
and this would result in a ValueError:
tree.string = 'abcde'
ValueError: string of length 5 is too long to fit in array of length 5 with null-termination
since it forces you to keep the last byte for the null termination.
I hope this helps, and thanks for reporting this!
Cheers,
Noel