Adding leaf to existing branch and overwriting

Hi rooters,

I am trying to add a leaf to an existing branch. But there is no method “AddLeaf” or Branch associated with TBranches.

How should I proceed ? Could I just use the regular “dot” pattern for specifying my branch/leaf ? I don’t want to overwrite my branch, so I expect that creating a new branch with one more leaf is not the solution.

Can anyone help me on this ?

Also, I have been trying to update some trees (adding branches to the root) without problem, except the fact that it seems that new branches are added (with the same name) when I run the macro again, to correct some branches.

I tried both tree->Write("",TObject::kOverwrite), which creates a new branch with the same name each time me macro is run, and branch->Write("",TObject::kOverwrite), which will add my branch to the root of the file, not my tree.

Thanks

Karolos

Hi,

Adding a leaf to a branch is not possible. Adding a new branch to an existing TTree is possible but not recommended. To ‘Add’ a branch we recommend to create a new TTree and make the new tree a ‘Friend’ (TTree::AddFriend) of the old one. To ‘replace’ values, we recommend cloning the tree and rewrite all the entries to a new file (with good old value and new values). See $ROOTSYS/tutorials/tree/copytree*.C

Cheers,
Philippe

Thanks a lot for your reply. I was already using friends but I wanted to update these. Anyhow, I’ll copy the trees and then rename the files.

Karolos