Jpp - 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  /**
31  * Auxiliary class to perform check-sum on raw data.
32  */
33  struct JChecksum {
34  /**
35  * Error types.
36  */
37  enum error_types {
38  EPMT_t = 1, //!< PMT number error
39  ETDC_t, //!< TDC value error
40  TIME_t, //!< Time order error
41  EUDP_t //!< UDP packet error
42  };
43 
44 
45  /**
46  * Error.
47  */
48  struct error {
49  /**
50  * Default constructor.
51  */
52  error() :
53  pos (-1),
54  type(-1)
55  {}
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param pos index in frame
62  * \param type error type
63  */
64  error(const int pos,
65  const int type) :
66  pos (pos),
67  type(type)
68  {}
69 
70 
71  int pos; //!< index in frame
72  int type; //!< error type
73  };
74 
75 
77  typedef result_type::const_iterator const_iterator;
78  typedef result_type::const_reverse_iterator const_reverse_iterator;
79 
80 
81  /**
82  * Default constructor.
83  */
85  {
86  t0.resize(NUMBER_OF_PMTS, 0);
87  }
88 
89 
90  /**
91  * Check sum.
92  *
93  * The following checks are made:
94  * -# UDP packet assembly is complete;
95  * -# PMT number greater or equals zero and less than NUMBER_OF_PMTS;
96  * -# TDC value less than frame time (with 5% margin);
97  * -# TDC values from same PMT are monotonously increasing;
98  *
99  * \param frame DAQ frame
100  * \return list of errors; empty if all okay
101  */
102  const result_type& get(const JDAQSuperFrame& frame) const
103  {
104  using namespace std;
105  using namespace KM3NETDAQ;
106 
107  const JDAQHit::JTDC_t Tmax = (JDAQHit::JTDC_t) (getTimeSinceRTS(frame.getFrameIndex()) + 1.05 * getFrameTime());
108 
109  buffer.clear();
110 
111  for (vector<JDAQHit::JTDC_t>::iterator i = t0.begin(); i != t0.end(); ++i) {
112  *i = 0;
113  }
114 
115  if (!frame.testDAQStatus()) {
116  buffer.push_back(error(-1, EUDP_t));
117  }
118 
119  for (JDAQSuperFrame::const_iterator hit = frame.begin(); hit != frame.end(); ++hit) {
120 
121  const JDAQHit::JTDC_t pmt = hit->getPMT();
122  const JDAQHit::JTDC_t tdc = hit->getT();
123 
124  if (pmt < NUMBER_OF_PMTS) {
125 
126  if (tdc < t0[pmt]) {
127  buffer.push_back(error(distance(frame.begin(), hit), TIME_t));
128  }
129 
130  if (tdc > Tmax) {
131  buffer.push_back(error(distance(frame.begin(), hit), ETDC_t));
132  }
133 
134  t0[pmt] = tdc;
135 
136  } else {
137 
138  buffer.push_back(error(distance(frame.begin(), hit), EPMT_t));
139  }
140  }
141 
142  return buffer;
143  }
144 
145 
146  /**
147  * Check sum.
148  *
149  * \param frame DAQ frame
150  * \return true if okay; else false
151  */
152  bool operator()(const JDAQSuperFrame& frame) const
153  {
154  return get(frame).empty();
155  }
156 
157 
158  private:
161  };
162 
163 
164  /**
165  * Function object to perform check-sum of raw data.
166  */
167  static const JChecksum checksum;
168 }
169 
170 #endif
std::vector< JDAQHit::JTDC_t > t0
Definition: JChecksum.hh:159
error()
Default constructor.
Definition: JChecksum.hh:52
int pos
index in frame
Definition: JChecksum.hh:71
JChecksum()
Default constructor.
Definition: JChecksum.hh:84
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:77
error_types
Error types.
Definition: JChecksum.hh:37
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:167
Auxiliary class to perform check-sum on raw data.
Definition: JChecksum.hh:33
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:64
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:152
TDC value error.
Definition: JChecksum.hh:39
Time order error.
Definition: JChecksum.hh:40
std::vector< error > result_type
Definition: JChecksum.hh:76
PMT number error.
Definition: JChecksum.hh:38
result_type::const_reverse_iterator const_reverse_iterator
Definition: JChecksum.hh:78
result_type buffer
Definition: JChecksum.hh:160
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:41
Data frame of one optical module.