How to create and use a branch with a C char array from PyROOT

I have a brand new TTree, and I want to create in it a branch on it that will hold a C char array (of a known length) so that I can access this char array from python, modify it, and “Fill” the tree.

I actually managed to create such a branch with the monstrosity below, but I can’t modify the resulting python object. I find lots of old relevant posts, but they all refer to which no longer exists (and may well be outdated due to the new pyroot).

R.gInterpreter.Declare("struct a5 { char c[5]; };") 
Ra5 = getattr( R, 'a5' )
a5 = Ra5() 
tr.Branch( 'dummy', R.AddressOf(a5), 'dummy/C' ) 

ROOT Version: 6.18/04
Platform: Ubuntu
Compiler: Not Provided


You can use a character array in Python, with the array.array type. Here you can find an explanation:

So something like:
s=array('c', 'ab\0')

which you can pass to tr.Branch and you can modify before each fill with the value you want for the next tree entry.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.