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