#ifndef __JRECONSTRUCTION__JHISTORY__ #define __JRECONSTRUCTION__JHISTORY__ #include #include #include #include #include #include #include #include "km3net-dataformat/definitions/fitparameters.hh" #include "JROOT/JRoot.hh" #include "JLang/Jpp.hh" #include "JLang/JUUID.hh" #include "JLang/JPredicate.hh" #include "JSystem/JDate.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 JPP; this->type = type; this->uuid = JUUID::rndm(); this->git = getGITVersion(); this->date = getDateAndTime(); } /** * Virtual destructor. */ virtual ~JEvent() {} /** * 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 }; /** * Container for historical events. */ struct JHistory : public std::vector { /** * Auxiliary class to test history. */ struct is_event { /** * Constructor. * * \param type application type */ is_event(int type) { this->type = type; } /** * Constructor. * * \param history history */ is_event(const JHistory& history) { if (!history.empty()) this->type = history.rbegin()->type; else this->type = -1; } /** * Test history. * * \param history history * \return true if given history ends with specified event type; else false */ bool operator()(const JHistory& history) const { if (!history.empty()) { return history.rbegin()->type == this->type; } return false; } 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 type application type */ JHistory(const int type) : std::vector() { add(type); } /** * Constructor. * * \param history history * \param type application type */ JHistory(const JHistory& history, const int type) : std::vector(history) { add(type); } /** * 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