#ifndef __JRECONSTRUCTION__JHISTORY__ #define __JRECONSTRUCTION__JHISTORY__ #include #include #include #include #include #include #include #include #include "km3net-dataformat/definitions/fitparameters.hh" #include "JLang/Jpp.hh" #include "JLang/JUUID.hh" #include "JLang/JPredicate.hh" #include "JSystem/JDateAndTime.hh" /** * \author mdejong */ namespace JRECONSTRUCTION {} namespace JPP { using namespace JRECONSTRUCTION; } namespace JFIT { using JLANG::JUUID; /** * Auxiliary class for historical event. */ struct JEvent { /** * Default constructor. */ JEvent() : type(-1), uuid() {} /** * Constructor. * * \param type application type */ JEvent(const int type) { using namespace std; using namespace JPP; this->type = type; this->git = getGITVersion(); this->date = getDateAndTime(); // UUID random_device device; uniform_int_distribution generator(1, numeric_limits::max()); uint32_t* value = reinterpret_cast(&(this->uuid.uuid)); for (int i = 0; i != 3; ++i) { value[i] = generator(device); } } /** * Virtual destructor. */ virtual ~JEvent() {} /** * Make this event unique. * * \return event */ const JEvent& operator()() { uint32_t* value = reinterpret_cast(&(this->uuid.uuid)); value[3] = ++counter; return *this; } /** * Write event to output stream. * * \param out output stream * \param event event * \return output stream */ friend std::ostream& operator<<(std::ostream& out, const JEvent& event) { using namespace std; out << setw(3) << right << event.type << ' ' << setw(36) << left << event.uuid << ' ' << setw(20) << left << event.git << ' ' << setw(20) << left << event.date << right; return out; } ClassDef(JEvent, 2); int type; ///< application type JUUID uuid; ///< UUID std::string git; ///< GIT revision std::string date; ///< date uint32_t counter = 0;//!< internal counter }; /** * Container for historical events. */ struct JHistory : public std::vector { /** * Auxiliary class to test history. */ struct is_event : public std::vector { /** * Constructor. * * \param history history */ is_event(const JHistory& history) { for (JHistory::const_iterator i = history.begin(); i != history.end(); ++i) { this->push_back(i->type); } } /** * Test history. * * \param history history * \return true if given history same as this history; else false */ bool operator()(const JHistory& history) const { return history.getStatus(*this); } }; /** * Auxiliary class to test history. */ struct is_application { /** * Constructor. * * \param type application type */ is_application(int type) : type(type) {} /** * Test history. * * \param history history * \return true if given history ends with this application type; else false */ bool operator()(const JHistory& history) const { return !history.empty() && history.rbegin()->type == this->type; } int type; }; /** * Auxiliary class to test history. */ struct is_not_event { /** * Constructor. * * \param type application type */ is_not_event(int type) { this->type = type; } /** * Test history. * * \param history history * \return true if given history does not contain specified event type; else false */ bool operator()(const JHistory& history) const { using namespace std; using namespace JPP; return count_if(history.begin(), history.end(), make_predicate(&JEvent::type, this->type)) == 0; } int type; }; /** * Default constructor. */ JHistory() : std::vector() {} /** * Constructor. * * \param event event */ JHistory(const JEvent& event) : std::vector(1, event) {} /** * Constructor. * * \param type application type */ JHistory(const int type) : std::vector(1, JEvent(type)) {} /** * Constructor. * * \param history history * \param event event */ JHistory(const JHistory& history, const JEvent& event) : std::vector(history) { push_back(event); } /** * Virtual destructor. */ virtual ~JHistory() {} /** * Get history. * * \return histtory */ const JHistory& getHistory() const { return static_cast(*this); } /** * Get history. * * \return histtory */ JHistory& getHistory() { return static_cast(*this); } /** * Has event in history. * * \param type application type * \return true if given event in history; else false */ bool has(const int type) const { for (const_iterator i = this->begin(); i != this->end(); ++i) { if (i->type == type) { return true; } } return false; } /** * Get status. * * \param types application types * \return true if history matches appplication types; else false */ bool getStatus(const std::vector& types) const { if (this->size() == types.size()) { for (size_t i = 0; i != this->size(); ++i) { if ((*this)[i].type != types[i]) { return false; } } return true; } else { return false; } } /** * Add event to history. * * \param type application type * \return this history */ JHistory& add(const int type) { push_back(JEvent(type)); return *this; } /** * Has parent UUID. */ bool hasParentUUID() const { return this->size() >= 2u; } /** * Get UUID. */ const JUUID& getUUID() const { return this->at(this->size() - 1).uuid; } /** * Get parent UUID. */ const JUUID& getParentUUID() const { return this->at(this->size() - 2).uuid; } /** * Write history to output stream. * * \param out output stream * \param history history * \return output stream */ friend std::ostream& operator<<(std::ostream& out, const JHistory& history) { using namespace std; for (const_iterator i = history.begin(); i != history.end(); ++i) { out << *i << endl; } return out; } ClassDef(JHistory, 2); }; } namespace JRECONSTRUCTION { typedef JFIT::JEvent JEvent; typedef JFIT::JHistory JHistory; } #endif