#ifndef __JRUNCONTROL__JEVENTTABLE__ #define __JRUNCONTROL__JEVENTTABLE__ #include #include #include "JNet/JTag.hh" #include "JNet/JControlHost.hh" #include "JRuncontrol/JDAQCHSM.hh" #include "JRuncontrol/JRuncontrolToolkit.hh" /** * \author mdejong */ namespace KM3NETDAQ { using JNET::JTag; using JNET::JSubscriptionList; /** * Type definition of a DAQ event. */ typedef JDAQStateMachine::ev_daq_event JDAQEvent_t; /** * Event table. * * This class consists of a STL map in which the key corresponds to * the unique combination of a ControlHost tag and an event name. * The associated value points to the corresponding event. */ class JEventTable : public std::map { public: typedef std::map JMap_t; /** * Default constructor. */ JEventTable() : JMap_t() {} /** * Get key for a given tag and event. * * \param tag tag * \param event event * \return key */ static std::string getKey(const JTag& tag, const CHSM::event& event) { return getKey(tag, event.name()); } /** * Get key for a given tag and event name. * * \param tag tag * \param event_name event name * \return key */ static std::string getKey(const JTag& tag, const std::string& event_name) { return tag.toString() + getTokenDelimeter() + event_name; } /** * Insert entry in table. * * \param tag tag * \param event event */ void insert(const JTag& tag, JDAQEvent_t& event) { JMap_t::insert(make_pair(getKey(tag,event), &event)); } /** * Replace entry in table. * * \param oldTag old tag * \param newTag new tag * \param event event */ void replace(const JTag& oldTag, const JTag& newTag, JDAQEvent_t& event) { iterator i = JMap_t::find(getKey(oldTag,event)); if (i != this->end()) { this->erase(i); } insert(newTag, event); } /** * Find entry. * * \param tag tag * \param event_name event name */ const_iterator find(const JTag& tag, const std::string& event_name) const { return JMap_t::find(getKey(tag,event_name)); } }; /** * Convert event table to ControlHost subscription. * * \param event_table event table * \return subscription */ inline JSubscriptionList getSubscription(const JEventTable& event_table) { using namespace std; using namespace JPP; JSubscriptionList buffer; for (JEventTable::const_iterator i = event_table.begin(); i != event_table.end(); ++i) { string key = i->first; string::size_type pos = key.find_first_of(TOKEN_DELIMETER); if (pos != string::npos) { buffer.add(JSubscriptionAll(key.substr(0, pos))); } } return buffer; } } #endif