#ifndef __JDB_JRUNSETUPS__ #define __JDB_JRUNSETUPS__ #include #include #include #include #include "JDB/JRuns.hh" #include "Jeep/JeepToolkit.hh" /** * \author mdejong */ namespace JDATABASE {} namespace JPP { using namespace JDATABASE; } namespace JDATABASE { /** * Auxiliary data structure for run setup information. */ struct JRunsetup_t { std::string name; float value; }; /** * Auxiliary class for run setup evaluation. * * The run number is mapped to a unique floating point value according the setup name. */ struct JRunsetups : public std::map { static const char SEPARATOR = '.'; //!< separator between tokens in setup name static const int MAX_NUMBER_OF_SETUPS = 1000; //!< maximal number of setups for a main category /** * Main run setup category. */ enum JRuntype_t { CALIB = 100, //!< Calibration NANOCALIB = 200, //!< Nano-beacon calibration TEST = 300, //!< Test WRONG_TEST = 400, //!< Wrong test PHYS = 1000, //!< Physics OTHER = -1 //!< Other }; /** * Get run setup type. * * \param setup run setup name * \return type */ static inline int getType(const std::string& setup) { using namespace std; using namespace JPP; static std::map buffer; if (buffer.empty()) { #define MAKE_ENTRY(A) std::make_pair(getClassname(#A), A) buffer.insert(MAKE_ENTRY(CALIB)); buffer.insert(MAKE_ENTRY(NANOCALIB)); buffer.insert(MAKE_ENTRY(TEST)); buffer.insert(MAKE_ENTRY(WRONG_TEST)); buffer.insert(MAKE_ENTRY(PHYS)); buffer.insert(MAKE_ENTRY(OTHER)); #undef MAKE_ENTRY } string key = setup; string::size_type pos = key.find(SEPARATOR); if (pos != string::npos) { key = key.substr(0,pos); } std::map::const_iterator i = buffer.find(key); if (i != buffer.end()) return i->second; else return OTHER; } /** * Put run parameters. * * \param run run number * \param setup run setup name */ void put(const int run, const std::string setup) { using namespace std; using namespace JPP; const int type = getType(setup); vector& buffer = data[type]; vector::iterator p = std::find(buffer.begin(), buffer.end(), setup); if (p == buffer.end()) { buffer.push_back(setup); p = buffer.rbegin().base(); } const int index = distance(buffer.begin(),p) + 1; if (index >= MAX_NUMBER_OF_SETUPS) { cerr << "Index of " << setup << ' ' << index << " >= " << MAX_NUMBER_OF_SETUPS << endl; } if (type > 0) (*this)[run] = { setup, type + (float) index / (float) MAX_NUMBER_OF_SETUPS }; else (*this)[run] = { setup, type - (float) index / (float) MAX_NUMBER_OF_SETUPS }; } /** * Put run parameters. * * \param parameters run parameters */ void put(const JRuns& parameters) { put(parameters.RUN, parameters.RUNSETUPNAME); } /** * Check if run setup is vailable. * * \param run run number * \return true if available; else false */ bool has(const int run) const { return this->find(run) != this->end(); } /** * Get run setup value. * * \param run run number * \return value */ float get(const int run) const { const_iterator p = this->find(run); if (p != this->end()) return p->second.value; else return 0.0; } protected: mutable std::map > data; // run type -> run setup names }; } #endif