How to recognize empty trees returned by TFile.Get

Hi,

using the code shown below for reading tree files, how can I find out if _tree actually is a valid TTree object?
Would isinstance(_tree, TTree) do?
Or do I have to resort to a try except around the call to GetEntries()?

_treeFile = TFile( plotDef['file']+'.tree' ) if _treeFile: _tree = _treeFile.Get(plotDef['tree']) logFile.writeln( "plotTree: %s has %d entries" % (plotDef['name'], _tree.GetEntries()) )

TIA & regards,
Roland

Hi,

isinstance() would work b/c an invalid tree name would return a null TObject pointer, which is not an instance of TTree. However, simply “if _tree” should do the trick (just like “if _treeFile”).

Cheers,
Wim

gr8, tnx a lot,
Roland