ATLAS Offline Software
Loading...
Searching...
No Matches
CmmEnergySubBlock.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <utility>
6
7#include "CmmEnergySubBlock.h"
8
9namespace LVL1BS {
10
11// Constant definitions
12
14
39
45
46
50
54
55// Clear all data
56
62
63// Return Ex subsum for given JEM or source ID
64
65unsigned int CmmEnergySubBlock::ex(const int slice, const int source) const
66{
67 unsigned int ex = 0;
68 if (slice >= 0 && slice < timeslices() && !m_sumsData.empty()) {
69 if (source >= 0 && source < s_maxJems) {
70 ex = (m_sumsData[index(slice, source)] >> s_exBit) & s_exMask;
71 } else if (source == REMOTE || source == LOCAL || source == TOTAL) {
72 ex = m_sumsData[index(slice, source)] & s_sumsMask;
73 }
74 }
75 return ex;
76}
77
78// Return Ey subsum for given JEM or source ID
79
80unsigned int CmmEnergySubBlock::ey(const int slice, const int source) const
81{
82 unsigned int ey = 0;
83 if (slice >= 0 && slice < timeslices() && !m_sumsData.empty()) {
84 if (source >= 0 && source < s_maxJems) {
85 ey = (m_sumsData[index(slice, source)] >> s_eyBit) & s_eyMask;
86 } else if (source == REMOTE || source == LOCAL || source == TOTAL) {
87 ey = m_sumsData[index(slice, source+1)] & s_sumsMask;
88 }
89 }
90 return ey;
91}
92
93// Return Et subsum for given JEM or source ID
94
95unsigned int CmmEnergySubBlock::et(const int slice, const int source) const
96{
97 unsigned int et = 0;
98 if (slice >= 0 && slice < timeslices() && !m_sumsData.empty()) {
99 if (source >= 0 && source < s_maxJems) {
100 et = (m_sumsData[index(slice, source)] >> s_etBit) & s_etMask;
101 } else if (source == REMOTE || source == LOCAL || source == TOTAL) {
102 et = m_sumsData[index(slice, source+2)] & s_sumsMask;
103 }
104 }
105 return et;
106}
107
108// Return Ex subsum error for given JEM or source ID
109
110int CmmEnergySubBlock::exError(const int slice, const int source) const
111{
112 int error = 0;
113 if (slice >= 0 && slice < timeslices() && !m_sumsData.empty()) {
114 if (source >= 0 && source < s_maxJems) {
116 } else if (source == REMOTE) {
117 error = (m_sumsData[index(slice, source)] >> s_errorBit)
119 } else if (source == LOCAL || source == TOTAL) {
121 }
122 }
123 return error;
124}
125
126// Return Ey subsum error for given JEM or source ID
127
128int CmmEnergySubBlock::eyError(const int slice, const int source) const
129{
130 int error = 0;
131 if (slice >= 0 && slice < timeslices() && !m_sumsData.empty()) {
132 if (source >= 0 && source < s_maxJems) {
134 } else if (source == REMOTE) {
135 error = (m_sumsData[index(slice, source+1)] >> s_errorBit)
137 } else if (source == LOCAL || source == TOTAL) {
138 error = (m_sumsData[index(slice, source+1)] >> s_errorBit) & s_errorMask;
139 }
140 }
141 return error;
142}
143
144// Return Et subsum error for given JEM or source ID
145
146int CmmEnergySubBlock::etError(const int slice, const int source) const
147{
148 int error = 0;
149 if (slice >= 0 && slice < timeslices() && !m_sumsData.empty()) {
150 if (source >= 0 && source < s_maxJems) {
152 } else if (source == REMOTE) {
153 error = (m_sumsData[index(slice, source+2)] >> s_errorBit)
155 } else if (source == LOCAL || source == TOTAL) {
156 error = (m_sumsData[index(slice, source+2)] >> s_errorBit) & s_errorMask;
157 }
158 }
159 return error;
160}
161
162// Return Missing-ET Hits map
163
164unsigned int CmmEnergySubBlock::missingEtHits(const int slice) const
165{
166 unsigned int map = 0;
167 if (slice >= 0 && slice < timeslices() && !m_sumsData.empty()) {
169 }
170 return map;
171}
172
173// Return Sum-ET Hits map
174
175unsigned int CmmEnergySubBlock::sumEtHits(const int slice) const
176{
177 unsigned int map = 0;
178 if (slice >= 0 && slice < timeslices() && !m_sumsData.empty()) {
179 unsigned int mask = (version() > 1) ? s_etHitsMask : s_etHitsMaskV1;
180 map = (m_sumsData[index(slice, TOTAL+2)] >> s_etHitsBit) & mask;
181 }
182 return map;
183}
184
185// Return Missing-ET-Sig Hits map
186
187unsigned int CmmEnergySubBlock::missingEtSigHits(const int slice) const
188{
189 unsigned int map = 0;
190 if (version() > 1 && slice >= 0 && slice < timeslices()
191 && !m_sumsData.empty()) {
193 }
194 return map;
195}
196
197// Store energy subsums and errors for given JEM or source ID
198
199void CmmEnergySubBlock::setSubsums(const int slice, const int source,
200 const unsigned int ex, const unsigned int ey,
201 const unsigned int et, const int exError,
202 const int eyError, const int etError)
203{
204 if (slice >= 0 && slice < timeslices() &&
205 source >= 0 && source < s_maxSums &&
206 (ex || ey || et || exError || eyError || etError)) {
207 resize();
208 if (source < s_maxJems) {
209 uint32_t word = 0;
210 word |= (ex & s_exMask) << s_exBit;
211 word |= (ey & s_eyMask) << s_eyBit;
212 word |= (et & s_etMask) << s_etBit;
213 word |= (exError & s_errorMask) << s_jemErrorBit;
214 word |= (eyError & s_errorMask) << s_jemErrorBit;
215 word |= (etError & s_errorMask) << s_jemErrorBit;
216 word |= (source & s_sourceIdMask) << s_sourceIdBit;
217 word |= s_dataWordId << s_dataWordIdBit;
218 m_sumsData[index(slice, source)] = word;
219 } else {
220 unsigned int sum = ex;
221 int err = exError;
222 uint32_t mask = s_errorMask;
223 if (source == REMOTE) mask = s_remoteErrorMask;
224 for (int i = 0; i < 3; ++i) {
225 if (sum || err) {
226 uint32_t word = m_sumsData[index(slice, source+i)];
227 word |= sum & s_sumsMask;
228 word |= (err & mask) << s_errorBit;
229 word |= ((source+i) & s_sourceIdMask) << s_sourceIdBit;
230 word |= s_dataWordId << s_dataWordIdBit;
231 m_sumsData[index(slice, source+i)] = word;
232 }
233 if (i == 0) {
234 sum = ey;
235 err = eyError;
236 } else {
237 sum = et;
238 err = etError;
239 }
240 }
241 }
242 }
243}
244
245// Store Missing-ET Hits map
246
248 const unsigned int map)
249{
250 if (slice >= 0 && slice < timeslices() && map) {
251 resize();
252 const int source = TOTAL + 1;
253 uint32_t word = m_sumsData[index(slice, source)];
254 word |= (map & s_etMissMask) << s_etMissBit;
255 word |= (source & s_sourceIdMask) << s_sourceIdBit;
256 word |= s_dataWordId << s_dataWordIdBit;
257 m_sumsData[index(slice, source)] = word;
258 }
259}
260
261// Store Sum-Et Hits map
262
263void CmmEnergySubBlock::setSumEtHits(const int slice, const unsigned int map)
264{
265 if (slice >= 0 && slice < timeslices() && map) {
266 resize();
267 const int source = TOTAL + 2;
268 const unsigned int mask = (version() > 1) ? s_etHitsMask : s_etHitsMaskV1;
269 uint32_t word = m_sumsData[index(slice, source)];
270 word |= (map & mask) << s_etHitsBit;
271 word |= (source & s_sourceIdMask) << s_sourceIdBit;
272 word |= s_dataWordId << s_dataWordIdBit;
273 m_sumsData[index(slice, source)] = word;
274 }
275}
276
277// Store Missing-ET-Sig Hits map
278
280 const unsigned int map)
281{
282 if (version() > 1 && slice >= 0 && slice < timeslices() && map) {
283 resize();
284 const int source = TOTAL;
285 uint32_t word = m_sumsData[index(slice, source)];
286 word |= (map & s_etMissSigMask) << s_etMissSigBit;
287 word |= (source & s_sourceIdMask) << s_sourceIdBit;
288 word |= s_dataWordId << s_dataWordIdBit;
289 m_sumsData[index(slice, source)] = word;
290 }
291}
292
293// Packing/Unpacking routines
294
296{
297 bool rc = false;
298 switch (version()) {
299 case 2:
300 switch (format()) {
301 case NEUTRAL:
302 rc = packNeutral();
303 break;
304 case UNCOMPRESSED:
306 break;
307 default:
308 break;
309 }
310 break;
311 default:
312 break;
313 }
314 return rc;
315}
316
318{
319 bool rc = false;
320 switch (version()) {
321 case 1:
322 case 2:
323 switch (format()) {
324 case NEUTRAL:
325 rc = unpackNeutral();
326 break;
327 case UNCOMPRESSED:
329 break;
330 default:
332 break;
333 }
334 break;
335 default:
337 break;
338 }
339 return rc;
340}
341
342// Return data index appropriate to format
343
344int CmmEnergySubBlock::index(const int slice, const int source) const
345{
346 int ix = source;
347 if (format() == NEUTRAL) ix += slice * s_maxSums;
348 return ix;
349}
350
351// Resize the sums vector according to format
352
354{
355 if (m_sumsData.empty()) {
356 int size = s_maxSums;
357 if (format() == NEUTRAL) size *= timeslices();
358 m_sumsData.resize(size);
359 }
360}
361
362// Pack neutral data
363
365{
366 resize();
367 const int slices = timeslices();
368 for (int slice = 0; slice < slices; ++slice) {
369 for (int pin = 0; pin < s_maxJems; ++pin) {
370 // JEM energy sums (jem == pin); parity error
371 packerNeutral(pin, ex(slice, pin), s_jemSumBits);
372 packerNeutral(pin, ey(slice, pin), s_jemSumBits);
373 packerNeutral(pin, et(slice, pin), s_jemSumBits);
374 packerNeutral(pin, etError(slice, pin), 1);
375 // Bunch crossing number; Fifo overflow
376 if (pin < s_bunchCrossingBits) {
377 packerNeutral(pin, bunchCrossing() >> pin, 1);
378 // Padding
380 } else if (pin == s_fifoOverflowPin) {
381 packerNeutral(pin, daqOverflow(), 1);
382 } else packerNeutral(pin, 0, 1);
383 }
384 int pin = s_bunchCrossingBits - 1;
385 // Missing-ET-Sig Hits Map
387 // Total Et
390 packerNeutral(pin, etError(slice, TOTAL), 1);
391 // Sum-Et Hits Map
393 // Missing-ET Hits Map
395 // Remote Ex, Ey
400 // Local Ex, Ey
402 packerNeutral(pin, exError(slice, LOCAL), 2);
404 packerNeutral(pin, eyError(slice, LOCAL), 2);
405 // Total Ex, Ey
407 packerNeutral(pin, exError(slice, TOTAL), 2);
409 packerNeutral(pin, eyError(slice, TOTAL), 2);
410 // Remote and Local Et
414 packerNeutral(pin, etError(slice, LOCAL), 3);
415 // G-Link parity errors
416 for (int p = 0; p <= pin; ++p) packerNeutralParity(p);
417 }
418 return true;
419}
420
421// Pack uncompressed data
422
424{
425 std::vector<uint32_t>::const_iterator pos;
426 for (pos = m_sumsData.begin(); pos != m_sumsData.end(); ++pos) {
427 if (*pos) packer(*pos, s_wordLength);
428 }
429 packerFlush();
430 return true;
431}
432
433// Unpack neutral data
434
436{
437 resize();
438 int bunchCrossing = 0;
439 int overflow = 0;
440 int parity = 0;
441 const int slices = timeslices();
442 for (int slice = 0; slice < slices; ++slice) {
443 for (int pin = 0; pin < s_maxJems; ++pin) {
444 // JEM energy sums (jem == pin); parity error
445 const unsigned int ex = unpackerNeutral(pin, s_jemSumBits);
446 const unsigned int ey = unpackerNeutral(pin, s_jemSumBits);
447 const unsigned int et = unpackerNeutral(pin, s_jemSumBits);
448 const int er = unpackerNeutral(pin, 1);
449 setSubsums(slice, pin, ex, ey, et, er, er, er);
450 // Bunch crossing number; Fifo overflow
451 if (pin < s_bunchCrossingBits) {
452 bunchCrossing |= unpackerNeutral(pin, 1) << pin;
453 // Padding
455 } else if (pin == s_fifoOverflowPin) {
456 overflow |= unpackerNeutral(pin, 1);
457 } else unpackerNeutral(pin, 1);
458 }
459 int pin = s_bunchCrossingBits - 1;
460 // Missing-ET-Sig Hits Map
462 // Total Et
463 unsigned int etTot = unpackerNeutral(++pin, s_paddingBits);
464 etTot |= unpackerNeutral(++pin, s_paddingBits-1) << s_paddingBits;
465 const int etErrTot = unpackerNeutral(pin, 1);
466 // Sum-Et Hits Map + padding
468 // Missing-ET Hits Map
470 // Remote Ex, Ey
471 const unsigned int exRem = unpackerNeutral(++pin, s_sumBits);
472 const int exErrRem = unpackerNeutral(pin, 2);
473 const unsigned int eyRem = unpackerNeutral(pin, s_sumBits);
474 const int eyErrRem = unpackerNeutral(pin, 2);
475 // Local Ex, Ey
476 const unsigned int exLoc = unpackerNeutral(++pin, s_sumBits);
477 const int exErrLoc = unpackerNeutral(pin, 1);
478 unpackerNeutral(pin, 1);
479 const unsigned int eyLoc = unpackerNeutral(pin, s_sumBits);
480 const int eyErrLoc = unpackerNeutral(pin, 1);
481 unpackerNeutral(pin, 1);
482 // Total Ex, Ey
483 const unsigned int exTot = unpackerNeutral(++pin, s_sumBits);
484 const int exErrTot = unpackerNeutral(pin, 1);
485 unpackerNeutral(pin, 1);
486 const unsigned int eyTot = unpackerNeutral(pin, s_sumBits);
487 const int eyErrTot = unpackerNeutral(pin, 1);
488 unpackerNeutral(pin, 1);
489 // Remote and Local Et
490 const unsigned int etRem = unpackerNeutral(++pin, s_sumBits-1);
491 const int etErrRem = unpackerNeutral(pin, 2);
492 unpackerNeutral(pin, 1);
493 const unsigned int etLoc = unpackerNeutral(pin, s_sumBits-1);
494 const int etErrLoc = unpackerNeutral(pin, 1);
495 unpackerNeutral(pin, 2);
496 setSubsums(slice, REMOTE, exRem, eyRem, etRem,
497 exErrRem, eyErrRem, etErrRem);
498 setSubsums(slice, LOCAL, exLoc, eyLoc, etLoc,
499 exErrLoc, eyErrLoc, etErrLoc);
500 setSubsums(slice, TOTAL, exTot, eyTot, etTot,
501 exErrTot, eyErrTot, etErrTot);
502 // G-Link parity errors
503 for (int p = 0; p <= pin; ++p) parity |= unpackerNeutralParityError(p);
504 }
506 setDaqOverflow(overflow);
507 setGlinkParity(parity);
508
509 const bool rc = unpackerSuccess();
511 return rc;
512}
513
514// Unpack uncompressed data
515
517{
518 resize();
519 unpackerInit();
520 uint32_t word = unpacker(s_wordLength);
521 while (unpackerSuccess()) {
522 const int source = sourceId(word);
523 if (source < s_maxSums && m_sumsData[source] == 0) m_sumsData[source] = word;
524 else {
526 return false;
527 }
528 word = unpacker(s_wordLength);
529 }
530 return true;
531}
532
533} // end namespace
static Double_t rc
int exError(int slice, int source) const
Return Ex subsum error for given JEM or source ID.
static const uint32_t s_exMask
void setMissingEtSigHits(int slice, unsigned int map)
Store Missing-ET-Sig Hits map.
bool unpackUncompressed()
Unpack uncompressed data.
static const int s_fifoOverflowPin
static const uint32_t s_remoteErrorMask
static const uint32_t s_etHitsMask
unsigned int ey(int slice, int source) const
Return Ey subsum for given JEM or source ID.
unsigned int et(int slice, int source) const
Return Et subsum for given JEM or source ID.
std::vector< uint32_t > m_sumsData
Energy subsums data.
static const uint32_t s_errorMask
void setSumEtHits(int slice, unsigned int map)
Store Sum-Et Hits map.
bool packNeutral()
Pack neutral data.
static const uint32_t s_etHitsMaskV1
static const int s_wordLength
Data word length.
void clear()
Clear all data.
static const int s_dataWordIdBit
bool packUncompressed()
Pack uncompressed data.
static const int s_etMissSigBit
bool unpackNeutral()
Unpack neutral data.
static const uint32_t s_etMissSigMask
unsigned int sumEtHits(int slice) const
Return Sum-Et Hits map.
int eyError(int slice, int source) const
Return Ey subsum error for given JEM or source ID.
unsigned int missingEtSigHits(int slice) const
Return Missing-ET-Sig Hits map.
static const uint32_t s_eyMask
static const uint32_t s_etMissMask
void setSubsums(int slice, int source, unsigned int ex, unsigned int ey, unsigned int et, int exError, int eyError, int etError)
Store energy subsums and errors for given JEM or source ID.
int index(int slice, int source) const
int sourceId(uint32_t word) const
static const int s_bunchCrossingBits
unsigned int missingEtHits(int slice) const
Return Missing-ET Hits map.
int etError(int slice, int source) const
Return Et subsum error for given JEM or source ID.
void setMissingEtHits(int slice, unsigned int map)
Store Missing-ET Hits map.
static const uint32_t s_etMask
static const uint32_t s_sumsMask
static const uint32_t s_sourceIdMask
unsigned int ex(int slice, int source) const
Return Ex subsum for given JEM or source ID.
int timeslices() const
void setDaqOverflow(int bit=1)
Set DAQ FIFO Overflow bit in Sub-status word.
void setGlinkParity(int bit=1)
Set G-Link Parity bit in Sub-status word.
void packer(uint32_t datum, int nbits)
Pack given data into given number of bits.
uint32_t unpacker(int nbits)
Unpack given number of bits of data.
void setUnpackErrorCode(int code)
Set the unpacking error code.
bool unpackerSuccess() const
Return unpacker success flag.
bool unpackerNeutralParityError(int pin)
Unpack and test G-Link parity bit for given pin.
void clear()
Clear all data.
void packerNeutralParity(int pin)
Pack current G-Link parity bit for given pin.
void packerFlush()
Flush the current data word padded with zeros.
uint32_t unpackerNeutral(int pin, int nbits)
Unpack given number of bits of neutral data for given pin.
int bunchCrossing() const
Return the Bunch Crossing number (neutral format only)
void unpackerInit()
Initialise unpacker.
void packerNeutral(int pin, uint32_t datum, int nbits)
Pack given neutral data from given pin.
void setBunchCrossing(int bc)
Set the Bunch Crossing number (neutral format only)
STL class.
Definition index.py:1
setEventNumber uint32_t