#ifndef __JDB_JDBSUPPORTKIT__ #define __JDB_JDBSUPPORTKIT__ #include #include #include #include #include "JLang/JException.hh" #include "JLang/JComparable.hh" #include "Jeep/JVersion.hh" #include "JDB/JRuns.hh" #include "JDB/JRunQuality.hh" /** * \author mdejong, bjung */ namespace JDATABASE {}; namespace JPP { using namespace JDATABASE; } /** * Auxiliary classes and methods for database I/O. */ namespace JDATABASE { using JEEP::JVersion; using JLANG::JComparable; using JLANG::JValueOutOfRange; /** * Auxiliary class for detector/run comparisons. */ struct JRun_t : public JComparable, public JComparable, public JComparable { /** * Constructor. * * \param detector detector * \param run run */ JRun_t(const int detector, const int run) : detector(detector), run (run) {} /** * Less-than method. * * \param object run */ bool less(const JRun_t& object) const { if (this->detector == object.detector) return this->run < object.run; else return this->detector < object.detector; } /** * Less-than method. * * \param object run */ bool less(const JRuns& object) const { if (this->detector == object.DETID) return this->run < object.RUN; else return this->detector < object.DETID; } /** * More-than method. * * \param object run */ bool more(const JRuns& object) const { if (this->detector == object.DETID) return this->run > object.RUN; else return this->detector > object.DETID; } /** * Less-than method. * * \param object run */ bool less(const JRunQuality& object) const { if (this->detector == object.detector) return this->run < object.run; else return this->detector < object.detector; } /** * More-than method. * * \param object run */ bool more(const JRunQuality& object) const { if (this->detector == object.detector) return this->run > object.run; else return this->detector > object.detector; } int detector; int run; }; /** * Auxiliary data structure for I/O of database API versions. */ struct JDBAPIVersion : public JVersion, public JComparable { /** * Default constructor. */ JDBAPIVersion() : JVersion() {} /** * Constructor. * * \param major major version * \param minor minor version * \param patch patch version */ JDBAPIVersion(const int major, const int minor, const int patch) : JVersion(major, minor, patch) {} /** * Check validity. * * \return true if valid; else false */ bool is_valid() const { using namespace std; static const set versions{ JVersion(1, 0, 0), JVersion(2, 0, 0) }; for (set::const_iterator i = versions.cbegin(); i != versions.cend(); ++i) { if (i->getMajorVersion() == this->getMajorVersion() && i->getMinorVersion() == this->getMinorVersion() && i->getPatchVersion() == this->getPatchVersion()) { return true; } } return false; } }; /** * Table listing HV-tuning database test types. */ struct JDBTestTypesTuneHV { /** * Constructor. */ JDBTestTypesTuneHV() { DBTestTypesTuneHV.insert("HV-TUNING-GAIN-v1"); DBTestTypesTuneHV.insert("HV-TUNING-GAIN-v2"); DBTestTypesTuneHV.insert("HV-TUNING-GAIN-v3"); } /** * Get HV-tuning DB test type corresponding to given version number. * * \param version version number * \return HV-tuning database test type */ const std::string& operator()(const int version) const { using namespace std; for (set::const_iterator i = DBTestTypesTuneHV.cbegin(); i != DBTestTypesTuneHV.cend(); ++i) { if (i->find(to_string(version)) != string::npos) { return *i; } } THROW(JValueOutOfRange, "JDBTestTypesTuneHV::operator(): No HV-tuning database test type corresponding to given version number \'" << version << "\'."); } /** * Get version number corresponding to given HV-tuning DB test type. * * \param testType HV-tuning database test type * \return version number */ const int operator()(const std::string& testType) const { using namespace std; for (set::const_iterator i = DBTestTypesTuneHV.cbegin(); i != DBTestTypesTuneHV.cend(); ++i) { if (i->compare(testType) == 0) { const int pos = i->find('v') + 1; return stoi(i->substr(pos)); } } THROW(JValueOutOfRange, "JDBTestTypesTuneHV::operator(): Given HV-tuning database test type \'" << testType << "\' is invalid."); } protected: std::set DBTestTypesTuneHV; }; extern JDBTestTypesTuneHV getDBTestTypeTuneHV; //!< Function object for looking up the HV-tuning database test type corresponding to a specific version number. static JDBTestTypesTuneHV& getDBVersionTuneHV = getDBTestTypeTuneHV; //!< Function object for looking up the HV-tuning database version number corresponding to a specific test type. } #endif