Discussion:
SetBranchAddress with pointer juggling
Karl Bicker
2014-09-10 14:18:04 UTC
Permalink
Dear rootonauts,

I am having a peculiar problem when working with TTree::SetBranchAddress(). I attached a breaking example script, which is intended to be compiled.

The problem is the following: When I am setting a branch address with a pointer on a pointer and the latter is deleted after the branch address has been set, the reading of the TTree does not work anymore (and somehow screws up the root command line). Is there a reason for this? Why does the pointer I am handing over to SetBranchAddress (via a pointer to it) have to survive while the TTree is being read? Would it not be a simple matter just to copy it in SetBranchAddress?

Thanks in advance for your help!

Best regards,
Karl Bicker

PS: For people who have enough time on their hands to read a lengthy forum post, the background of this question is here: http://root.cern.ch/phpBB3/viewtopic.php?f=14&t=17632
Philippe Canal
2014-09-10 18:45:58 UTC
Permalink
Hi,
Why does the pointer I am handing over to SetBranchAddress (via a pointer to it) have to survive while the TTree > is being read?
Because it is a message passing mechanism between the user and the TTree (if the Tree delete or reallocate the object, it will
update the pointer).

We are planning on adding a new interface that will allow to skip this message passing mechanism ... but until now whenever the
pointer whose address your passed to the TTree disappears, you must call ResetBranchAddress.

Cheers,
Philippe.
Dear rootonauts,
I am having a peculiar problem when working with TTree::SetBranchAddress(). I attached a breaking example script, which is intended to be compiled.
The problem is the following: When I am setting a branch address with a pointer on a pointer and the latter is deleted after the branch address has been set, the reading of the TTree does not work anymore (and somehow screws up the root command line). Is there a reason for this? Why does the pointer I am handing over to SetBranchAddress (via a pointer to it) have to survive while the TTree is being read? Would it not be a simple matter just to copy it in SetBranchAddress?
Thanks in advance for your help!
Best regards,
Karl Bicker
PS: For people who have enough time on their hands to read a lengthy forum post, the background of this question is here: http://root.cern.ch/phpBB3/viewtopic.php?f=14&t=17632
Loading...