Cannot find tree with TChain & Python 3


ROOT Version: 6.16.00
Platform: Ubuntu 18.04
Compiler: GCC 7 (?? ROOT from conda-forge)


Dear experts,

I am facing an issue with PyROOT (not tested in C++) that is only appearing under Python 3.
With my input_file, I’ve tried

treeName = 'l1UpgradeTree/L1UpgradeTree'
f = TFile.Open(input_file)
tree = f.Get(treeName)
print(treeName, '=', tree.GetEntries())

which works for both Python 2.7 and Python 3.6 as well as

treeName = 'l1UpgradeTree/L1UpgradeTree'
chain=TChain(treeName)
chain.AddFile(input_file)
print(treeName, '=', chain.GetEntries())

which fails with Cannot find tree: l1UpgradeTree/L1UpgradeTree in input file for Python 3 only.

This behaviour has also been observed with older ROOT (6.04).

Is something wrong with the Python bindings, or am I doing something wrong?

Try to rename your tree to not have a slash character. Slashes are special in that they are used to separate tree names from branch names, and this might confuse TChain.

Hi @amadio

The slash is part of the tree path, the TDirectory in which the TTree is located.
I thought the TChain can handle paths?

Do I have to use TChain::SetDirectory?

From the documentation it looks like this should be possible:

In case the Tree is in a subdirectory, do, eg:

TChain ch("subdir/treename");

OK, I think I chased it down to using nentries in

Int_t TChain::AddFile	(
  const char * 	name,
  Long64_t 	nentries = TTree::kMaxEntries,
  const char * 	tname = "" 
)	

If I use

trees[treeName].AddFile(f)

all is fine.

If I use

trees[treeName].AddFile(f, nentries=nevents)

I get

Cannot find tree: l1UpgradeTree/L1UpgradeTree in input file

So, in fact, the example code was wrong as I was using nentries=10 in my version. Apologies.

Interestingly, just passing the value directly

trees[treeName].AddFile(f, 10)

instead of naming the parameter

trees[treeName].AddFile(f, nentries=10)

is working. So it seems that named parameters are not working in Python 3 with PyROOT

EDIT: I should have printed the error message:

keyword arguments are not yet supported

… apologies for the noise

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