TFile::Delete(): memory?


I am recalculationg variables in an exisitng tree. I do this by setting the branches to be recalculated inactive, clone the tree, create the brnaches again on the cloned tree, process the tree and, depending on an overwrite flag being set or not, overwrite the tree in its file. I do this by (the tree’s name be 'tree")

file->Delete("tree;1"); tree->Write(); file->Close(); delete file;

Afterwards, I open the file interactively, and gDirectory->ls() shows me that indeed only one tree, the processed one, is in the file.

BUT: ls -lha reveals that the file has grown in size, by about a factor of 2!!?? How can that happen? What did I do wrong?



This might be normal if the space occupied by the previous tree header is smaller than the new Tree header. The freed space will be used when
writing an object smaller or equal to the slot.

see the space used by all records in the file bia TFile::Map


Hi Rene,

I don’t understand: I delete my tree of 50MB, and write the same tree again in the same file, but now it has 55MB, and the file has 105 MB now?

Isn’t there a way to wipe out the whole content of the TFile? I guess I have to close it and reopen it with the ‘RECREATE’ option.

Frankly, I find to have to play way to many tricks to recalculate existing tree branches. I read in some other thread that TTree is designed as ‘Write once, Read many times’. Why? Isn’t this a most usual operation?

You give the answer yourself!
I assume that to create the updated Tree you need the first Tree, so you cannot delete the first Tree before writing the updated Tree.
as a result, the file will grow to the sum of the two Trees.
For this reason, it is more clever to write the updated Tree in a new file,
the delete the first file.


Hi Rene,
Oh, I see: the cloned tree is stil connected to the mother tree at the time of writing! How?

But then, wouldn’t the same happen if I open a new file and write the cloned tree, as long as the mother tree is still around? Can I delete the mother tree before writing the cloned tree?

The original tree keep a list of its clone. This is used so that the original tree can pass to its clones any changes in the branch address (so that they can stay properly connected).

Well … the main idea of TTree is that they are disk resident (because they usually do not fit in the memory). So delete the original tree before writing the clone would result in a loss of information.
If you have enough memory, in ROOT 4.01/04 there is a new method TTree::LoadBasket. You might be able to use this method, then delete the tree from the file then clone and copy it.
However, you might be better served by create the clone in a new file and then delete the old file and rename the new one.