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