I am posting a problem which I sent to the roottalk list a week ago but got no answer to, maybe I am more lucky here:
I would like to modify some branches of an existing TTree I load to memory. I need to do that since I need to modify for example the jet energy and later use TTreeFormula or TBranchProxy to access the tree which should then contain the changed value. I do not want to save the modification to disk but do it transiently only.
Is this possible and if yes, how is it done?
I have figured out how to directly modify the baskets in a branch in the meantime which seems to do part of the job but also seems to mess with the loading of tree entries, so I need some more information on that.
If the problem is stated unclearly here is a code snippet which probably explains it better:
thanks for the answer!
So does your example code provide that a later access to the tree via TTreeFormula reads the changed branch value? I thought that the TTreeFormula directly reads the branch again and does not care about the branch address I set in my code.
TTreeFormula does not read any data. It is simply a class doing some calculations with the variables in the formula using the values of the variables currently in memory.
Unfortunately I told you something partially wrong. When calling EvalInstance(0) TTreeFormula will
take a copy from the input buffer in memory and store the value specified in the branch address.
This happens only for instance=0. if you call this function to access the second element of the array
it would work, but of course, it is not what you want.
I will discuss this oddity with Philippe (currently away) to see if we can modify this behavior.
The behavior is completely intentional. There is case where user expect that even if there do go ahead and modifying the underlying data that a ‘re-read’ will lead to having the original data back (this seems like the more straightforward default).