PyRoot GetListOfBranches() after creation of new branch

Dear Experts,

I’m adding a new branch to my ttree with the following code:

infile = ROOT.TFile('infile.root', 'update')
tree = infile.Get('nominal')

jet_NN = ROOT.std.vector('float')()
branch = tree.Branch('jet_NN_output', jet_NN)

n_entries = tree.GetEntries()
for i_entry in range(n_entries):

	jet_NN.clear()

	for NN in NN_event:
		jet_NN.push_back(NN)

    branch.Fill()

tree.Write()
infile.Purge()
infile.Close()  

However, if I check whether the branch is already existing using

list_branches = [key.GetName() for key in tree.GetListOfBranches()]

it doesn’t show up. Is there a solution to this problem?

Best regards,
Sonja


ROOT Version: 6-16-00
Platform: Not Provided
Compiler: Not Provided


Dear Sonja,

The code that checks if the branch is there, you run it on the same tree you just wrote?

What happens if you open the file with TBrowser, does it show the new branch?

Dear etejedor,

thank you for your answer.
Yes, the code is run on exactly the same tree and both when using the Print() function after opening the root file and in the TBrowser, the new branch shows up. Hence the confusion…

Try:

import ROOT
infile = ROOT.TFile('infile.root', 'read')
tree = infile.Get('nominal')
list_branches = [key.GetName() for key in tree.GetListOfBranches()]
print list_branches
infile.Close()

That worked. Opening the files with the option ‘update’ afterwards also worked. I went back to trying my original code, without a problem, also tried separately in a clean environment. To be honest, I have no idea what happened and I feel like I have no way of reproducing the error.

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