ATLAS Offline Software
Loading...
Searching...
No Matches
ZdcSubBlock.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
17
18
20
21
22// Static constant definitions
23
30
47
57
62
65
78
82
83// Clear all data
84
86{
87 m_header = 0;
88 m_trailer = 0;
91 m_bitword = 0;
92 m_currentBit = 0;
93 m_unpackerFlag = false;
94 m_currentPinBit.assign(s_maxPins, 0);
95 m_oddParity.assign(s_maxPins, 1);
96 m_dataWords = 0;
97 m_data.clear();
98}
99
100// Store header data
101
102void ZdcSubBlock::setHeader(const int wordId, const int version,
103 const int format, const int seqno,
104 const int crate, const int module,
105 const int slices2, const int slices1)
106{
107 uint32_t word = 0;
108 word |= (wordId & s_wordIdMask) << s_wordIdBit;
109 word |= (version & s_versionMask) << s_versionBit;
110 word |= (format & s_formatMask) << s_formatBit;
111 word |= (seqno & s_seqnoMask) << s_seqnoBit;
112 word |= (crate & s_crateMask) << s_crateBit;
113 word |= (module & s_moduleMask) << s_moduleBit;
114 word |= (slices2 & s_slices2Mask) << s_slices2Bit;
115 word |= (slices1 & s_slices1Mask) << s_slices1Bit;
116 m_header = word;
117}
118
119// Input complete packed sub-block from ROD vector
120
124{
125 m_dataWords = 0;
126 m_unpackerFlag = true;
129 for (; pos != pose; ++pos) {
130 const uint32_t word = *pos;
131 const SubBlockWordType type = wordType(word);
132 if (type == HEADER) {
133 if (m_header) return pos;
134 m_header = word;
135 }
136 else if (type == STATUS) m_trailer = word;
137 else {
138 m_data.push_back(word);
139 ++m_dataWords;
140 }
141 }
142 return pose;
143}
144
145// Output complete packed sub-block to ROD vector
146
149{
150 theROD->push_back(m_header);
151 std::vector<uint32_t>::const_iterator pos;
152 for (pos = m_data.begin(); pos != m_data.end(); ++pos) {
153 theROD->push_back(*pos);
154 }
155 if (m_trailer) theROD->push_back(m_trailer);
156}
157
158// Store error status trailer
159
161 const bool glinkTimeout, const bool glinkDown, const bool upstreamError,
162 const bool daqOverflow, const bool bcnMismatch,
163 const bool glinkProtocol, const bool glinkParity)
164{
165 uint32_t word = 0;
168 word |= glinkDown << s_glinkDownBit;
170 word |= daqOverflow << s_daqOverflowBit;
171 word |= bcnMismatch << s_bcnMismatchBit;
173 word |= glinkParity << s_glinkParityBit;
174 if (word) {
175 word |= (wordId() & s_wordIdMask) << s_wordIdBit;
176 word |= (s_statusVal & s_statusMask) << s_statusBit;
177 word |= (seqno() & s_seqnoMask) << s_seqnoBit;
178 word |= (crate() & s_crateMask) << s_crateBit;
179 word |= (module() & s_moduleMask) << s_moduleBit;
180 }
181 m_trailer = word;
182}
183
184// Set DAQ FIFO Overflow bit in Sub-status word
185
187{
188 if (bit) {
189 if (m_trailer) m_trailer |= (1 << s_daqOverflowBit);
190 else setStatus(0, false, false, false, true, false, false, false);
191 }
192}
193
194// Set G-Link Parity bit in Sub-status word
195
197{
198 if (bit) {
199 if (m_trailer) m_trailer |= (1 << s_glinkParityBit);
200 else setStatus(0, false, false, false, false, false, false, true);
201 }
202}
203
204// Return the unpacking error message for printing
205
207{
208 std::string msg;
209 switch (m_unpackError) {
210 case UNPACK_NONE:
211 msg = "No error";
212 break;
213 case UNPACK_VERSION:
214 msg = "Unsupported Data Version";
215 break;
216 case UNPACK_FORMAT:
217 msg = "Unsupported Data Format";
218 break;
220 msg = "Unsupported Compression Version";
221 break;
223 msg = "Unsupported Number of Slices for Compression Version";
224 break;
226 msg = "Premature End of Sub-block Data";
227 break;
228 case UNPACK_SOURCE_ID:
229 msg = "Invalid Source ID in Sub-block Data";
230 break;
231 case UNPACK_WORD_ID:
232 msg = "Invalid Word ID in Sub-block Data";
233 break;
234 default:
235 msg = "Unknown Error Code";
236 break;
237 }
238 return msg;
239}
240
241// Packing utilities
242
243// Return the minimum number of bits needed for given data
244
245int ZdcSubBlock::minBits(const uint32_t datum)
246{
247 const int maxBits = 32;
248 int nbits = maxBits;
249 for (int i = 0; i < maxBits; ++i) {
250 if ( !(datum >> i)) {
251 nbits = i;
252 break;
253 }
254 }
255 return nbits;
256}
257
258// Return the parity bit for given data
259
260int ZdcSubBlock::parityBit(const int init, const uint32_t datum,
261 const int nbits)
262{
263 // set init to 0/1 for even/odd parity
264 int parity = init;
265 for (int bit = 0; bit < nbits; ++bit) parity ^= (datum >> bit) & 0x1;
266 return parity;
267}
268
269// Pack given data into given number of bits
270
271void ZdcSubBlock::packer(const uint32_t datum, const int nbits)
272{
273 if (nbits > 0) {
274 uint32_t mask = 0x1;
275 for (int i = 1; i < nbits; ++i) mask |= (mask << 1);
276 m_bitword |= (datum & mask) << m_currentBit;
277 m_currentBit += nbits;
278 if (m_currentBit >= m_maxBits) {
280 m_data.push_back(m_bitword);
281 ++m_dataWords;
282 const int bitsLeft = m_currentBit - m_maxBits;
283 if (bitsLeft > 0) {
284 m_bitword = (datum & mask) >> (nbits - bitsLeft);
285 m_currentBit = bitsLeft;
286 } else {
287 m_bitword = 0;
288 m_currentBit = 0;
289 }
290 }
291 }
292}
293
294// Flush the current data word padded with zeros
295
297{
298 if (m_currentBit > 0) {
300 m_data.push_back(m_bitword);
301 ++m_dataWords;
302 m_bitword = 0;
303 m_currentBit = 0;
304 }
305}
306
307// Unpack given number of bits of data
308
309uint32_t ZdcSubBlock::unpacker(const int nbits)
310{
311 uint32_t word = 0;
312 if (nbits > 0) {
313 if (m_dataPos == m_dataPosEnd) {
314 m_unpackerFlag = false;
315 return 0;
316 }
317 int nbitsDone = nbits;
318 if (nbitsDone > m_maxBits - m_currentBit) {
319 nbitsDone = m_maxBits - m_currentBit;
320 }
321 uint32_t mask = 0x1;
322 for (int i = 1; i < nbitsDone; ++i) mask |= (mask << 1);
323 word = (m_bitword >> m_currentBit) & mask;
324 m_currentBit += nbits;
325 if (m_currentBit >= m_maxBits) {
326 m_bitword = 0;
327 if (m_dataPos != m_dataPosEnd) {
328 ++m_dataPos;
329 if (m_dataPos != m_dataPosEnd) {
331 }
332 }
333 m_currentBit = 0;
334 const int bitsLeft = nbits - nbitsDone;
335 if (bitsLeft > 0) {
336 if (m_dataPos == m_dataPosEnd) {
337 m_unpackerFlag = false;
338 return word;
339 }
340 mask = 0x1;
341 for (int i = 1; i < bitsLeft; ++i) mask |= (mask << 1);
342 word |= (m_bitword & mask) << nbitsDone;
343 m_currentBit = bitsLeft;
344 }
345 }
346 }
347 return word;
348}
349
350// Initialise unpacker
351
353{
354 m_bitword = 0;
355 m_currentBit = 0;
356 m_unpackerFlag = true;
357 m_dataPos = m_data.begin();
358 m_dataPosEnd = m_data.end();
360}
361
362// Pack given neutral data from given pin
363
364void ZdcSubBlock::packerNeutral(const int pin, const uint32_t datum,
365 const int nbits)
366{
367 if (pin >= 0 && pin < s_maxPins && nbits > 0) {
368 if (m_currentPinBit[pin] + nbits > m_dataWords) {
369 m_dataWords = m_currentPinBit[pin] + nbits;
371 }
372 for (int bit = 0; bit < nbits; ++bit) {
373 m_data[m_currentPinBit[pin] + bit] |= ((datum >> bit) & 0x1) << pin;
374 }
375 m_currentPinBit[pin] += nbits;
376 m_oddParity[pin] = parityBit(m_oddParity[pin], datum, nbits);
377 }
378}
379
380// Pack current G-Link parity bit for given pin
381
383{
384 if (pin >= 0 && pin < s_maxPins) {
385 packerNeutral(pin, m_oddParity[pin], 1);
386 m_oddParity[pin] = 1;
387 }
388}
389
390// Unpack given number of bits of neutral data for given pin
391
392uint32_t ZdcSubBlock::unpackerNeutral(const int pin, const int nbits)
393{
394 uint32_t word = 0;
395 if (pin >= 0 && pin < s_maxPins && nbits > 0
396 && m_currentPinBit[pin] + nbits <= m_dataWords) {
397 for (int bit = 0; bit < nbits; ++bit) {
398 word |= ((m_data[m_currentPinBit[pin] + bit] >> pin) & 0x1) << bit;
399 }
400 m_currentPinBit[pin] += nbits;
401 m_oddParity[pin] = parityBit(m_oddParity[pin], word, nbits);
402 } else m_unpackerFlag = false;
403 return word;
404}
405
406// Unpack and test G-Link parity bit for given pin
407
409{
410 bool error = true;
411 if (pin >= 0 && pin < s_maxPins) {
412 int parity = m_oddParity[pin];
413 int bit = unpackerNeutral(pin, 1);
414 m_oddParity[pin] = 1;
415 error = !(bit == parity);
416 }
417 return error;
418}
419
420// Static function to determine word type
421
423{
425 if (((word >> s_headerBit) & s_headerMask) == s_headerVal) {
426 if (((word >> s_statusBit) & s_statusMask) == s_statusVal) type = STATUS;
427 else type = HEADER;
428 }
429 return type;
430}
431
432// Return wordID field from given header word
433
434int ZdcSubBlock::wordId(const uint32_t word)
435{
436 return (word >> s_wordIdBit) & s_wordIdMask;
437}
438
439// Return data format from given header word
440
441int ZdcSubBlock::format(const uint32_t word)
442{
443 return (word >> s_formatBit) & s_formatMask;
444}
445
446// Return seqno field from given header word
447
448int ZdcSubBlock::seqno(const uint32_t word)
449{
450 return (word >> s_seqnoBit) & s_seqnoMask;
451}
452
453// Return module field from given header word
454
455int ZdcSubBlock::module(const uint32_t word)
456{
457 return (word >> s_moduleBit) & s_moduleMask;
458}
459
std::vector< uint32_t > RODDATA
ROD data as a vector of unsigned int.
static int parityBit(int init, uint32_t datum, int nbits)
Return the parity bit for given data.
uint32_t unpackerNeutral(int pin, int nbits)
Unpack given number of bits of neutral data for given pin.
bool glinkDown() const
int slices2() const
static const int s_versionBit
int version() const
static const int s_failingBcnBit
bool glinkProtocol() const
static const int s_seqnoBit
OFFLINE_FRAGMENTS_NAMESPACE::PointerType read(const OFFLINE_FRAGMENTS_NAMESPACE::PointerType beg, const OFFLINE_FRAGMENTS_NAMESPACE::PointerType end)
Input complete packed sub-block from ROD array.
void unpackerInit()
Initialise unpacker.
uint32_t unpacker(int nbits)
Unpack given number of bits of data.
bool glinkTimeout() const
static const uint32_t s_headerVal
static const int s_maxStreamedBits
static const uint32_t s_statusVal
static const int s_glinkParityBit
static const int s_maxWordBits
int m_dataWords
Current number of data words.
void packerNeutral(int pin, uint32_t datum, int nbits)
Pack given neutral data from given pin.
static const int s_formatBit
static const uint32_t s_glinkDavSet
@ UNPACK_COMPRESSION_VERSION
Definition ZdcSubBlock.h:49
@ UNPACK_COMPRESSION_SLICES
Definition ZdcSubBlock.h:50
@ UNPACK_DATA_TRUNCATED
Definition ZdcSubBlock.h:51
int wordId() const
uint32_t m_header
Sub-Block Header.
std::vector< int > m_oddParity
static const int s_glinkDownBit
static const int s_daqOverflowBit
static int minBits(uint32_t datum)
Return the minimum number of bits needed for given data.
static const uint32_t s_formatMask
void write(FullEventAssembler< ZdcSrcIdMap >::RODDATA *theROD) const
Output complete packed sub-block to ROD vector.
int format() const
static const uint32_t s_maxWordMask
int slices1() const
uint32_t m_bitword
void setDaqOverflow(int bit=1)
Set DAQ FIFO Overflow bit in Sub-status word.
static const int s_maxPins
uint32_t failingBCN() const
void setHeader(int wordId, int version, int format, int seqno, int crate, int module, int slices2, int slices1)
Store header data.
bool unpackerNeutralParityError(int pin)
Unpack and test G-Link parity bit for given pin.
static const uint32_t s_maxStreamedMask
bool bcnMismatch() const
static const uint32_t s_failingBcnMask
int crate() const
static const int s_bcnMismatchBit
std::vector< uint32_t > m_data
Sub-Block data.
bool glinkParity() const
static const int s_statusBit
void packer(uint32_t datum, int nbits)
Pack given data into given number of bits.
static const uint32_t s_statusMask
bool m_unpackerFlag
std::string unpackErrorMsg() const
Return the unpacking error message for printing.
int m_unpackError
Unpacking error code.
void packerNeutralParity(int pin)
Pack current G-Link parity bit for given pin.
static const int s_crateBit
static const int s_upstreamErrorBit
void setStatus(uint32_t failingBCN, bool glinkTimeout, bool glinkDown, bool upstreamError, bool daqOverflow, bool bcnMismatch, bool glinkProtocol, bool glinkParity)
Store error status trailer.
static const int s_wordIdBit
static const uint32_t s_versionMask
static const int s_headerBit
ZdcSubBlock.cxx this is a base class derived (copyed) from LVL1 I do not think we need this this way;...
static const uint32_t s_slices1Mask
static const int s_slices1Bit
std::vector< uint32_t >::const_iterator m_dataPos
void packerFlush()
Flush the current data word padded with zeros.
void clear()
Clear all data.
bool upstreamError() const
static SubBlockWordType wordType(uint32_t word)
Word identification.
void setGlinkParity(int bit=1)
Set G-Link Parity bit in Sub-status word.
static const uint32_t s_seqnoMask
int module() const
uint32_t m_maxMask
static const uint32_t s_headerMask
bool daqOverflow() const
static const uint32_t s_crateMask
static const int s_moduleBit
int seqno() const
static const uint32_t s_wordIdMask
static const int s_slices2Bit
std::vector< int > m_currentPinBit
static const uint32_t s_slices2Mask
static const int s_glinkTimeoutBit
static const int s_glinkProtocolBit
std::vector< uint32_t >::const_iterator m_dataPosEnd
int m_bunchCrossing
Bunch Crossing number (neutral format only)
uint32_t m_trailer
Sub-Block Status Trailer.
static const uint32_t s_moduleMask
const DataType * PointerType
Definition RawEvent.h:25
setEventNumber uint32_t
MsgStream & msg
Definition testRead.cxx:32