Skip to content

Commit c675a35

Browse files
committed
[RF] More verbose errors in RooPlot::findObject
It greatly helps debugging if the error message tells you which objects are actually existing. (cherry picked from commit 81d596f)
1 parent 112c105 commit c675a35

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

roofit/roofitcore/src/RooPlot.cxx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -898,22 +898,28 @@ bool RooPlot::drawAfter(const char *after, const char *target)
898898
/// methods to change the drawing style attributes of a contained
899899
/// object directly.
900900

901-
TObject *RooPlot::findObject(const char *name, const TClass* tClass) const
901+
TObject *RooPlot::findObject(const char *name, const TClass *tClass) const
902902
{
903-
TObject *ret = nullptr;
903+
TObject *ret = nullptr;
904904

905-
for(auto const& item : _items) {
906-
TObject &obj = *item.first;
907-
if ((!name || name[0] == '\0' || !TString(name).CompareTo(obj.GetName()))
908-
&& (!tClass || (obj.IsA()==tClass))) {
909-
ret = &obj ;
910-
}
911-
}
905+
for (auto const &item : _items) {
906+
TObject &obj = *item.first;
907+
if ((!name || name[0] == '\0' || !TString(name).CompareTo(obj.GetName())) && (!tClass || (obj.IsA() == tClass))) {
908+
ret = &obj;
909+
}
910+
}
912911

913-
if (ret == nullptr) {
914-
coutE(InputArguments) << "RooPlot::findObject(" << GetName() << ") cannot find object " << (name?name:"<last>") << std::endl ;
915-
}
916-
return ret ;
912+
if (ret == nullptr) {
913+
std::stringstream error;
914+
error << "RooPlot::findObject(" << GetName() << ") cannot find object " << (name ? name : "<last>") << "\n"
915+
<< "Available objects are:\n";
916+
for (auto const &item : _items) {
917+
TObject &obj = *item.first;
918+
error << " - " << obj.IsA()->GetName() << " \"" << obj.GetName() << "\"\n";
919+
}
920+
coutE(InputArguments) << error.str();
921+
}
922+
return ret;
917923
}
918924

919925

0 commit comments

Comments
 (0)