Error checking with TTreeReader

Hi experts,

I am considering to update some old code to TTreeReader. How can I do error checking, for example for the wrong type or a misspelled name?

ROOT will print something like Error in <TTreeReaderValueBase::CreateProxy()>: The tree does not have a branch, nor a sub-branch called c.ccXXX when I call reader.Next() - but I would like to avoid the printout but instead call some function (or throw an exception). How do I do this?

In some cases, reader.Next() returns true even though it has printed an error message! Example:

root [0] auto tree = new TTree("t", "t"); struct X {Float_t a=23,b=42,c=1234;}x; tree->Branch("a", &x, "a/F:b:c"); tree->Fill();
root [1] TTreeReader r(tree); TTreeReaderValue<Float_t> rva(r, "a.a"); TTreeReaderValue<Double_t> rvb(r, "a.b");
root [2] r.Next()
Error in <TTreeReaderValueBase::CreateProxy()>: Leaf of type Float_t cannot be read by TTreeReaderValue<double>.
(bool) true
root [3] cout << *rva << ", " << *rvb << '\n';
23, 5.15396e+10
root [4] rva.IsValid()
(bool) true
root [5] rvb.IsValid()
(bool) true
root [6] rvb.GetReadStatus()
(ROOT::Internal::TTreeReaderValueBase::EReadStatus) (ROOT::Internal::TTreeReaderValueBase::EReadStatus::kReadSuccess) : (unsigned int) 0
root [7] rvb.GetSetupStatus()
(ROOT::Internal::TTreeReaderValueBase::ESetupStatus) (ROOT::Internal::TTreeReaderValueBase::ESetupStatus::kSetupMatch) ? (ROOT::Internal::TTreeReaderValueBase::ESetupStatus::kSetupMatchBranch) : (int) 0

So: how do I check for errors?

Edit: tested with a ROOT head from 20170628 (git 88eaa53edb).

@pcanal may help you.

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

That’s a bug!

Luckily it’s fixed:

root [0] auto tree = new TTree("t", "t"); struct X {Float_t a=23,b=42,c=1234;}x; tree->Branch("a", &x, "a/F:b:c"); tree->Fill();
root [1] TTreeReader r(tree); TTreeReaderValue<Float_t> rva(r, "a.a"); TTreeReaderValue<Double_t> rvb(r, "a.b");
root [2] r.Next()
Error in <TTreeReaderValueBase::CreateProxy()>: Leaf of type Float_t cannot be read by TTreeReaderValue<double>.
(bool) true
root [3] rvb.IsValid()
(bool) false

Can you confirm that the master doesn’t have this issue anymore?

Axel.