Adding a branch to a tree

Hi,

I’m opening a root file in “update” mode and adding one new branch to a tree of about 90 branches. I write the tree out using “TObject::kOverwrite” as it says in the manual, and after the code has run the size of the rootfile is doubled. The number of entries in each branch remains the same before and after the adding of the new branch, but I’m worried that the original tree is being duplicated but not writen over. Is it normal for the file size to increase this much? The method I’m using is detailed below.

Thanks for any help you can give.

Rob

Double_t var = 1.0;
TFile f(filename,“update”);
TTree tree = (TTree)f.Get(Tree);
TBranch *new_var = tree->Branch(“var”,&var,“var/D”);
new_var->Fill();
tree->Write("",TObject::kOverwrite);

Hi,

When you overwrite the TTree object (which is large), ROOT will marker its previous location on file as free (but it is of course still part of the file). When writing the new TTree, it will try to find a place in the file where to write it. The freed gap could have been used (actually sometimes, it can’t even do that because we sometime write the new one first) … except that the new TTree object is larger and hence the file will increase.

Now that is not enough to explain a doubling … unless you do not have a lot of data or if your TTree was created in memory before being written to file (in which case all the data is stored with the TTree objects).

Cheers,
Philippe