Renaming leaf in branch

I have a TTree with a TBranch that was written like this:

t3->Branch("me_wgt",&m_mewgt,"me_wtg/D");

Is there a way to rename that leaf, so that it has the same name as the branch, without copying the file?

I tried

TFile *_file0 = TFile::Open("file.root","update");
t3->GetLeaf("me_wtg")->SetName("me_wgt");
_file0->Write();

but that had no effect.

t3->GetBranch("me_wgt")->GetLeaf("me_wtg");

returns nullptr;

It is possible but delicate. What is the purpose of the rename?
It might be simpler to alias it:

tree->SetAlias("me_wgt","me_wtg");

Cheers,
Philippe.

I want to use a TTreeReader, but with the leaf’s name not matching that of the branch it throws an error.

If it’s possible, can you tell me how to do it?

Fortunately, it turns out I was mis-remembering or so it seems.

Your example as-is works for me. Note that most tools use the branch name rather than the leaf name so you need to change both.

_file0->Write();

Most likely it is failing simply that the file is not open for update.

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.