TFile issue when updating an existing TTree

Hi everybody,

I’m facing an issue concerning the tree update. My ROOT macro analyses a run of an experiment and gathers some informations in a TTree : this latter is loaded from a TFile to add the new entries.
Here is the procedure used in the program (I found it on the forum) :

  • open the file in “Update” mode
  • get the Tree from the file
  • set the branch(es) address
  • fill loop
  • save the new Tree header mytree->Write()
  • close the file

But at each execution of the program, a new TTree is written with all the entries (it’s ok, no information is lost) but the tree resulting from the previous execution of the program is still present (named “tree;N-1” in the TBrowser GUI). Thus after an hundred executions, the resulting file contained an hundred trees (“tree;1”, … “tree;100” -> I expected as “tree;100” would be the only tree present in the TFile…) and the disk space was full. ](*,)

I would like to update the existing tree without keeping the previous one in the TFile.

Thanks for any suggestion.


Hi Thomas,

Use t->Write(nullptr,TObject::kOverwrite);


Thanks !
Now it works perfectly :slight_smile: