Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQEvent.hh
Go to the documentation of this file.
1 #ifndef __JDAQEVENT__
2 #define __JDAQEVENT__
3 
4 #include <ostream>
5 #include <iomanip>
6 #include <vector>
7 
8 #include "JDAQ/JDAQRoot.hh"
9 #include "JDAQ/JDAQPreamble.hh"
10 #include "JDAQ/JDAQEventHeader.hh"
11 #include "JDAQ/JDAQHit.hh"
12 #include "JDAQ/JDAQKeyHit.hh"
13 #include "JDAQ/JDAQTriggeredHit.hh"
14 #include "JDAQ/JDAQPrint.hh"
15 #include "JIO/JSTDIO.hh"
16 
17 
18 /**
19  * \author mdejong
20  */
21 
22 namespace KM3NETDAQ {
23 
24  using JIO::JReader;
25  using JIO::JWriter;
26 
27 
29 
30 
31  /**
32  * DAQ Event.
33  */
34  class JDAQEvent :
35  public JDAQPreamble,
36  public JDAQEventHeader
37  {
38  public:
39 
41 
42 
43  /**
44  * Default constructor.
45  */
49  {}
50 
51 
52  /**
53  * Constructor.
54  *
55  * \param chronometer DAQ chronometer
56  * \param mask trigger mask
57  */
58  JDAQEvent(const JDAQChronometer& chronometer,
59  const JDAQTriggerMask& mask = JDAQTriggerMask()) :
61  JDAQEventHeader(chronometer, mask)
62  {}
63 
64 
65  /**
66  * Template const_iterator
67  */
68  template<class T>
69  class const_iterator :
71  {
72  public:
73  /**
74  * Default constructor.
75  */
77  std::vector<T>::const_iterator()
78  {}
79 
80 
81  /**
82  * Copy constructor.
83  *
84  * \param i iterator
85  */
87  std::vector<T>::const_iterator(i)
88  {}
89  };
90 
91 
92  /**
93  * Template const_reverse_iterator
94  */
95  template<class T>
98  {
99  public:
100  /**
101  * Default constructor.
102  */
104  std::vector<T>::const_reverse_iterator()
105  {}
106 
107 
108  /**
109  * Copy constructor.
110  *
111  * \param i iterator
112  */
114  std::vector<T>::const_reverse_iterator(i)
115  {}
116  };
117 
118 
119  /**
120  * Get container with hits.
121  *
122  * \return container with hits
123  */
124  template<class T>
125  const std::vector<T>& getHits() const;
126 
127 
128  /**
129  * Get container with hits.
130  *
131  * \return container with hits
132  */
133  template<class T>
135 
136 
137  /**
138  * Get begin of data.
139  *
140  * \return begin of data
141  */
142  template<class T>
143  const_iterator<T> begin() const;
144 
145 
146  /**
147  * Get end of data.
148  *
149  * \return end of data
150  */
151  template<class T>
152  const_iterator<T> end() const;
153 
154 
155  /**
156  * Get reverse begin of data.
157  *
158  * \return begin of data
159  */
160  template<class T>
161  const_reverse_iterator<T> rbegin() const;
162 
163 
164  /**
165  * Get reverse end of data.
166  *
167  * \return end of data
168  */
169  template<class T>
170  const_reverse_iterator<T> rend() const;
171 
172 
173  /**
174  * Get number of hits.
175  *
176  * \return number of hits
177  */
178  template<class T>
179  unsigned int size() const;
180 
181 
182  /**
183  * Check emptyness of hit container.
184  *
185  * \return true if empty; else false
186  */
187  template<class T>
188  bool empty() const;
189 
190 
191  /**
192  * Clear event.
193  */
194  void clear()
195  {
196  snapshotHits .clear();
197  triggeredHits.clear();
198  }
199 
200 
201  /**
202  * Add hit.
203  *
204  * \param hit hit
205  */
206  void push_back(const JDAQKeyHit& hit)
207  {
208  snapshotHits.push_back(hit);
209  }
210 
211 
212  /**
213  * Add hit.
214  *
215  * \param hit hit
216  */
217  void push_back(const JDAQTriggeredHit& hit)
218  {
219  triggeredHits.push_back(hit);
220  }
221 
222 
223  /**
224  * Get trigger mask of given hit.
225  *
226  * \param hit hit
227  * \return trigger mask
228  */
230  {
231  return hit.getTriggerMask();
232  }
233 
234 
235  /**
236  * Get trigger mask of given hit.
237  *
238  * \param hit hit
239  * \return trigger mask
240  */
242  {
244  if (*i == hit) {
245  return i->getTriggerMask();
246  }
247  }
248 
249  return JTriggerMask_t(0);
250  }
251 
252 
253  /**
254  * Read DAQ event from input.
255  *
256  * \param in JReader
257  * \param event JDAQEvent
258  * \return JReader
259  */
260  friend inline JReader& operator>>(JReader& in, JDAQEvent& event)
261  {
262  in >> static_cast<JDAQPreamble&> (event);
263  in >> static_cast<JDAQEventHeader&>(event);
264  in >> event.triggeredHits;
265  in >> event.snapshotHits;
266 
267  return in;
268  }
269 
270 
271  /**
272  * Write DAQ event to output.
273  *
274  * \param out JWriter
275  * \param event JDAQEvent
276  * \return JWriter
277  */
278  friend inline JWriter& operator<<(JWriter& out, const JDAQEvent& event)
279  {
280  out << static_cast<const JDAQPreamble&> (event);
281  out << static_cast<const JDAQEventHeader&>(event);
282  out << event.triggeredHits;
283  out << event.snapshotHits;
284 
285  return out;
286  }
287 
288 
289  /**
290  * Print DAQ Event.
291  *
292  * \param out output stream
293  * \param lpr long print
294  * \return output stream
295  */
296  std::ostream& print(std::ostream& out, const bool lpr = false) const;
297 
298 
299  /**
300  * Get size of object.
301  *
302  * \return number of bytes
303  */
304  virtual int getSize() const
305  {
306  return (JDAQPreamble ::sizeOf() +
308  sizeof(int) + triggeredHits.size() * JDAQTriggeredHit::sizeOf() +
309  sizeof(int) + snapshotHits .size() * JDAQSnapshotHit ::sizeOf());
310  }
311 
312 
313  ClassDef(JDAQEvent,4);
314 
315 
316  protected:
319  };
320 
321 
322  /**
323  * Equal operator for DAQ events.
324  *
325  * \param first event
326  * \param second event
327  * \result true if first event equal to second; else false
328  */
329  bool operator==(const JDAQEvent& first,
330  const JDAQEvent& second);
331 
332 
333  /**
334  * Not-equal operator for DAQ events.
335  *
336  * \param first event
337  * \param second event
338  * \result true if first event not equal to second; else false
339  */
340  inline bool operator!=(const JDAQEvent& first,
341  const JDAQEvent& second)
342  {
343  return !(first == second);
344  }
345 
346 
347  /**
348  * Print DAQ Event.
349  *
350  * \param out output stream
351  * \param event event
352  * \return output stream
353  */
354  inline std::ostream& operator<<(std::ostream& out, const JDAQEvent& event)
355  {
356  return event.print(out, getDAQLongprint());
357  }
358 }
359 
360 #endif
JDAQTriggerMask()
Default constructor.
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
DAQ key hit.
Definition: JDAQKeyHit.hh:24
Interface for binary output.
JTriggerMask_t getTriggerMask() const
Get trigger mask.
Auxiliary class for a DAQ type holder.
Auxiliary class for trigger mask.
bool empty() const
Check emptyness of hit container.
const_iterator()
Default constructor.
Definition: JDAQEvent.hh:76
JDAQKeyHit JDAQSnapshotHit
Definition: JDAQEvent.hh:28
Template const_iterator.
Definition: JDAQEvent.hh:69
JDAQEvent()
Default constructor.
Definition: JDAQEvent.hh:46
Template const_reverse_iterator.
Definition: JDAQEvent.hh:96
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
std::vector< JDAQTriggeredHit > triggeredHits
Definition: JDAQEvent.hh:317
unsigned int size() const
Get number of hits.
std::ostream & print(std::ostream &out, const bool lpr=false) const
Print DAQ Event.
static JTriggerMask_t getTriggerMask(const JDAQTriggeredHit &hit)
Get trigger mask of given hit.
Definition: JDAQEvent.hh:229
virtual int getSize() const
Get size of object.
Definition: JDAQEvent.hh:304
const_iterator< T > end() const
Get end of data.
unsigned long long int JTriggerMask_t
Type definition of trigger mask.
const std::vector< T > & getHits() const
Get container with hits.
friend JWriter & operator<<(JWriter &out, const JDAQEvent &event)
Write DAQ event to output.
Definition: JDAQEvent.hh:278
const_iterator< T > begin() const
Get begin of data.
JTriggerMask_t getTriggerMask(const JDAQSnapshotHit &hit) const
Get trigger mask of given hit.
Definition: JDAQEvent.hh:241
static int sizeOf()
Get size of object.
Definition: JDAQKeyHit.hh:108
ClassDef(JDAQEvent, 4)
const_reverse_iterator< T > rbegin() const
Get reverse begin of data.
Interface for binary input.
const_reverse_iterator()
Default constructor.
Definition: JDAQEvent.hh:103
static int sizeOf()
Get size of object.
const_reverse_iterator< T > rend() const
Get reverse end of data.
const_iterator(const typename std::vector< T >::const_iterator &i)
Copy constructor.
Definition: JDAQEvent.hh:86
friend JReader & operator>>(JReader &in, JDAQEvent &event)
Read DAQ event from input.
Definition: JDAQEvent.hh:260
void push_back(const JDAQTriggeredHit &hit)
Add hit.
Definition: JDAQEvent.hh:217
void push_back(const JDAQKeyHit &hit)
Add hit.
Definition: JDAQEvent.hh:206
static int sizeOf()
Get size of object.
bool operator!=(const JDAQChronometer &first, const JDAQChronometer &second)
Not-equal operator for DAQ chronometers.
std::vector< JDAQSnapshotHit > snapshotHits
Definition: JDAQEvent.hh:318
bool & getDAQLongprint()
Get DAQ print option.
Definition: JDAQPrint.hh:15
JDAQEvent(const JDAQChronometer &chronometer, const JDAQTriggerMask &mask=JDAQTriggerMask())
Constructor.
Definition: JDAQEvent.hh:58
std::ostream & operator<<(std::ostream &out, const JDAQChronometer &chronometer)
Print DAQ chronometer.
void clear()
Clear event.
Definition: JDAQEvent.hh:194
STD extensions for binary I/O.
const_reverse_iterator(const typename std::vector< T >::const_reverse_iterator &i)
Copy constructor.
Definition: JDAQEvent.hh:113
static int sizeOf()
Get size of object.