Jpp  18.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JChecksum.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JCHECKSUM__
2 #define __JTRIGGER__JCHECKSUM__
3 
4 #include <vector>
5 #include <limits>
6 
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JTRIGGER {}
18 namespace JPP { using namespace JTRIGGER; }
19 
20 namespace JTRIGGER {
21 
22  using KM3NETDAQ::JDAQHit;
25 
28 
29  /**
30  * Maximal frame size.
31  */
32  static int MAXIMAL_FRAME_SIZE = std::numeric_limits<int>::max();
33 
34 
35  /**
36  * Auxiliary class to perform check-sum on raw data.
37  */
38  struct JChecksum {
39  /**
40  * Error types.
41  */
42  enum error_types {
43  EPMT_t = 1, //!< PMT number error
44  ETDC_t, //!< TDC value error
45  TIME_t, //!< Time order error
46  EUDP_t, //!< UDP packet error
47  SIZE_t //!< size error
48  };
49 
50 
51  /**
52  * Error.
53  */
54  struct error {
55  /**
56  * Default constructor.
57  */
58  error() :
59  pos (-1),
60  type(-1)
61  {}
62 
63 
64  /**
65  * Constructor.
66  *
67  * \param pos index in frame
68  * \param type error type
69  */
70  error(const int pos,
71  const int type) :
72  pos (pos),
73  type(type)
74  {}
75 
76 
77  int pos; //!< index in frame
78  int type; //!< error type
79  };
80 
81 
83  typedef result_type::const_iterator const_iterator;
84  typedef result_type::const_reverse_iterator const_reverse_iterator;
85 
86 
87  /**
88  * Default constructor.
89  */
91  {
92  t0.resize(NUMBER_OF_PMTS, 0);
93  }
94 
95 
96  /**
97  * Check sum.
98  *
99  * The following checks are made:
100  * -# UDP packet assembly is complete;
101  * -# PMT number greater or equals zero and less than NUMBER_OF_PMTS;
102  * -# TDC value less than frame time (with 5% margin);
103  * -# TDC values from same PMT are monotonously increasing;
104  *
105  * \param frame DAQ frame
106  * \return list of errors; empty if all okay
107  */
108  const result_type& get(const JDAQSuperFrame& frame) const
109  {
110  using namespace std;
111  using namespace KM3NETDAQ;
112 
113  const JDAQHit::JTDC_t Tmax = (JDAQHit::JTDC_t) (getTimeSinceRTS(frame.getFrameIndex()) + 1.05 * getFrameTime());
114 
115  buffer.clear();
116 
117  for (vector<JDAQHit::JTDC_t>::iterator i = t0.begin(); i != t0.end(); ++i) {
118  *i = 0;
119  }
120 
121  if (frame.size() > MAXIMAL_FRAME_SIZE) {
122  buffer.push_back(error(-1, SIZE_t));
123  }
124 
125  if (!frame.testDAQStatus()) {
126  buffer.push_back(error(-1, EUDP_t));
127  }
128 
129  for (JDAQSuperFrame::const_iterator hit = frame.begin(); hit != frame.end(); ++hit) {
130 
131  const JDAQHit::JTDC_t pmt = hit->getPMT();
132  const JDAQHit::JTDC_t tdc = hit->getT();
133 
134  if (pmt < NUMBER_OF_PMTS) {
135 
136  if (tdc < t0[pmt]) {
137  buffer.push_back(error(distance(frame.begin(), hit), TIME_t));
138  }
139 
140  if (tdc > Tmax) {
141  buffer.push_back(error(distance(frame.begin(), hit), ETDC_t));
142  }
143 
144  t0[pmt] = tdc;
145 
146  } else {
147 
148  buffer.push_back(error(distance(frame.begin(), hit), EPMT_t));
149  }
150  }
151 
152  return buffer;
153  }
154 
155 
156  /**
157  * Check sum.
158  *
159  * \param frame DAQ frame
160  * \return true if okay; else false
161  */
162  bool operator()(const JDAQSuperFrame& frame) const
163  {
164  return get(frame).empty();
165  }
166 
167  private:
170  };
171 
172 
173  /**
174  * Function object to perform check-sum of raw data.
175  */
176  static const JChecksum checksum;
177 }
178 
179 #endif
std::vector< JDAQHit::JTDC_t > t0
Definition: JChecksum.hh:168
error()
Default constructor.
Definition: JChecksum.hh:58
int pos
index in frame
Definition: JChecksum.hh:77
JChecksum()
Default constructor.
Definition: JChecksum.hh:90
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
result_type::const_iterator const_iterator
Definition: JChecksum.hh:83
error_types
Error types.
Definition: JChecksum.hh:42
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:39
static const JChecksum checksum
Function object to perform check-sum of raw data.
Definition: JChecksum.hh:176
static int MAXIMAL_FRAME_SIZE
Maximal frame size.
Definition: JChecksum.hh:32
Auxiliary class to perform check-sum on raw data.
Definition: JChecksum.hh:38
Hit data structure.
Definition: JDAQHit.hh:34
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
error(const int pos, const int type)
Constructor.
Definition: JChecksum.hh:70
double getTimeSinceRTS(const int frame_index)
Get time in ns since last RTS for a given frame index.
Definition: JDAQClock.hh:263
bool operator()(const JDAQSuperFrame &frame) const
Check sum.
Definition: JChecksum.hh:162
TDC value error.
Definition: JChecksum.hh:44
Time order error.
Definition: JChecksum.hh:45
std::vector< error > result_type
Definition: JChecksum.hh:82
PMT number error.
Definition: JChecksum.hh:43
result_type::const_reverse_iterator const_reverse_iterator
Definition: JChecksum.hh:84
result_type buffer
Definition: JChecksum.hh:169
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:90
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
UDP packet error.
Definition: JChecksum.hh:46
Data frame of one optical module.