With ROOT version 6.22/06 on MacOS, as well as 6.22 versions on CentOS7, we are experiencing some unexpected behaviour when we loop over a TTree to compute a simple sum. To invoke this unexpected behaviour, three ingredients are required:
- We create a new TTree in a function that we directly add as a friend, using
- We call
SetBranchAddressfor one of the branches of the original tree, giving it a
c_types.c_double()as a container;
What we see is that the original tree changes each time we call this function, which should leave the original tree intact. It is as if the original branch value is overwritten by the friend tree’s value. If we do not call
AddFriend, this behaviour is not seen. If we use a
array('d', [0.]) as a container for the branch values instead of the
c_double, the behaviour is also not seen.
We added a call to
ResetBranchAddresses to be sure, but this does not fix the behaviour. What is going wrong when using the c_doubles paired with AddFriend? Is this intended behaviour, and should we always just use the
array containers for SetBranchAddress?
Included is a minimal example that reproduces the problem. The expected output is a set of identical numbers. With my ROOT version I see “((6716.289999781176, 6716.289999781176, None), (5035.0, 5035.0, None))”. When the type is changed to
array in lines 44/43, the problem is fixed. Also when commenting out line 60. There is an explicit
tree.Show call to illustrate that the values of the original tree seemingly change.