ROOT Version: 6.08
How do I do error detecting with TTreeReader, i.e. make sure the Trees/Branches exist?
Going off the example at https://root.cern.ch/doc/master/classTTreeReader.html, I notice it only checks the TTreeReaderValues, not the TTreeReader itself. If “MyTree” is not a tree in the file, the while loop will be skipped entirely and analyze
will erroneously return true (assuming there’s a missing return true;
at the end of the analyze
function body).
How do I check that TTreeReader is properly setup before calling next()
? It seems TTreeReader::GetEntryStatus()
might be what I want but it always returns kEntryNotLoaded
after initialization.
Also, why does the example check TTreeReaderValue.GetSetupStatus()
every single iteration of the loop? I’d assume the setup status should only need to be checked once, unless the name is misleading and the ‘setup’ changes between iterations? I would have assumed GetReadStatus()
should be called every loop and GetSetupStatus()
after initializing the reader value.
Notably, GetSetupStatus()
always returns kSetupNotSetup
until you call Next()
, which seems to defeat the purpose of checking a setup status. (Related: is the example in https://root.cern.ch/doc/v608/classTTreeReader.html incorrect? The CheckValues will always return false).
Moreover, this again causes analyze
to short-circuit and return true erroneously. If the TTreeReaderValue is supplied an invalid branch name, ROOT does output the error message Error in <TTreeReaderValueBase::CreateProxy()>: The tree does not have a branch called asdf.
However, the while loop will never be entered and the CheckValues will never be called. So analyze
returns true, and my program will continue on oblivious of the error.