Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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#include "JLang/JException.hh"
13#include "Jeep/JStatus.hh"
14
15/**
16 * \author mdejong
17 */
18
19namespace JTRIGGER {}
20namespace JPP { using namespace JTRIGGER; }
21
22namespace JTRIGGER {
23
26 using KM3NETDAQ::NUMBER_OF_PMTS;
27
30 using JEEP::JStatus;
31
32 /**
33 * Maximal frame size.
34 */
35 static int MAXIMAL_FRAME_SIZE = std::numeric_limits<int>::max();
36
37
38 /**
39 * Auxiliary class to perform check-sum on raw data.
40 */
41 struct JChecksum {
42 /**
43 * Error types.
44 */
46 EPMT_t = 1, //!< PMT number error
47 ETDC_t, //!< TDC value error
48 TIME_t, //!< Time order error
49 EUDP_t, //!< UDP packet error
50 SIZE_t //!< size error
51 };
52
53
54 /**
55 * Error.
56 */
57 struct error {
58 /**
59 * Default constructor.
60 */
62 pos (-1),
63 type(-1)
64 {}
65
66
67 /**
68 * Constructor.
69 *
70 * \param pos index in frame
71 * \param type error type
72 */
73 error(const int pos,
74 const int type) :
75 pos (pos),
76 type(type)
77 {}
78
79
80 int pos; //!< index in frame
81 int type; //!< error type
82 };
83
84
85 /**
86 * Auxiliary data structure for result of checksum.
87 */
88 struct result_type :
89 public std::vector<error>
90 {
91 /**
92 * Type conversion operator.
93 *
94 * \return true if okay; else false
95 */
96 operator bool() const
97 {
98 return this->empty();
99 }
100
101 /**
102 * Check for errors with given error mask.
103 *
104 * \param mask error mask
105 * \return true if error present; else false
106 */
107 bool has(const JStatus& mask) const
108 {
109 for (const_iterator i = this->begin(); i != this->end(); ++i) {
110 if (mask.has(i->type)) {
111 return true;
112 }
113 }
114
115 return false;
116 }
117 };
118
119 typedef result_type::const_iterator const_iterator;
120 typedef result_type::const_reverse_iterator const_reverse_iterator;
121
122
123 /**
124 * Default constructor.
125 */
127 {
128 t0.resize(NUMBER_OF_PMTS, 0);
129 }
130
131
132 /**
133 * Check sum.
134 *
135 * The following checks are made:
136 * -# UDP packet assembly is complete;
137 * -# PMT number greater or equals zero and less than NUMBER_OF_PMTS;
138 * -# TDC value less than frame time (with 5% margin);
139 * -# TDC values from same PMT are monotonously increasing;
140 *
141 * \param frame DAQ frame
142 * \return list of errors; empty if all okay
143 */
144 const result_type& operator()(const JDAQSuperFrame& frame) const
145 {
146 using namespace std;
147 using namespace KM3NETDAQ;
148
149 const JDAQHit::JTDC_t Tmax = (JDAQHit::JTDC_t) (getTimeSinceRTS(frame.getFrameIndex()) + 1.05 * getFrameTime());
150
151 buffer.clear();
152
153 for (vector<JDAQHit::JTDC_t>::iterator i = t0.begin(); i != t0.end(); ++i) {
154 *i = 0;
155 }
156
157 if (frame.size() > MAXIMAL_FRAME_SIZE) {
158 buffer.push_back(error(-1, SIZE_t));
159 }
160
161 if (!frame.testDAQStatus()) {
162 buffer.push_back(error(-1, EUDP_t));
163 }
164
165 for (JDAQSuperFrame::const_iterator hit = frame.begin(); hit != frame.end(); ++hit) {
166
167 const JDAQHit::JTDC_t pmt = hit->getPMT();
168 const JDAQHit::JTDC_t tdc = hit->getT();
169
170 if (pmt < NUMBER_OF_PMTS) {
171
172 if (tdc < t0[pmt]) {
173 buffer.push_back(error(distance(frame.begin(), hit), TIME_t));
174 }
175
176 if (tdc > Tmax) {
177 buffer.push_back(error(distance(frame.begin(), hit), ETDC_t));
178 }
179
180 t0[pmt] = tdc;
181
182 } else {
183
184 buffer.push_back(error(distance(frame.begin(), hit), EPMT_t));
185 }
186 }
187
188 return buffer;
189 }
190
191 private:
194 };
195
196
197 /**
198 * Function object to perform check-sum of raw data.
199 */
200 static const JChecksum checksum;
201}
202
203#endif
KM3NeT DAQ constants, bit handling, etc.
Exceptions.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Exception for accessing an index in a collection that is outside of its range.
Exception for accessing a value in a collection that is outside of its range.
int getFrameIndex() const
Get frame index.
bool testDAQStatus() const
Test DAQ status of packets.
const_iterator end() const
Definition JDAQFrame.hh:166
const_iterator begin() const
Definition JDAQFrame.hh:165
Hit data structure.
Definition JDAQHit.hh:35
unsigned int JTDC_t
leading edge [ns]
Definition JDAQHit.hh:39
Data frame of one optical module.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for triggering.
static const JChecksum checksum
Function object to perform check-sum of raw data.
Definition JChecksum.hh:200
static int MAXIMAL_FRAME_SIZE
Maximal frame size.
Definition JChecksum.hh:35
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
double getTimeSinceRTS(const int frame_index)
Get time in ns since last RTS for a given frame index.
Definition JDAQClock.hh:263
Auxiliary class for handling status.
Definition JStatus.hh:39
bool has(const int bit) const
Test PMT status.
Definition JStatus.hh:120
int pos
index in frame
Definition JChecksum.hh:80
error()
Default constructor.
Definition JChecksum.hh:61
error(const int pos, const int type)
Constructor.
Definition JChecksum.hh:73
Auxiliary data structure for result of checksum.
Definition JChecksum.hh:90
bool has(const JStatus &mask) const
Check for errors with given error mask.
Definition JChecksum.hh:107
Auxiliary class to perform check-sum on raw data.
Definition JChecksum.hh:41
result_type buffer
Definition JChecksum.hh:193
error_types
Error types.
Definition JChecksum.hh:45
@ ETDC_t
TDC value error.
Definition JChecksum.hh:47
@ SIZE_t
size error
Definition JChecksum.hh:50
@ EUDP_t
UDP packet error.
Definition JChecksum.hh:49
@ EPMT_t
PMT number error.
Definition JChecksum.hh:46
@ TIME_t
Time order error.
Definition JChecksum.hh:48
std::vector< JDAQHit::JTDC_t > t0
Definition JChecksum.hh:192
result_type::const_iterator const_iterator
Definition JChecksum.hh:119
result_type::const_reverse_iterator const_reverse_iterator
Definition JChecksum.hh:120
const result_type & operator()(const JDAQSuperFrame &frame) const
Check sum.
Definition JChecksum.hh:144
JChecksum()
Default constructor.
Definition JChecksum.hh:126