Skip to content

Commit d2f6f5a

Browse files
DanielSamitzchiarazampolli
authored andcommitted
more detailed output to .json
1 parent 100ab33 commit d2f6f5a

File tree

1 file changed

+68
-37
lines changed

1 file changed

+68
-37
lines changed

RelVal/ReleaseValidation.C

Lines changed: 68 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void SelectCriticalHistos();
4545
void createTestsSummaryPlot(TFile* file, TString const& obj);
4646
bool WriteObject(TObject* o, TDirectory* outDir, std::string const& currentPrefix = "");
4747
void SetZLabels(TAxis* axis);
48-
void WriteToJson(TH2F* hSum);
48+
void WriteToJson(TH2F* hSumCheck, TH2F* hSumTests);
4949

5050
bool checkFileOpen(TFile* file)
5151
{
@@ -209,7 +209,7 @@ void ReleaseValidation(const TString filename1, const TString filename2,
209209
}
210210
fileSummaryOutput->Close();
211211

212-
WriteToJson(hSummaryCheck);
212+
WriteToJson(hSummaryCheck,hSummaryTests);
213213
}
214214

215215
// setting the labels of the Z axis for the colz plot
@@ -219,9 +219,9 @@ void SetZLabels(TAxis* axis)
219219
axis->SetNdivisions(10, kFALSE);
220220
axis->SetTickLength(0.);
221221
axis->ChangeLabel(1, -1, 0, -1, -1, -1, "");
222-
axis->ChangeLabel(2, -1, -1, -1, -1, -1, "N.C. (crit.)");
222+
axis->ChangeLabel(2, -1, -1, -1, -1, -1, "#splitline{NOT COMPARABLE}{(critical)}");
223223
axis->ChangeLabel(3, -1, 0, -1, -1, -1, "");
224-
axis->ChangeLabel(4, -1, -1, -1, -1, -1, "N.C. (non-crit.)");
224+
axis->ChangeLabel(4, -1, -1, -1, -1, -1, "#splitline{NOT COMPARABLE}{(non-critical)}");
225225
axis->ChangeLabel(5, -1, 0, -1, -1, -1, "");
226226
axis->ChangeLabel(6, -1, -1, -1, -1, -1, "BAD");
227227
axis->ChangeLabel(7, -1, 0, -1, -1, -1, "");
@@ -1042,46 +1042,77 @@ struct results CompareNentr(TH1* hA, TH1* hB, double val)
10421042
return res;
10431043
}
10441044

1045-
void WriteSingleJSONKeyVal(std::ofstream& os, std::vector<std::string> const& labels, std::string const& key, std::string const& last = ",")
1046-
{
1047-
os << " \"" << key << "\": [";
1048-
for (auto& l : labels) {
1049-
os << "\"" << l << "\"";
1050-
if (l != labels.back())
1051-
os << ",";
1045+
void WriteListsToJson(std::ofstream &jsonout, std::vector<std::string> (&results)[5],std::string (&results_names)[5],int indent=1){
1046+
for (int i=0;i<5;i++){
1047+
for (int in=0;in<indent;in++)
1048+
jsonout << " ";
1049+
jsonout << "\"" <<results_names[i] << "\":[";
1050+
for (std::string s : results[i]){
1051+
jsonout << "\"" << s <<"\"";
1052+
if (s!=results[i].back())
1053+
jsonout << ",";
1054+
}
1055+
jsonout << "]";
1056+
if (i<4)
1057+
jsonout << ",";
1058+
jsonout << "\n";
1059+
results[i].clear();
10521060
}
1053-
os << "]" << last << "\n";
10541061
}
10551062

1056-
// write the result of the check into a .json file. One list for each possible outcome
1057-
void WriteToJson(TH2F* hSum)
1058-
{
1063+
1064+
//write the result of the check into a .json file. One list for each possible outcome.
1065+
void WriteToJson(TH2F* hSumCheck, TH2F* hSumTests){
10591066
std::vector<std::string> good, warning, bad, nc, critical_nc;
1060-
int nhists = hSum->GetYaxis()->GetNbins();
1061-
1062-
for (int i = 1; i <= nhists; i++) {
1063-
double res = hSum->GetBinContent(1, i);
1064-
const char* label = hSum->GetYaxis()->GetBinLabel(i);
1065-
if (res == 0)
1066-
bad.push_back(label);
1067-
if (res == 0.5)
1068-
warning.push_back(label);
1069-
if (res == 1)
1070-
good.push_back(label);
1071-
if (res == -0.25)
1072-
nc.push_back(label);
1073-
if (res == -0.5)
1074-
critical_nc.push_back(label);
1075-
}
1067+
std::vector<std::string> TestNames;
1068+
std::vector<std::string> results[5];
1069+
std::string results_names[5] = {"GOOD","WARNING","BAD","CRIT_NC","NONCRIT_NC"};
1070+
int nhists=hSumCheck->GetYaxis()->GetNbins();
1071+
int ntests=hSumTests->GetXaxis()->GetNbins();
10761072

10771073
std::ofstream jsonout("Summary.json");
10781074
jsonout << "{\n";
1079-
WriteSingleJSONKeyVal(jsonout, good, "GOOD");
1080-
WriteSingleJSONKeyVal(jsonout, warning, "WARNING");
1081-
WriteSingleJSONKeyVal(jsonout, bad, "BAD");
1082-
WriteSingleJSONKeyVal(jsonout, critical_nc, "CRIT_NC");
1083-
WriteSingleJSONKeyVal(jsonout, nc, "NONCRIT_NC", "");
1084-
jsonout << "}";
10851075

1076+
jsonout << " \"Summary\":{\n";
1077+
for(int i=1;i<=nhists;i++){
1078+
double res = hSumCheck->GetBinContent(1,i);
1079+
const char* label = hSumCheck->GetYaxis()->GetBinLabel(i);
1080+
if (res==0)
1081+
results[2].push_back(label);
1082+
if (res==0.5)
1083+
results[1].push_back(label);
1084+
if (res==1)
1085+
results[0].push_back(label);
1086+
if (res==-0.25)
1087+
results[4].push_back(label);
1088+
if (res==-0.5)
1089+
results[3].push_back(label);
1090+
}
1091+
WriteListsToJson(jsonout,results,results_names,2);
1092+
jsonout << " },\n";
1093+
1094+
for (int t=1;t<=ntests;t++){
1095+
jsonout << " \"" << hSumTests->GetXaxis()->GetBinLabel(t) << "\":{\n";
1096+
for(int i=1;i<=nhists;i++){
1097+
double res = hSumTests->GetBinContent(t,i);
1098+
const char* label = hSumTests->GetYaxis()->GetBinLabel(i);
1099+
if (res==0)
1100+
results[2].push_back(label);
1101+
if (res==0.5)
1102+
results[1].push_back(label);
1103+
if (res==1)
1104+
results[0].push_back(label);
1105+
if (res==-0.25)
1106+
results[4].push_back(label);
1107+
if (res==-0.5)
1108+
results[3].push_back(label);
1109+
}
1110+
WriteListsToJson(jsonout,results,results_names,2);
1111+
jsonout << " }";
1112+
if (t<ntests)
1113+
jsonout << ",";
1114+
jsonout << "\n";
1115+
}
1116+
jsonout << "}";
10861117
jsonout.close();
10871118
}

0 commit comments

Comments
 (0)