Free segments in a TFile

Dear all,
I have the following problem:
I create a file with one tree and one branch which contains a certain number of events. At a certain point I want to change the values of some entries that were filled in the middle of the branch, for example if I have three entries I want to change the values of the second one.

To do so I create a new tree I copy the first entries to the new one (in the above example I copy the first entry), I update some entries and fill it in the new tree (the second entry is calculated again and filled) and I copy the last entries from the old tree to the new one (the third entry is copied from the old to the new tree). At this point I call Delete(“all”) for the old tree, I save the file and exit (file->Write(); file->Close()).

I have noticed that doing this way the dimension of the file on disk increases even if the list of object contained in the file is correct (no keys duplicates). If I have understood correctly this is due to the fact that when I “clone” my tree I need twice the space of the single tree and when I delete the old tree in reality I free the space for new data but the space is “allocated” and written to disk anyway, and this can be easily seen opening the file and using file->Map().

Hence my question is: does anybody know if it is possible to “purge” the free segments on a file? or not save them? if not, is it possible to tag an object not to be saved into the file? I have tried with mytree->Write() instead of file->Write() but this way it seems the tree is not saved at all…

Thanks,
Emiliano

The space occupied by the free segments will be reused if you close
the file and repon it in update mode.
In your case, it migth be more convenient to write to a new file
the updated Tree.

Rene