Jpp  15.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEventTable.hh
Go to the documentation of this file.
1 #ifndef __JRUNCONTROL__JEVENTTABLE__
2 #define __JRUNCONTROL__JEVENTTABLE__
3 
4 #include <string>
5 #include <map>
6 
7 #include "JNet/JTag.hh"
8 #include "JNet/JControlHost.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace KM3NETDAQ {
17 
18  using JNET::JTag;
20 
21 
22  /**
23  * Type definition of a DAQ event.
24  */
26 
27 
28  /**
29  * Event table.
30  *
31  * This class consists of a STL map<key,value> in which the key corresponds to
32  * the unique combination of a ControlHost tag and an event name.
33  * The associated value points to the corresponding event.
34  */
35  class JEventTable :
36  public std::map<std::string, JDAQStateMachine::ev_daq_event*>
37  {
38  public:
39 
41 
42 
43  /**
44  * Default constructor.
45  */
47  JMap_t()
48  {}
49 
50 
51  /**
52  * Get key for a given tag and event.
53  *
54  * \param tag tag
55  * \param event event
56  * \return key
57  */
58  static std::string getKey(const JTag& tag, const CHSM::event& event)
59  {
60  return getKey(tag, event.name());
61  }
62 
63 
64  /**
65  * Get key for a given tag and event name.
66  *
67  * \param tag tag
68  * \param event_name event name
69  * \return key
70  */
71  static std::string getKey(const JTag& tag, const std::string& event_name)
72  {
73  return tag.toString() + getTokenDelimeter() + event_name;
74  }
75 
76 
77  /**
78  * Insert entry in table.
79  *
80  * \param tag tag
81  * \param event event
82  */
83  void insert(const JTag& tag, JDAQEvent_t& event)
84  {
85  JMap_t::insert(make_pair(getKey(tag,event), &event));
86  }
87 
88 
89  /**
90  * Replace entry in table.
91  *
92  * \param oldTag old tag
93  * \param newTag new tag
94  * \param event event
95  */
96  void replace(const JTag& oldTag,
97  const JTag& newTag,
98  JDAQEvent_t& event)
99  {
100  iterator i = JMap_t::find(getKey(oldTag,event));
101 
102  if (i != this->end()) {
103  this->erase(i);
104  }
105 
106  insert(newTag, event);
107  }
108 
109 
110  /**
111  * Find entry.
112  *
113  * \param tag tag
114  * \param event_name event name
115  */
116  const_iterator find(const JTag& tag, const std::string& event_name) const
117  {
118  return JMap_t::find(getKey(tag,event_name));
119  }
120  };
121 
122 
123  /**
124  * Convert event table to ControlHost subscription.
125  *
126  * \param event_table event table
127  * \return subscription
128  */
129  inline JSubscriptionList getSubscription(const JEventTable& event_table)
130  {
131  using namespace std;
132  using namespace JPP;
133 
134  JSubscriptionList buffer;
135 
136  for (JEventTable::const_iterator i = event_table.begin(); i != event_table.end(); ++i) {
137 
138  string key = i->first;
139  string::size_type pos = key.find_first_of(TOKEN_DELIMETER);
140 
141  if (pos != string::npos) {
142  buffer.add(JSubscriptionAll(key.substr(0, pos)));
143  }
144  }
145 
146  return buffer;
147  }
148 }
149 
150 #endif
std::map< std::string, JDAQStateMachine::ev_daq_event * > JMap_t
Definition: JEventTable.hh:40
static std::string getKey(const JTag &tag, const std::string &event_name)
Get key for a given tag and event name.
Definition: JEventTable.hh:71
static const std::string TOKEN_DELIMETER
Definition: JDAQTags.hh:36
Subscription list.
void replace(const JTag &oldTag, const JTag &newTag, JDAQEvent_t &event)
Replace entry in table.
Definition: JEventTable.hh:96
JEventTable()
Default constructor.
Definition: JEventTable.hh:46
char getTokenDelimeter()
Get the token delimeter for command messages.
Auxiliary class for all subscription.
Definition: JControlHost.hh:97
static std::string getKey(const JTag &tag, const CHSM::event &event)
Get key for a given tag and event.
Definition: JEventTable.hh:58
void insert(const JTag &tag, JDAQEvent_t &event)
Insert entry in table.
Definition: JEventTable.hh:83
std::string toString() const
Convert tag to string.
Definition: JTag.hh:171
JSubscriptionList getSubscription(const JEventTable &event_table)
Convert event table to ControlHost subscription.
Definition: JEventTable.hh:129
ControlHost tag.
Definition: JTag.hh:38
JDAQStateMachine::ev_daq_event JDAQEvent_t
Type definition of a DAQ event.
Definition: JEventTable.hh:25
const_iterator find(const JTag &tag, const std::string &event_name) const
Find entry.
Definition: JEventTable.hh:116
ControlHost tag.