Skip to content

Commit eb40b1f

Browse files
DanielSamitzchiarazampolli
authored andcommitted
added output to .json file
1 parent b04f906 commit eb40b1f

File tree

1 file changed

+33
-47
lines changed

1 file changed

+33
-47
lines changed

RelVal/ReleaseValidation.C

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ void WriteProfile(TProfile* hProf, TDirectory* outDir, std::string const& curren
445445
// functionality for histogram comparison //
446446
////////////////////////////////////////////
447447

448-
448+
// fills the result of a single test into the histogram displaying all test results
449449
void FillhTests(TH2F* hTests,const char* histName, results testResult){
450450
if(testResult.comparable){
451451
if (testResult.passed == false) {
@@ -467,7 +467,7 @@ void FillhTests(TH2F* hTests,const char* histName, results testResult){
467467
}
468468
}
469469

470-
470+
// keeps track if there was at least one failed/critical failed/non-comparable/... test
471471
void SetTestResults(results testResult,bool &test_failed, bool &criticaltest_failed, bool &test_nc, bool &criticaltest_nc){
472472
if (!testResult.passed){
473473
test_failed=true;
@@ -848,13 +848,15 @@ void SelectCriticalHistos()
848848
}
849849

850850

851+
// chi2. critical test
851852
struct results CompareChiSquare(TH1* hA, TH1* hB, double val){
852853
struct results res;
853854
res.testname="Chi2 test";
854855
res.critical=true;
855856

856857
res.passed=true;
857858

859+
//not comparable if some difference in the bins is detected
858860
if (!PotentiallySameAxes(hA,hB)){
859861
res.comparable=false;
860862
printf("%s: %s can not be performed\n",hA->GetName(),res.testname.Data());
@@ -935,6 +937,7 @@ struct results CompareChiSquare(TH1* hA, TH1* hB, double val){
935937
}
936938

937939

940+
//(normalized) difference of bin content. critical test
938941
struct results CompareBinContent(TH1* hA, TH1* hB, double val){
939942
struct results res;
940943
res.testname="Bin cont test";
@@ -943,6 +946,7 @@ struct results CompareBinContent(TH1* hA, TH1* hB, double val){
943946

944947
res.passed=true;
945948

949+
//not comparable if some difference in the bins is detected
946950
if (!PotentiallySameAxes(hA,hB)){
947951
res.comparable=false;
948952
printf("%s: %s can not be performed\n",hA->GetName(),res.testname.Data());
@@ -1007,7 +1011,7 @@ struct results CompareBinContent(TH1* hA, TH1* hB, double val){
10071011
}
10081012

10091013

1010-
1014+
//compare number of entries. non-critical
10111015
struct results CompareNentr(TH1* hA, TH1* hB, double val){
10121016
struct results res;
10131017
res.testname="Num entries test";
@@ -1016,6 +1020,7 @@ struct results CompareNentr(TH1* hA, TH1* hB, double val){
10161020

10171021
res.passed=true;
10181022

1023+
//check only if the range of the histogram is the same, do no care about bins
10191024
if (!PotentiallySameRange(hA,hB)){
10201025
res.comparable=false;
10211026
printf("%s: %s can not be performed\n",hA->GetName(),res.testname.Data());
@@ -1045,6 +1050,7 @@ struct results CompareNentr(TH1* hA, TH1* hB, double val){
10451050
}
10461051

10471052

1053+
//write the result of the check into a .json file. One list for each possible outcome
10481054
void WriteToJson(TH2F* hSum){
10491055
std::vector<std::string> good, warning, bad, nc, critical_nc;
10501056
int nhists=hSum->GetYaxis()->GetNbins();
@@ -1063,67 +1069,47 @@ void WriteToJson(TH2F* hSum){
10631069
if (res==-0.5)
10641070
critical_nc.push_back(label);
10651071
}
1066-
auto good_json = TBufferJSON::ToJSON(&good);
1067-
auto warning_json = TBufferJSON::ToJSON(&warning);
1068-
auto bad_json = TBufferJSON::ToJSON(&bad);
1069-
auto nc_json = TBufferJSON::ToJSON(&nc);
1070-
auto critical_nc_json = TBufferJSON::ToJSON(&critical_nc);
1071-
1072-
1073-
std::map<std::string,std::string> data;
1074-
data["GOOD"] = good_json;
1075-
data["WARNING"] = warning_json;
1076-
data["BAD"] = bad_json;
1077-
data["NONCRIT_NC"] = nc_json;
1078-
data["CRIT_NC"] = critical_nc_json;
1079-
1080-
auto json = TBufferJSON::ToJSON(&data, TBufferJSON::kMapAsObject);
1072+
10811073

10821074
std::ofstream jsonout("Summary.json");
1083-
jsonout << json;
1084-
jsonout.close();
1085-
1086-
std::ofstream jsonout2("Summary2.json");
1087-
jsonout2 << "{\n";
1088-
jsonout2 << "\t\"GOOD\":[";
1075+
jsonout << "{\n";
1076+
jsonout << "\t\"GOOD\":[";
10891077
for (std::string s : good){
1090-
jsonout2 << "\"" << s <<"\"";
1078+
jsonout << "\"" << s <<"\"";
10911079
if (s!=good.back())
1092-
jsonout2 << ",";
1080+
jsonout << ",";
10931081
}
1094-
jsonout2 << "],\n";
1095-
jsonout2 << "\t\"WARNING\":[";
1082+
jsonout << "],\n";
1083+
jsonout << "\t\"WARNING\":[";
10961084
for (std::string s : warning){
1097-
jsonout2 << "\"" << s <<"\"";
1085+
jsonout << "\"" << s <<"\"";
10981086
if (s!=warning.back())
1099-
jsonout2 << ",";
1087+
jsonout << ",";
11001088
}
1101-
jsonout2 << "],\n";
1102-
jsonout2 << "\t\"BAD\":[";
1089+
jsonout << "],\n";
1090+
jsonout << "\t\"BAD\":[";
11031091
for (std::string s : bad){
1104-
jsonout2 << "\"" << s <<"\"";
1092+
jsonout << "\"" << s <<"\"";
11051093
if (s!=bad.back())
1106-
jsonout2 << ",";
1094+
jsonout << ",";
11071095
}
1108-
jsonout2 << "],\n";
1109-
jsonout2 << "\t\"CRIT_NC\":[";
1096+
jsonout << "],\n";
1097+
jsonout << "\t\"CRIT_NC\":[";
11101098
for (std::string s : critical_nc){
1111-
jsonout2 << "\"" << s <<"\"";
1099+
jsonout << "\"" << s <<"\"";
11121100
if (s!=critical_nc.back())
1113-
jsonout2 << ",";
1101+
jsonout << ",";
11141102
}
1115-
jsonout2 << "],\n";
1116-
jsonout2 << "\t\"NONCRIT_NC\":[";
1103+
jsonout << "],\n";
1104+
jsonout << "\t\"NONCRIT_NC\":[";
11171105
for (std::string s : nc){
1118-
jsonout2 << "\"" << s <<"\"";
1106+
jsonout << "\"" << s <<"\"";
11191107
if (s!=nc.back())
1120-
jsonout2 << ",";
1108+
jsonout << ",";
11211109
}
1122-
jsonout2 << "]\n";
1123-
jsonout2 << "}";
1124-
1125-
1126-
jsonout2.close();
1110+
jsonout << "]\n";
1111+
jsonout << "}";
11271112

11281113

1114+
jsonout.close();
11291115
}

0 commit comments

Comments
 (0)