#include #include #include #include "dbclient/KM3NeTDBClient.h" #include "JDB/JDB.hh" #include "JDB/JDBToolkit.hh" #include "JDB/JSelector.hh" #include "JDB/JSelectorSupportkit.hh" #include "JDB/JCalibration.hh" #include "JDB/JRunCalibration.hh" #include "JDB/JSonSupportkit.hh" #include "JSon/JSon.hh" #include "JSon/JSupport.hh" #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JDetectorSupportkit.hh" #include "JLang/JPredicate.hh" #include "JLang/JManip.hh" #include "JSupport/JMeta.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { static const char* const RUN_t = "RUN"; } /** * \file * * Auxiliary program to download official detector. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JServer server; string usr; string pwd; string cookie; string detid; int run; int ranking; string variant; string outputFile; vector format; int debug; try { JParser<> zap("Auxiliary program to download official detector."); zap['s'] = make_field(server) = getServernames(); zap['u'] = make_field(usr) = ""; zap['!'] = make_field(pwd) = ""; zap['C'] = make_field(cookie) = ""; zap['D'] = make_field(detid); zap['r'] = make_field(run); zap['R'] = make_field(ranking, "ranking (1 is best)") = 1; zap['V'] = make_field(variant, "detector version") = getDetectorVersions(); zap['o'] = make_field(outputFile, "detector file or JSon files (must then contain wildcard \'" << FILENAME_WILD_CARD << "\')") = ""; zap['F'] = make_field(format, "column names: " << RUN_t << ' ' << PMT_T0_CALIBRATION_t << ' ' << DOM_POSITION_CALIBRATION_t << ' ' << DOM_ROTATION_CALIBRATION_t << ' ' << ACOUSTIC_T0_CALIBRATION_t << ' ' << COMPASS_CALIBRATION_t << ' ' << STATUS_CALIBRATION_t) = JPARSER::initialised(); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } try { JDB::reset(usr, pwd, cookie); detid = getDetector(detid); json js; to_json(js, JRunCalibration::getName(), getSelector(detid, run, ranking)); DEBUG(setw(2) << js << endl); if (!is_valid(js)) { FATAL("JSon error code not okay." << endl); } if (!js.contains(Data_t) || js[Data_t].empty()) { FATAL("JSon outout does not contain data." << endl); } struct calibration_type : public vector { /** * Get calibration identifier. * * \param type calibration type * \return calibration idientifier */ std::string operator[](const std::string& type) const { const_iterator p = find_if(this->begin(), this->end(), make_predicate(&JRunCalibration_t::CalibrationType, type)); if (p != this->end()) return p->CalibrationId; else FATAL("No calibration type " << type << endl); } }; const calibration_type calibration = js[Data_t].get(); if (debug >= debug_t) { for (const auto& element : calibration) { cout << setw(24) << left << element.CalibrationType << ' ' << right << element.CalibrationId << endl; } } if (outputFile != "") { if (!hasWildCard(outputFile)) { JDetector detector; *(JDB::get()->DetX)(detid.c_str(), calibration[PMT_T0_CALIBRATION_t] .c_str(), calibration[DOM_POSITION_CALIBRATION_t].c_str(), calibration[DOM_ROTATION_CALIBRATION_t].c_str(), calibration[ACOUSTIC_T0_CALIBRATION_t] .c_str(), calibration[COMPASS_CALIBRATION_t] .c_str(), calibration[STATUS_CALIBRATION_t] .c_str(), getDetectorVersion(variant)) >> detector; detector.comment.add(JMeta(argc,argv)); for (const auto& i : { PMT_T0_CALIBRATION_t, DOM_POSITION_CALIBRATION_t, DOM_ROTATION_CALIBRATION_t, ACOUSTIC_T0_CALIBRATION_t, COMPASS_CALIBRATION_t, STATUS_CALIBRATION_t }) { detector.comment.add(MAKE_STRING(i << "=" << calibration[i])); } if (detector.setToLatestVersion()) { NOTICE("Set detector version to " << detector.getVersion() << endl); } store(outputFile, detector); } else { for (const auto& element : calibration) { json buffer; to_json(buffer, JCalibration_t::getName(), getSelector(detid, element.CalibrationId)); if (is_valid(buffer)) store(setWildCard(outputFile.c_str(), element.CalibrationType), buffer); else ERROR("Invalid JSon data " << setw(2) << buffer); } } } if (!format.empty()) { for (vector::const_iterator i = format.begin(); i != format.end(); ++i) { if (*i == RUN_t) cout << ' ' << run; else cout << ' ' << calibration[*i]; } cout << endl; } } catch(const exception& error) { FATAL(error.what() << endl); } return 0; }