Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JDAQ.hh
Go to the documentation of this file.
1#ifndef __JDAQ__
2#define __JDAQ__
3
5
6
7/**
8 * \file
9 *
10 * KM3NeT DAQ constants, bit handling, etc.
11 * \author mdejong
12 */
13
14
15/**
16 * %KM3NeT DAQ data structures and auxiliaries.
17 */
18namespace KM3NETDAQ {
19
20#define KM3NET 1
21#define ANTARES 2
22
23#if NAMESPACE == ANTARES
24 static const int NUMBER_OF_PMTS = 3; //!< Total number of PMTs in module
25#else
26 static const int NUMBER_OF_PMTS = 31; //!< Total number of PMTs in module
27#endif
28
29#undef KM3NET
30#undef ANTARES
31
32
33 /**
34 * Auxiliary data structure for single bit.
35 */
36 struct JBit {
37 /**
38 * Default constructor.
39 */
40 JBit() :
41 bit(0)
42 {}
43
44
45 /**
46 * Constructor.
47 *
48 * \param __bit bit [0, 31]
49 */
50 JBit(int __bit) :
51 bit(__bit)
52 {
53 if (bit < 0 || bit > 31) {
54 throw JDAQException("JBit: illegal bit range.");
55 }
56 }
57
58
59 /**
60 * Get bit mask.
61 *
62 * In the returned mask, the single bit at <tt>bit</tt> set to 1.
63 *
64 * \return bit mask
65 */
66 int get() const
67 {
68 return 1 << bit;
69 }
70
71
72 /**
73 * Set bit in given bit mask.
74 *
75 * \param mask bit mask (I/O)
76 */
77 void set(int& mask) const
78 {
79 mask |= get();
80 }
81
82
83 /**
84 * Unset bit in given bit mask.
85 *
86 * \param mask bit mask (I/O)
87 */
88 void unset(int& mask) const
89 {
90 mask &= ~get();
91 }
92
93
94 /**
95 * Set bit in given bit mask.
96 *
97 * \param mask bit mask (I/0)
98 * \param value bit status
99 */
100 void set(int& mask, const bool value) const
101 {
102 if (value)
103 set (mask);
104 else
105 unset(mask);
106 }
107
108
109 /**
110 * Write given value as bit mask.
111 *
112 * \param value value
113 * \return bit mask
114 */
115 int write(const int value) const
116 {
117 return (value << bit) & get();
118 }
119
120
121 /**
122 * Read given bit mask as value.
123 *
124 * \param mask bit mask
125 * \return value
126 */
127 int read(const int mask) const
128 {
129 return (mask & get()) >> bit;
130 }
131
132
133 /**
134 * Test bit.
135 *
136 * \param mask bit mask
137 * \return true if bit set; else false
138 */
139 bool has(const int mask) const
140 {
141 return (mask & get()) != 0;
142 }
143
144
145 int bit; //!< bit
146 };
147
148
149 /**
150 * Auxiliary data structure for range of bits.
151 */
152 struct JBits {
153 /**
154 * Default constructor.
155 */
157 lsb(0),
158 msb(0)
159 {}
160
161
162 /**
163 * Constructor.
164 *
165 * \param __lsb least significant bit [0, 31]
166 * \param __msb most significant bit [lsb, 31]
167 */
168 JBits(int __lsb, int __msb) :
169 lsb(__lsb),
170 msb(__msb)
171 {
172 if (lsb < 0 || lsb > 31 ||
174 throw JDAQException("JBits: illegal bit range.");
175 }
176 }
177
178
179 /**
180 * Get bit mask.
181 *
182 * In the returned mask, the bits from <tt>lsb</tt> (included) to <tt>msb</tt> (included) are set to 1.
183 *
184 * \return bit mask
185 */
186 int get() const
187 {
188 static const unsigned int mask[] = { 0x00000001,
189 0x00000003,
190 0x00000007,
191 0x0000000F,
192
193 0x0000001F,
194 0x0000003F,
195 0x0000007F,
196 0x000000FF,
197
198 0x000001FF,
199 0x000003FF,
200 0x000007FF,
201 0x00000FFF,
202
203 0x00001FFF,
204 0x00003FFF,
205 0x00007FFF,
206 0x0000FFFF,
207
208 0x0001FFFF,
209 0x0003FFFF,
210 0x0007FFFF,
211 0x000FFFFF,
212
213 0x001FFFFF,
214 0x003FFFFF,
215 0x007FFFFF,
216 0x00FFFFFF,
217
218 0x01FFFFFF,
219 0x03FFFFFF,
220 0x07FFFFFF,
221 0x0FFFFFFF,
222
223 0x1FFFFFFF,
224 0x3FFFFFFF,
225 0x7FFFFFFF,
226 0xFFFFFFFF };
227
228 return (int) (mask[msb-lsb] << lsb);
229 }
230
231
232 /**
233 * Write given value as bit mask.
234 *
235 * \param value value
236 * \return bit mask
237 */
238 int write(const int value) const
239 {
240 return (value << lsb) & get();
241 }
242
243
244 /**
245 * Read given bit mask as value.
246 *
247 * \param mask bit mask
248 * \return value
249 */
250 int read(const int mask) const
251 {
252 return (mask & get()) >> lsb;
253 }
254
255
256 /**
257 * Test bit mask.
258 *
259 * \param mask bit mask
260 * \return true if at least one of the bits is set; else false
261 */
262 bool has(const int mask) const
263 {
264 return (get() & mask) != 0;
265 }
266
267
268 int lsb; //!< least significant bit
269 int msb; //!< most significant bit
270 };
271
272
273 static const JBit DAQ_WHITE_RABBIT (31); //!< White Rabbit status
274 static const JBits DAQ_TDC ( 0, 30); //!< TDC high-rate veto status
275 static const JBits DAQ_FIFO ( 0, 30); //!< FIFO almost full bits
276
277 static const JBit DAQ_UDP_TRAILER (31); //!< UDP trailer
278 static const JBits DAQ_UDP_RECEIVED_PACKETS( 0, 15); //!< Mask of UDP received packets
279 static const JBits DAQ_UDP_SEQUENCE_NUMBER (16, 31); //!< Mask of UDP sequence number
280}
281
282#endif
General exception.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
static const JBits DAQ_UDP_RECEIVED_PACKETS(0, 15)
Mask of UDP received packets.
static const JBits DAQ_TDC(0, 30)
TDC high-rate veto status.
static const JBits DAQ_UDP_SEQUENCE_NUMBER(16, 31)
Mask of UDP sequence number.
static const JBits DAQ_FIFO(0, 30)
FIFO almost full bits.
static const JBit DAQ_WHITE_RABBIT(31)
White Rabbit status.
static const JBit DAQ_UDP_TRAILER(31)
UDP trailer.
Auxiliary data structure for single bit.
Definition JDAQ.hh:36
void unset(int &mask) const
Unset bit in given bit mask.
Definition JDAQ.hh:88
void set(int &mask, const bool value) const
Set bit in given bit mask.
Definition JDAQ.hh:100
int write(const int value) const
Write given value as bit mask.
Definition JDAQ.hh:115
int bit
bit
Definition JDAQ.hh:145
JBit()
Default constructor.
Definition JDAQ.hh:40
JBit(int __bit)
Constructor.
Definition JDAQ.hh:50
int read(const int mask) const
Read given bit mask as value.
Definition JDAQ.hh:127
void set(int &mask) const
Set bit in given bit mask.
Definition JDAQ.hh:77
bool has(const int mask) const
Test bit.
Definition JDAQ.hh:139
int get() const
Get bit mask.
Definition JDAQ.hh:66
Auxiliary data structure for range of bits.
Definition JDAQ.hh:152
int write(const int value) const
Write given value as bit mask.
Definition JDAQ.hh:238
int get() const
Get bit mask.
Definition JDAQ.hh:186
int lsb
least significant bit
Definition JDAQ.hh:268
int read(const int mask) const
Read given bit mask as value.
Definition JDAQ.hh:250
JBits()
Default constructor.
Definition JDAQ.hh:156
bool has(const int mask) const
Test bit mask.
Definition JDAQ.hh:262
JBits(int __lsb, int __msb)
Constructor.
Definition JDAQ.hh:168
int msb
most significant bit
Definition JDAQ.hh:269