Skip to content

Commit 8c6444d

Browse files
ga94pezwiechula
authored andcommitted
TPC: Adapt checkers to the case of empty graphs
1 parent cdbf68f commit 8c6444d

2 files changed

Lines changed: 98 additions & 52 deletions

File tree

Modules/TPC/src/CheckOfSlices.cxx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ Quality CheckOfSlices::check(std::map<std::string, std::shared_ptr<MonitorObject
114114
auto mo = moMap->begin()->second;
115115
if (!mo) {
116116
ILOG(Error, Support) << "Monitoring object not found" << ENDM;
117-
totalQuality.addMetadata(Quality::Null.getName(), "Monitoring object not found");
117+
totalQuality.addMetadata(Quality::Null.getName(), "Monitoring object not found \n");
118118
return totalQuality;
119119
}
120120
auto* canv = dynamic_cast<TCanvas*>(mo->getObject());
121121
if (!canv) {
122122
ILOG(Error, Support) << "Canvas not found" << ENDM;
123-
totalQuality.addMetadata(Quality::Null.getName(), "Canvas not found");
123+
totalQuality.addMetadata(Quality::Null.getName(), "Canvas not found \n");
124124
return totalQuality;
125125
}
126126
TList* padList = (TList*)canv->GetListOfPrimitives();
@@ -131,19 +131,25 @@ Quality CheckOfSlices::check(std::map<std::string, std::shared_ptr<MonitorObject
131131
auto pad = static_cast<TPad*>(padList->At(0));
132132
if (!pad) {
133133
ILOG(Error, Support) << "Could not retrieve pad containing slice graph" << ENDM;
134-
totalQuality.addMetadata(Quality::Null.getName(), "Could not retrieve pad containing slice graph");
134+
totalQuality.addMetadata(Quality::Null.getName(), "Could not retrieve pad containing slice graph \n");
135135
return totalQuality;
136136
}
137137

138138
TGraphErrors* g = nullptr;
139139
g = static_cast<TGraphErrors*>(pad->GetPrimitive("Graph"));
140140
if (!g) {
141141
ILOG(Error, Support) << "No Graph object found" << ENDM;
142-
totalQuality.addMetadata(Quality::Null.getName(), "No Graph object found");
142+
totalQuality.addMetadata(Quality::Null.getName(), "No Graph object found \n");
143143
return totalQuality;
144144
}
145145

146146
const int NBins = g->GetN();
147+
if (NBins == 0) {
148+
totalQuality.addMetadata(Quality::Null.getName(), "Graph has no data points \n");
149+
mNullString = "Graph has no data points \n";
150+
return totalQuality;
151+
}
152+
147153
const double* yValues = g->GetY();
148154
const double* yErrors = g->GetEY();
149155
bool useErrors = true;
@@ -255,7 +261,7 @@ Quality CheckOfSlices::check(std::map<std::string, std::shared_ptr<MonitorObject
255261
}
256262

257263
if (totalQuality == Quality::Null) {
258-
mNullString = "No check performed";
264+
mNullString = "No check performed \n";
259265
}
260266

261267
totalQuality.addMetadata(Quality::Bad.getName(), mBadString);
@@ -290,12 +296,6 @@ void CheckOfSlices::beautify(std::shared_ptr<MonitorObject> mo, Quality checkRes
290296
return;
291297
}
292298

293-
const int nPoints = h->GetN();
294-
if (nPoints == 0) {
295-
ILOG(Error, Support) << "No bins were found for the Graph! (beautify function)" << ENDM;
296-
return;
297-
}
298-
299299
const double* yValues = h->GetY();
300300
const double* yErrors = h->GetEY(); // returns nullptr for TGraph (no errors)
301301
bool useErrors = true;
@@ -304,8 +304,8 @@ void CheckOfSlices::beautify(std::shared_ptr<MonitorObject> mo, Quality checkRes
304304
}
305305

306306
TPaveText* msg = new TPaveText(0.5, 0.75, 0.9, 0.9, "NDC");
307-
h->GetListOfFunctions()->Add(msg);
308307
msg->SetName(fmt::format("{}_msg", mo->GetName()).data());
308+
h->GetListOfFunctions()->Add(msg);
309309

310310
std::string checkMessage;
311311
if (checkResult == Quality::Good) {
@@ -342,6 +342,13 @@ void CheckOfSlices::beautify(std::shared_ptr<MonitorObject> mo, Quality checkRes
342342
}
343343
msg->AddText(checkResult.getMetadata("Comment", "").c_str());
344344

345+
const int nPoints = h->GetN();
346+
if (nPoints == 0) {
347+
h->AddPoint(0., 0.); // have to add dummy point, else msg is not shown
348+
h->SetMarkerColor(kWhite); // hide the dummy point
349+
return;
350+
}
351+
345352
const double xMin = h->GetPointX(0);
346353
const double xMax = h->GetPointX(nPoints - 1);
347354

Modules/TPC/src/CheckOfTrendings.cxx

Lines changed: 79 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ Quality CheckOfTrendings::check(std::map<std::string, std::shared_ptr<MonitorObj
168168
std::vector<Quality> qualitiesOfPad;
169169

170170
const int nBins = graphs[iGraph]->GetN();
171+
172+
if (nBins == 0) {
173+
mPadQualities.push_back(Quality::Null);
174+
padNullString += "Graph has no data points for pad " + std::to_string(iGraph) + " \n";
175+
176+
mPadMetaData[Quality::Null.getName()].push_back(padNullString);
177+
mPadMetaData[Quality::Bad.getName()].push_back(padBadString);
178+
mPadMetaData[Quality::Medium.getName()].push_back(padMediumString);
179+
mPadMetaData[Quality::Good.getName()].push_back(padGoodString);
180+
181+
continue;
182+
}
183+
171184
const double* yValues = graphs[iGraph]->GetY();
172185
const double* yErrors = graphs[iGraph]->GetEY(); // returns nullptr for TGraph (no errors)
173186

@@ -395,6 +408,54 @@ void CheckOfTrendings::beautify(std::shared_ptr<MonitorObject> mo, Quality check
395408
}
396409

397410
for (size_t iGraph = 0; iGraph < graphs.size(); iGraph++) {
411+
412+
// InfoBox
413+
std::string checkMessage;
414+
TPaveText* msg = new TPaveText(0.5, 0.75, 0.9, 0.9, "NDC");
415+
msg->SetName(Form("%s_msg_%zu", mo->GetName(), iGraph));
416+
graphs[iGraph]->GetListOfFunctions()->Add(msg);
417+
418+
if (mPadQualities[iGraph] == Quality::Good) {
419+
graphs[iGraph]->SetFillColor(kGreen - 2);
420+
msg->Clear();
421+
msg->AddText("Quality::Good");
422+
msg->SetFillColor(kGreen - 2);
423+
} else if (mPadQualities[iGraph] == Quality::Bad) {
424+
graphs[iGraph]->SetFillColor(kRed);
425+
msg->Clear();
426+
msg->AddText("Quality::Bad. Failed checks:");
427+
checkMessage = mPadMetaData[Quality::Bad.getName()][iGraph];
428+
msg->SetFillColor(kRed);
429+
} else if (mPadQualities[iGraph] == Quality::Medium) {
430+
graphs[iGraph]->SetFillColor(kOrange);
431+
msg->Clear();
432+
msg->AddText("Quality::Medium. Failed checks:");
433+
checkMessage = mPadMetaData[Quality::Medium.getName()][iGraph];
434+
msg->SetFillColor(kOrange);
435+
} else if (mPadQualities[iGraph] == Quality::Null) {
436+
graphs[iGraph]->SetFillColor(0);
437+
msg->AddText("Quality::Null. Failed checks:");
438+
checkMessage = mPadMetaData[Quality::Null.getName()][iGraph];
439+
}
440+
441+
// Split lines by hand as \n does not work with TPaveText
442+
const std::string delimiter = "\n";
443+
size_t pos = 0;
444+
std::string subText;
445+
while ((pos = checkMessage.find(delimiter)) != std::string::npos) {
446+
subText = checkMessage.substr(0, pos);
447+
msg->AddText(subText.c_str());
448+
checkMessage.erase(0, pos + delimiter.length());
449+
}
450+
msg->AddText(checkResult.getMetadata("Comment", "").c_str());
451+
452+
const int nDataPoints = graphs[iGraph]->GetN();
453+
if (nDataPoints == 0) {
454+
graphs[iGraph]->AddPoint(0., 0.); // have to add dummy point, else msg is not shown
455+
graphs[iGraph]->SetMarkerColor(kWhite); // hide the dummy point
456+
continue;
457+
}
458+
398459
graphs[iGraph]->SetLineColor(kBlack);
399460
double xMin = graphs[iGraph]->GetXaxis()->GetXmin();
400461
double xMax = graphs[iGraph]->GetXaxis()->GetXmax();
@@ -533,46 +594,6 @@ void CheckOfTrendings::beautify(std::shared_ptr<MonitorObject> mo, Quality check
533594
graphs[iGraph]->GetListOfFunctions()->Add(stddevGraphBadDown);
534595
}
535596
}
536-
537-
// InfoBox
538-
std::string checkMessage;
539-
TPaveText* msg = new TPaveText(0.5, 0.75, 0.9, 0.9, "NDC");
540-
msg->SetName(Form("%s_msg_%zu", mo->GetName(), iGraph));
541-
graphs[iGraph]->GetListOfFunctions()->Add(msg);
542-
543-
if (mPadQualities[iGraph] == Quality::Good) {
544-
graphs[iGraph]->SetFillColor(kGreen - 2);
545-
msg->Clear();
546-
msg->AddText("Quality::Good");
547-
msg->SetFillColor(kGreen - 2);
548-
} else if (mPadQualities[iGraph] == Quality::Bad) {
549-
graphs[iGraph]->SetFillColor(kRed);
550-
msg->Clear();
551-
msg->AddText("Quality::Bad. Failed checks:");
552-
checkMessage = mPadMetaData[Quality::Bad.getName()][iGraph];
553-
msg->SetFillColor(kRed);
554-
} else if (mPadQualities[iGraph] == Quality::Medium) {
555-
graphs[iGraph]->SetFillColor(kOrange);
556-
msg->Clear();
557-
msg->AddText("Quality::Medium. Failed checks:");
558-
checkMessage = mPadMetaData[Quality::Medium.getName()][iGraph];
559-
msg->SetFillColor(kOrange);
560-
} else if (mPadQualities[iGraph] == Quality::Null) {
561-
graphs[iGraph]->SetFillColor(0);
562-
msg->AddText("Quality::Null. Failed checks:");
563-
checkMessage = mPadMetaData[Quality::Null.getName()][iGraph];
564-
}
565-
566-
// Split lines by hand as \n does not work with TPaveText
567-
const std::string delimiter = "\n";
568-
size_t pos = 0;
569-
std::string subText;
570-
while ((pos = checkMessage.find(delimiter)) != std::string::npos) {
571-
subText = checkMessage.substr(0, pos);
572-
msg->AddText(subText.c_str());
573-
checkMessage.erase(0, pos + delimiter.length());
574-
}
575-
msg->AddText(checkResult.getMetadata("Comment", "").c_str());
576597
} // for(size_t iGraph = 0; iGraph < graphs.size(); iGraph++)
577598
}
578599

@@ -617,6 +638,8 @@ std::string CheckOfTrendings::createMetaData(const std::vector<std::string>& poi
617638
std::string expectedValueString = "";
618639
std::string rangeString = "";
619640
std::string zeroString = "";
641+
std::string noDataPointsString = "";
642+
std::string noChecksString = "";
620643

621644
for (size_t i = 0; i < pointMetaData.size(); i++) {
622645
if (pointMetaData.at(i).find("MeanCheck") != std::string::npos) {
@@ -631,6 +654,12 @@ std::string CheckOfTrendings::createMetaData(const std::vector<std::string>& poi
631654
if (pointMetaData.at(i).find("ZeroCheck") != std::string::npos) {
632655
zeroString += " " + std::to_string(i) + ",";
633656
}
657+
if (pointMetaData.at(i).find("Graph has no data points") != std::string::npos) {
658+
noDataPointsString += " " + std::to_string(i) + ",";
659+
}
660+
if (pointMetaData.at(i).find("No Checks performed") != std::string::npos) {
661+
noChecksString += " " + std::to_string(i) + ",";
662+
}
634663
}
635664

636665
if (meanString != "") {
@@ -653,6 +682,16 @@ std::string CheckOfTrendings::createMetaData(const std::vector<std::string>& poi
653682
zeroString = "ZeroCheck for Graphs:" + zeroString + "\n";
654683
totalString += zeroString;
655684
}
685+
if (noDataPointsString != "") {
686+
noDataPointsString.pop_back();
687+
noDataPointsString = "No data points for Graphs:" + noDataPointsString + "\n";
688+
totalString += noDataPointsString;
689+
}
690+
if (noChecksString != "") {
691+
noChecksString.pop_back();
692+
noChecksString = "No checks performed for Graphs:" + noChecksString + "\n";
693+
totalString += noChecksString;
694+
}
656695
} else {
657696
totalString = pointMetaData[0];
658697
}

0 commit comments

Comments
 (0)