#ifndef __JSON__JSUPPORT__ #define __JSON__JSUPPORT__ #include #include #include #include "JLang/JPredicate.hh" #include "JLang/JException.hh" #include "JSon/JSon.hh" /** * \file * JSon definitions and auxiliaries. * * \author mdejong, bjung, acreusot */ namespace JSON {} namespace JPP { using namespace JSON; } /** * Auxiliary classes and methods for detector calibration. */ namespace JSON { using JLANG::JValueOutOfRange; static const std::string TCAL = "tcal"; //!< PMT time offsets static const std::string PCAL = "pcal"; //!< (optical|base) module positions static const std::string RCAL = "rcal"; //!< optical module orientations static const std::string ACAL = "acal"; //!< acoustic time offsets (piezo sensor or hydrophone) static const std::string CCAL = "ccal"; //!< compass alignment (a.k.a.\ quaternion calibration) static const std::string SCAL = "scal"; //!< (module|PMT) status static const std::string PMT_T0_CALIBRATION_t = "PMT_T0_CALIBRATION"; //!< PMT time offsets static const std::string DOM_POSITION_CALIBRATION_t = "DOM_POSITION_CALIBRATION"; //!< (optical|base) module positions static const std::string DOM_ROTATION_CALIBRATION_t = "DOM_ROTATION_CALIBRATION"; //!< optical module orientations static const std::string ACOUSTIC_T0_CALIBRATION_t = "ACOUSTIC_T0_CALIBRATION"; //!< acoustic time offsets (piezo sensor or hydrophone) static const std::string COMPASS_CALIBRATION_t = "COMPASS_CALIBRATION"; //!< compass alignment (a.k.a.\ quaternion calibration) static const std::string STATUS_CALIBRATION_t = "STATUS_CALIBRATION"; //!< (module|PMT) status /** * Auxiliary data structure for pairwise nick and full name of calibration type. */ struct JCalibrationType { std::string nick_name; //!< nick name (e.g. "xcal") std::string full_name; //!< full name (e.g. "XXX_YYY_CALIBRATION") }; /** * Auxiliary data structure for correspondence between nick and full name of calibration types. */ static const struct getCalibrationType : public std::vector { /** * Default constructor. */ getCalibrationType() { this->push_back( { TCAL, PMT_T0_CALIBRATION_t } ); this->push_back( { PCAL, DOM_POSITION_CALIBRATION_t } ); this->push_back( { RCAL, DOM_ROTATION_CALIBRATION_t } ); this->push_back( { ACAL, ACOUSTIC_T0_CALIBRATION_t } ); this->push_back( { CCAL, COMPASS_CALIBRATION_t } ); this->push_back( { SCAL, STATUS_CALIBRATION_t } ); } /** * Has calibration type. * * \param type full name * \return true if available; else false */ bool hasNickname(const std::string& type) const { using namespace std; using namespace JPP; return (find_if(this->begin(), this->end(), make_predicate(&JCalibrationType::full_name, type)) != this->end()); } /** * Has calibration type. * * \param type nick name * \return full name */ bool hasFullname(const std::string& type) const { using namespace std; using namespace JPP; return (find_if(this->begin(), this->end(), make_predicate(&JCalibrationType::nick_name, type)) != this->end()); } /** * Get calibration type. * * \param type full name * \return nick name */ const std::string& getNickname(const std::string& type) const { using namespace std; using namespace JPP; const_iterator p = find_if(this->begin(), this->end(), make_predicate(&JCalibrationType::full_name, type)); if (p != this->end()) return p->nick_name; else THROW(JValueOutOfRange, "Invalid calibration type <" << type << ">"); } /** * Get calibration type. * * \param type nick name * \return full name */ const std::string& getFullname(const std::string& type) const { using namespace std; using namespace JPP; const_iterator p = find_if(this->begin(), this->end(), make_predicate(&JCalibrationType::nick_name, type)); if (p != this->end()) return p->full_name; else THROW(JValueOutOfRange, "Invalid calibration type <" << type << ">"); } } getCalibrationType; // Meta data static const std::string User_t = "User"; static const std::string UserId_t = "UserId"; static const std::string TypeId_t = "TypeId"; static const std::string Location_t = "Location"; static const std::string LocationId_t = "LocId"; static const std::string Time_t = "Time"; static const std::string Start_t = "Start"; static const std::string End_t = "End"; static const std::string Comment_t = "Comment"; static const std::string Encoding_t = "Encoding"; static const std::string Input_t = "Inputs"; static const std::string Error_t = "Error"; static const std::string Message_t = "Message"; static const std::string Code_t = "Code"; static const std::string Provenance_t = "Provenance"; static const std::string Info_t = "Info"; static const std::string Configuration_t = "Configuration"; static const std::string Arguments_t = "Arguments"; static const std::string Inputs_t = "Inputs"; static const std::string UUID_t = "UUID"; static const std::string APIVersion_t = "APIVersion"; static const std::string Result_t = "Result"; static const std::string Status_t = "StatusId"; static const std::string Decision_t = "DecisionId"; static const std::string OK_t = "OK"; static const std::string Fail_t = "FAIL"; static const std::string ValidFrom_t = "ValidFrom"; static const std::string ValidThrough_t = "ValidThrough"; static const std::string StartTime_t = "StartTime"; static const std::string EndTime_t = "EndTime"; static const std::string Tags_t = "Tags"; // Type specifiers static const std::string Type_t = "Type"; static const std::string Test_t = "Test"; static const std::string Tests_t = "Tests"; static const std::string Data_t = "Data"; static const std::string URL_t = "URL"; static const std::string Name_t = "Name"; static const std::string Unit_t = "Unit"; static const std::string Values_t = "Values"; static const std::string Parameters_t = "Parameters"; static const std::string RunNumber_t = "RUN_NUMBER"; // Calibration types static const std::string PMTT0s_t = "PMTT0s"; static const std::string DOMPositions_t = "DOMPositions"; static const std::string DOMRotations_t = "DOMRotations"; static const std::string DOMAcousticT0_t = "DOMAcousticT0s"; static const std::string DOMCompassRotations_t = "DOMCompassRotations"; static const std::string DOMStatusInfo_t = "DOMStatusInfo"; static const std::string BasePositions_t = "BasePositions"; static const std::string BaseAcousticT0_t = "BaseAcousticT0s"; static const std::string BaseCompassRotations_t = "BaseCompassRotations"; static const std::string BaseStatusInfo_t = "BaseStatusInfo"; // Module map of PMT addresses static const std::string DOMMap_t = "DOMMap"; // HV tuning types static const std::string PMTThreshold_t = "PMT_Threshold"; static const std::string PMTStatusInfo_t = "PMTStatusInfo"; static const std::string PMTSupplyVoltage_t = "PMT_Supply_Voltage"; static const std::string PMTGain_t = "PMT_Gain"; // Object identifiers static const std::string UPI_t = "UPI"; static const std::string PBS_t = "PBS"; static const std::string Variant_t = "Variant"; static const std::string DetOID_t = "DetOID"; static const std::string DetID_t = "DetID"; static const std::string Serial_t = "Serial"; static const std::string DOMId_t = "DOMId"; static const std::string Id_t = "Id"; // Variable names static const std::string T0_t = "T0"; static const std::string PX_t = "PX"; static const std::string PY_t = "PY"; static const std::string PZ_t = "PZ"; static const std::string Q0_t = "Q0"; static const std::string QX_t = "QX"; static const std::string QY_t = "QY"; static const std::string QZ_t = "QZ"; static const std::string STATUS_t = "Status"; // Units static const std::string Unitless_t = "-"; static const std::string Volt_t = "V"; /** * Check validity of JSon data. * * \param js JSon data * \return true if valid; else false */ inline bool is_valid(const json& js) { return (js.contains(Error_t) && js[Error_t][Code_t] == OK_t); } } #endif