#include #include "JSon/JSon.hh" #include "JLang/JUUID.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "JSystem/JDateAndTime.hh" #include "JSupport/JFilenameSupportkit.hh" #include "JDB/JDBSupportkit.hh" #include "JDetector/JDetectorCalibration.hh" /** * \file * * Test program to check DB-conformity of HV-tuning output. * \author bjung */ int main(int argc, char **argv) { using namespace std; using namespace JPP; vector inputFiles; int debug; try { JParser<> zap("Auxiliary program to print high-voltage tuning results."); zap['f'] = make_field(inputFiles, "input files (JSON output of JTuneHV)"); zap['d'] = make_field(debug, "debug") = 2; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } for (vector::const_iterator i = inputFiles.cbegin(); i != inputFiles.cend(); ++i) { NOTICE("Testing database-conformity of " << (*i) << endl); if (isJSONFile((*i).c_str())) { json js; ifstream ifs((*i).c_str()); ifs >> js; ifs.close(); JHVCalibration HVcals; // Check presence of necessary field for database conformity json::const_iterator p0 = js.find(APIVersion_t); if (p0 != js.cend()) { JDBAPIVersion DBAPIVersion; istringstream iss(p0->get()); iss >> DBAPIVersion; if (DBAPIVersion.getMajorVersion() == 2) { json::const_iterator p1 = js.find(Data_t + Type_t); json::const_iterator p2 = js.find(Encoding_t); json::const_iterator p3 = js.find(Error_t); json::const_iterator p4 = js.find(Start_t); json::const_iterator p5 = js.find(End_t); json::const_iterator p6 = js.find(Data_t); if (p1 != js.cend() && p2 != js.cend() && p3 != js.cend() && p4 != js.cend() && p5 != js.cend() && p6 != js.cend() && p6->size() > 0) { const string& dataType = p1->get(); const string& encoding = p2->get(); const json& error = *p3; const string& start = p4->get(); const string& end = p5->get(); const json& data = p6->at(0); ASSERT(dataType == "ProductTestSession"); ASSERT(encoding == "NativeJSON"); ASSERT(JDateAndTime::isISO8601(start)); ASSERT(JDateAndTime::isISO8601(end)); json::const_iterator q01 = error.find(Arguments_t); json::const_iterator q02 = error.find(Code_t); json::const_iterator q03 = error.find(Message_t); if (q01 != error.cend() && q02 != error.cend() && q03 != error.cend()) { const json& arguments = *q01; const string& errorCode = q02->get(); const string& errorMessage = q03->get(); ASSERT(arguments.size() >= 0); ASSERT(errorCode == OK_t); ASSERT(errorMessage.size() >= 0); } else { FATAL("Incomplete \'" << Error_t << "\' field."); } json::const_iterator q11 = data.find(Provenance_t + Info_t); json::const_iterator q12 = data.find(User_t); json::const_iterator q13 = data.find(Location_t); json::const_iterator q14 = data.find(Start_t + Time_t); json::const_iterator q15 = data.find(End_t + Time_t); json::const_iterator q16 = data.find(Test_t + Type_t); json::const_iterator q17 = data.find(Tests_t); if (q11 != data.cend() && q12 != data.cend() && q13 != data.cend() && q14 != data.cend() && q15 != data.cend() && q16 != data.cend() && q17 != data.cend()) { const json& metaData = *q11; json::const_iterator r1 = metaData.find(Configuration_t); json::const_iterator r2 = metaData.find(UUID_t); if (r1 != metaData.cend() && r2 != metaData.cend()) { const string& config = r1->get(); const JUUID UUID = JUUID::valueOf(r2->get()); ASSERT(!config.empty()); ASSERT(UUID.is_valid()); } else { FATAL("Incomplete \'" << Provenance_t + Info_t << "\' field"); } const string& user = q12->get(); const string& location = q13->get(); const string& StartTime = q14->get(); const string& EndTime = q15->get(); ASSERT(!user.empty()); ASSERT(!location.empty()); ASSERT(JDateAndTime::isISO8601(StartTime)); ASSERT(JDateAndTime::isISO8601(EndTime)); JHVCalibration_t::setVersion(getDBVersionTuneHV(q16->get())); HVcals = q17->get(); } else { FATAL("Incomplete \'" << Data_t << "\' field"); } } else { FATAL("Missing fields in \'" << (*i) << "\' for database API version " << DBAPIVersion); } } else { FATAL("Invalid database API version " << DBAPIVersion); } } else { json::const_iterator p1 = js.find(Test_t + Type_t); json::const_iterator p2 = js.find(User_t); json::const_iterator p3 = js.find(Location_t); json::const_iterator p4 = js.find(Start_t + Time_t); json::const_iterator p5 = js.find(End_t + Time_t); json::const_iterator p6 = js.find(Tests_t); if (p1 != js.cend() && p2 != js.cend() && p3 != js.cend() && p4 != js.cend() && p5 != js.cend() && p6 != js.cend()) { const string& user = p2->get(); const string& location = p3->get(); const string& StartTime = p4->get(); const string& EndTime = p5->get(); ASSERT(!user.empty()); ASSERT(!location.empty()); ASSERT(JDateAndTime::isISO8601(StartTime)); ASSERT(JDateAndTime::isISO8601(EndTime)); JHVCalibration_t::setVersion(getDBVersionTuneHV(p1->get())); HVcals = p6->get(); } else { FATAL("Missing fields in " << (*i)); } } // Check HV-calibrations database conformity for (JHVCalibration::const_iterator it = HVcals.cbegin(); it != HVcals.cend(); ++it) { ASSERT(it->is_valid()); ASSERT(it->getPBS() == PBS::PMT); ASSERT(it->supplyVoltage <= 0.0); if (JHVCalibration_t::getVersion() < 3) { ASSERT(!it->runNumbers.empty()); } if (JHVCalibration_t::getVersion() < 2) { ASSERT(it->PMTgain >= 0.0); } } } else { FATAL((*i) << " is not a JSON file."); } } return 0; }