Modifying entry number k in a TTree

Suppose I have a TFile, containing a TTree, containing a TBranch storing a class. Suppose that I have 4 entries in the TTree and suppose that I want to modify entry number 2 by changing the content of some variable of the instance of the class in entry number 2.
I have tried by opening the TFile in “UPDATE” mode. When reaching entry number 2, I have made my modification, I have called TTree::Fill and after reading the last entry and before closing the file, I have call TFile::Write.
The result was not what I expected. Instead of the TTree still having 4 entries, with entry 2 modified, I get a TTree with 5 entries, the first 4 not modified, and the 5th one containing entry 2 modified!
Is what I am trying to do only possible by completly rewriting the TTree or is there an other solution?
Thanks a lot

Hi,

[quote]Is what I am trying to do only possible by completly rewriting the TTree or is there an other solution?[/quote]TTree are intentionally optimized to be write-once, read-many-times. You can not modify the content of entries within a TTree. Your two options are to either copy the whole tree (modifying the entries you need on the way) or add a new Friend TTree containing the new values.

Cheers,
Philippe.