Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQFrameStatus.hh
Go to the documentation of this file.
1 #ifndef __JDAQFRAMESTATUS__
2 #define __JDAQFRAMESTATUS__
3 
4 #include "JIO/JSerialisable.hh"
5 #include "JDAQ/JDAQ.hh"
6 #include "JDAQ/JDAQException.hh"
7 #include "JDAQ/JDAQRoot.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace KM3NETDAQ {
15 
16  using JIO::JReader;
17  using JIO::JWriter;
18 
19 
20  /**
21  * DAQ frame status.
22  */
24  public:
25  /**
26  * Default constructor.
27  */
29  daq (0),
30  status (0),
31  fifo (0),
32  status_3(0),
33  status_4(0)
34  {}
35 
36 
37  /**
38  * Constructor.
39  *
40  * \param __daq DAQ status
41  * \param __status TDC status
42  * \param __fifo FIFO status
43  * \param __status_3 spare
44  * \param __status_4 spare
45  */
46  JDAQFrameStatus(const int __daq,
47  const int __status,
48  const int __fifo,
49  const int __status_3 = 0,
50  const int __status_4 = 0) :
51  daq (__daq),
52  status (__status),
53  fifo (__fifo),
54  status_3(__status_3),
55  status_4(__status_4)
56  {}
57 
58 
59  /**
60  * Get reference to unique instance of this class object.
61  *
62  * This instance has default values which correspond to a valid DAQ frame status.
63  *
64  * \return reference to this class object
65  */
66  static const JDAQFrameStatus& getInstance()
67  {
71 
72  return status;
73  }
74 
75 
76  /**
77  * Get DAQ frame status.
78  *
79  * \return DAQ frame status
80  */
82  {
83  return static_cast<const JDAQFrameStatus&>(*this);
84  }
85 
86 
87  /**
88  * Set DAQ frame status.
89  *
90  * \param status DAQ frame status
91  */
93  {
94  static_cast<JDAQFrameStatus&>(*this) = status;
95  }
96 
97 
98  /**
99  * Get DAQ status.
100  *
101  * \return DAQ status
102  */
103  int getDAQStatus() const
104  {
105  return this->daq;
106  }
107 
108 
109  /**
110  * Get TDC and White Rabbit status.
111  *
112  * \return status
113  */
114  int getStatus() const
115  {
116  return this->status;
117  }
118 
119 
120  /**
121  * Get FIFO status.
122  *
123  * \return FIFO status
124  */
125  int getFIFOStatus() const
126  {
127  return this->fifo;
128  }
129 
130 
131  /**
132  * Test DAQ status of packets.
133  *
134  * \return true if okay; else false
135  */
136  bool testDAQStatus() const
137  {
139  }
140 
141 
142  /**
143  * Test TDC and White Rabbit status.
144  *
145  * \return true if okay; else false
146  */
147  bool testStatus() const
148  {
149  return testWhiteRabbitStatus() && testTDCStatus();
150  }
151 
152 
153  /**
154  * Get number of received UDP packets.
155  *
156  * \return UDP received packets
157  */
159  {
160  return DAQ_UDP_RECEIVED_PACKETS.read(this->daq);
161  }
162 
163 
164  /**
165  * Get maximal sequence number of UDP packet.
166  *
167  * \return UDP sequence number
168  */
170  {
171  return DAQ_UDP_SEQUENCE_NUMBER.read(this->daq);
172  }
173 
174 
175  /**
176  * Test White Rabbit status.
177  *
178  * \return true if okay; else false
179  */
181  {
182  return DAQ_WHITE_RABBIT.has(this->status);
183  }
184 
185 
186  /**
187  * Test TDC status.
188  *
189  * \return true if okay; else false
190  */
191  bool testTDCStatus() const
192  {
193  return !testHighRateVeto();
194  }
195 
196 
197  /**
198  * Test high-rate veto status.
199  *
200  * \return true if one of the TDCs is high-rate vetoed; else false
201  */
202  bool testHighRateVeto() const
203  {
204  return DAQ_TDC.has(this->status);
205  }
206 
207 
208  /**
209  * Test high-rate veto status.
210  *
211  * \param tdc TDC
212  * \return true if TDC is high-rate vetoed; else false
213  */
214  bool testHighRateVeto(const int tdc) const
215  {
216  return JBit(tdc).has(this->status);
217  }
218 
219 
220  /**
221  * Count high-rate veto status.
222  *
223  * \return number of the TDCs with high-rate veto
224  */
225  int countHighRateVeto() const
226  {
227  int n = 0;
228 
229  if (testHighRateVeto()) {
230  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
231  if (JBit(pmt).has(this->status)) {
232  ++n;
233  }
234  }
235  }
236 
237  return n;
238  }
239 
240 
241  /**
242  * Test FIFO status.
243  *
244  * \return true if one of the TDCs has FIFO almost full; else false
245  */
246  bool testFIFOStatus() const
247  {
248  return DAQ_FIFO.has(this->fifo);
249  }
250 
251 
252  /**
253  * Test FIFO status.
254  *
255  * \param tdc TDC
256  * \return true if FIFO is almost full; else false
257  */
258  bool testFIFOStatus(const int tdc) const
259  {
260  return JBit(tdc).has(this->fifo);
261  }
262 
263 
264  /**
265  * Count FIFO status.
266  *
267  * \return number of the TDCs with FIFO almost full
268  */
269  int countFIFOStatus() const
270  {
271  int n = 0;
272 
273  if (testFIFOStatus()) {
274  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
275  if (JBit(pmt).has(this->fifo)) {
276  ++n;
277  }
278  }
279  }
280 
281  return n;
282  }
283 
284 
285  /**
286  * Get UDP trailer status.
287  *
288  * \return true if UDP trailer present; else false
289  */
290  bool hasUDPTrailer() const
291  {
292  return DAQ_UDP_TRAILER.has(this->fifo);
293  }
294 
295 
296  /**
297  * Set high-rate veto.
298  *
299  * \param tdc TDC
300  * \param value value
301  */
302  void setHighRateVeto(const int tdc, const bool value)
303  {
304  JBit(tdc).set(this->status, value);
305  }
306 
307 
308  /**
309  * Read DAQ frame status from input.
310  *
311  * \param in JReader
312  * \param status JDAQFrameStatus
313  * \return JReader
314  */
316  {
317  in >> status.daq;
318  in >> status.status;
319  in >> status.fifo;
320  in >> status.status_3;
321  in >> status.status_4;
322 
323  return in;
324  }
325 
326 
327  /**
328  * Write DAQ frame status to output.
329  *
330  * \param out JWriter
331  * \param status JDAQFrameStatus
332  * \return JWriter
333  */
334  friend inline JWriter& operator<<(JWriter& out, const JDAQFrameStatus& status)
335  {
336  out << status.daq;
337  out << status.status;
338  out << status.fifo;
339  out << status.status_3;
340  out << status.status_4;
341 
342  return out;
343  }
344 
345 
346  /**
347  * Get size of object.
348  *
349  * \return number of bytes
350  */
351  static int sizeOf()
352  {
353  return (sizeof(int) +
354  sizeof(int) +
355  sizeof(int) +
356  sizeof(int) +
357  sizeof(int));
358  }
359 
360 
362 
363  protected:
364  int daq; // DAQ status
365  int status; // TDC status
366  int fifo; // FIFO status
367  int status_3; // spare
368  int status_4; // spare
369  };
370 
371 
372  /**
373  * Equal operator for DAQ frame status.
374  *
375  * \param first frame status
376  * \param second frame status
377  * \result true if first frame status equal to second; else false
378  */
379  inline bool operator==(const JDAQFrameStatus& first,
380  const JDAQFrameStatus& second)
381  {
382  return (first.getDAQStatus() == second.getDAQStatus() &&
383  first.getStatus() == second.getStatus() &&
384  first.getFIFOStatus() == second.getFIFOStatus());
385  }
386 
387 
388  /**
389  * Not-equal operator for DAQ frame status.
390  *
391  * \param first frame status
392  * \param second frame status
393  * \result true if first frame status not equal to second; else false
394  */
395  inline bool operator!=(const JDAQFrameStatus& first,
396  const JDAQFrameStatus& second)
397  {
398  return !(first == second);
399  }
400 }
401 
402 #endif
static const JBits DAQ_UDP_RECEIVED_PACKETS(0, 15)
Mask of UDP received packets.
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
Interface for binary output.
bool testTDCStatus() const
Test TDC status.
int countFIFOStatus() const
Count FIFO status.
void set(int &mask) const
Set bit in given bit mask.
Definition: JDAQ.hh:77
int write(const int value) const
Write given value as bit mask.
Definition: JDAQ.hh:115
int read(const int mask) const
Read given bit mask as value.
Definition: JDAQ.hh:250
int getStatus() const
Get TDC and White Rabbit status.
static const JDAQFrameStatus & getInstance()
Get reference to unique instance of this class object.
bool hasUDPTrailer() const
Get UDP trailer status.
bool testWhiteRabbitStatus() const
Test White Rabbit status.
static int sizeOf()
Get size of object.
int write(const int value) const
Write given value as bit mask.
Definition: JDAQ.hh:238
static const JBits DAQ_FIFO(0, 30)
FIFO almost full bits.
int getUDPNumberOfReceivedPackets() const
Get number of received UDP packets.
bool testStatus() const
Test TDC and White Rabbit status.
bool testFIFOStatus(const int tdc) const
Test FIFO status.
bool has(const int mask) const
Test bit mask.
Definition: JDAQ.hh:262
int getUDPMaximalSequenceNumber() const
Get maximal sequence number of UDP packet.
int getDAQStatus() const
Get DAQ status.
ClassDefNV(JDAQFrameStatus, 1)
Interface for binary input.
static const JBit DAQ_UDP_TRAILER(31)
UDP trailer.
int getFIFOStatus() const
Get FIFO status.
bool has(const int mask) const
Test bit.
Definition: JDAQ.hh:139
bool testHighRateVeto() const
Test high-rate veto status.
bool testHighRateVeto(const int tdc) const
Test high-rate veto status.
void setHighRateVeto(const int tdc, const bool value)
Set high-rate veto.
Auxiliary data structure for single bit.
Definition: JDAQ.hh:36
int countHighRateVeto() const
Count high-rate veto status.
void setDAQFrameStatus(const JDAQFrameStatus &status)
Set DAQ frame status.
static const JBit DAQ_WHITE_RABBIT(31)
White Rabbit status.
JDAQFrameStatus(const int __daq, const int __status, const int __fifo, const int __status_3=0, const int __status_4=0)
Constructor.
static const JBits DAQ_UDP_SEQUENCE_NUMBER(16, 31)
Mask of UDP sequence number.
JDAQFrameStatus()
Default constructor.
KM3NeT DAQ constants, bit handling, etc.
bool operator!=(const JDAQChronometer &first, const JDAQChronometer &second)
Not-equal operator for DAQ chronometers.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
bool testDAQStatus() const
Test DAQ status of packets.
friend JWriter & operator<<(JWriter &out, const JDAQFrameStatus &status)
Write DAQ frame status to output.
friend JReader & operator>>(JReader &in, JDAQFrameStatus &status)
Read DAQ frame status from input.
const JDAQFrameStatus & getDAQFrameStatus() const
Get DAQ frame status.
static const JBits DAQ_TDC(0, 30)
TDC high-rate veto status.
bool testFIFOStatus() const
Test FIFO status.