ATLAS Offline Software
Loading...
Searching...
No Matches
CmxJetSubBlock.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
6#include "CmxJetSubBlock.h"
7
8namespace LVL1BS {
9
10// Constant definitions
11
13
27
44
48//const int CmxJetSubBlock::s_energySmBits[8];
49const int CmxJetSubBlock::s_energySmBits[8] = {3, 6, 5, 4, 7, 2, 9, 0};
66
67
71
75
76// Clear all data
77
79{
81 m_tobData.clear();
82 m_hitsData.clear();
83 m_presenceMaps.clear();
84 m_parityBits.clear();
85}
86
87// Return presence map for given JEM
88
89unsigned int CmxJetSubBlock::presenceMap(const int slice,
90 const int jem) const
91{
92 unsigned int map = 0;
93 const unsigned int ix = mapIndex(slice, jem);
94 if (ix < m_presenceMaps.size()) map = m_presenceMaps[ix];
95 return map;
96}
97
98// Return frame for given jem and tob
99
100int CmxJetSubBlock::frame(const int slice, const int jem, const int tob) const
101{
102 int fr = 0;
103 const unsigned int ix = tobIndex(slice, jem, tob);
104 if (ix < m_tobData.size()) {
105 fr = (m_tobData[ix] >> s_tobFrameBit) & s_tobFrameMask;
106 }
107 return fr;
108}
109
110// Return Local coordinate for given jem and tob
111
112int CmxJetSubBlock::localCoord(const int slice, const int jem, const int tob) const
113{
114 int coord = 0;
115 const unsigned int ix = tobIndex(slice, jem, tob);
116 if (ix < m_tobData.size()) {
118 }
119 return coord;
120}
121
122// Return energy large window size for given jem and tob
123
124int CmxJetSubBlock::energyLarge(const int slice, const int jem, const int tob) const
125{
126 int et = 0;
127 const unsigned int ix = tobIndex(slice, jem, tob);
128 if (ix < m_tobData.size()) {
130 }
131 return et;
132}
133
134// Return energy small window size for given jem and tob
135
136int CmxJetSubBlock::energySmall(const int slice, const int jem, const int tob) const
137{
138 int et = 0;
139 const unsigned int ix = tobIndex(slice, jem, tob);
140 if (ix < m_tobData.size()) {
142 }
143 return et;
144}
145
146// Return error bits for given jem and tob
147
148int CmxJetSubBlock::tobError(int slice, int jem, int tob) const
149{
150 int error = 0;
151 const unsigned int ix = tobIndex(slice, jem, tob);
152 if (ix < m_tobData.size()) {
154 }
155 return error;
156}
157
158// Return parity bits for given JEM
159
160int CmxJetSubBlock::parityBits(const int slice, const int jem) const
161{
162 int parity = 0;
163 const unsigned int ix = parIndex(slice, jem);
164 if (ix < m_parityBits.size()) parity = m_parityBits[ix];
165 return parity;
166}
167
168// Return hit/topo counts for given source ID and HL flag
169
170unsigned int CmxJetSubBlock::hits(const int slice, const int source,
171 const int flag) const
172{
173 unsigned int hits = 0;
174 const unsigned int ix = hitIndex(slice, source, flag);
175 if (ix < m_hitsData.size()) {
176 uint32_t mask = s_threshMainMask;
177 if (source == REMOTE_FORWARD || source == LOCAL_FORWARD
178 || source == TOTAL_FORWARD) {
179 mask = (flag) ? s_threshFwdHMask : s_threshFwdLMask;
180 }
181 else if (source == TOPO_CHECKSUM) mask = s_topoCheckMask;
182 else if (source == TOPO_OCCUPANCY_MAP) mask = s_topoMapMask;
183 else if (source == TOPO_OCCUPANCY_COUNTS) mask = s_topoCountsMask;
184 hits = (m_hitsData[ix] >> s_threshBit) & mask;
185 }
186 return hits;
187}
188
189// Return hit error for given source ID and HL flag
190
191int CmxJetSubBlock::hitsError(const int slice, const int source,
192 const int flag) const
193{
194 int error = 0;
195 if (source == REMOTE_MAIN || source == LOCAL_MAIN || source == TOTAL_MAIN ||
196 source == REMOTE_FORWARD || source == LOCAL_FORWARD ||
197 source == TOTAL_FORWARD) {
198 const unsigned int ix = hitIndex(slice, source, flag);
199 if (ix < m_hitsData.size()) {
201 }
202 }
203 return error;
204}
205
206// Store presence map
207
208void CmxJetSubBlock::setPresenceMap(const int slice, const int jem,
209 const unsigned int map)
210{
211 resize();
212 if (map) {
213 const unsigned int ix = mapIndex(slice, jem);
214 if (ix < m_presenceMaps.size()) m_presenceMaps[ix] = map;
215 }
216}
217
218// Store TOB (RoI) data for given JEM, frame, local coord
219
220void CmxJetSubBlock::setTob(const int slice, const int jem, const int frame,
221 const int loc, const int energyLarge,
222 const int energySmall, const int error)
223{
224 resize();
225 if (energyLarge || energySmall || error) {
226 uint32_t word = 0;
229 word |= (error & s_tobErrorMask) << s_tobErrorBit;
230 word |= (loc & s_tobCoordMask) << s_tobCoordBit;
231 word |= (frame & s_tobFrameMask) << s_tobFrameBit;
232 word |= (jem & s_tobJemMask) << s_tobJemBit;
233 word |= (s_tobWordId) << s_dataWordIdBit;
234 // Order by frame == presence bit // <<== CHECK
235 for (int tob = 0; tob < s_tobsPerModule; ++tob) {
236 const unsigned int ix = tobIndex(slice, jem, tob);
237 if (m_tobData[ix] == 0) {
238 m_tobData[ix] = word;
239 break;
240 } else {
241 const int frameOld = (m_tobData[ix] >> s_tobFrameBit)&s_tobFrameMask;
242 if (frame < frameOld) {
243 for (int i = s_tobsPerModule - tob - 1; i > 0; --i) {
244 m_tobData[ix + i] = m_tobData[ix + i - 1];
245 }
246 m_tobData[ix] = word;
247 break;
248 }
249 }
250 }
251 }
252}
253
254// Store parity bits for neutral format
255
256void CmxJetSubBlock::setParityBits(const int slice, const int jem,
257 const int parity)
258{
259 resize();
260 if (parity) {
261 const unsigned int ix = parIndex(slice, jem);
262 if (ix < m_parityBits.size()) m_parityBits[ix] = parity;
263 }
264}
265
266// Store hit counts for given source ID and HL flag
267
268void CmxJetSubBlock::setHits(const int slice, const int source, const int flag,
269 const unsigned int hits, const int error)
270{
271 resize();
272 const unsigned int ix = hitIndex(slice, source, flag);
273 if (ix < m_hitsData.size() && (hits || error)) {
274 uint32_t word = m_hitsData[ix];
275 uint32_t mask = s_threshMainMask;
276 if (source == REMOTE_FORWARD || source == LOCAL_FORWARD ||
277 source == TOTAL_FORWARD) {
278 mask = (flag) ? s_threshFwdHMask : s_threshFwdLMask;
279 }
280 else if (source == TOPO_CHECKSUM) mask = s_topoCheckMask;
281 else if (source == TOPO_OCCUPANCY_MAP) mask = s_topoMapMask;
282 else if (source == TOPO_OCCUPANCY_COUNTS) mask = s_topoCountsMask;
283 word |= (hits & mask) << s_threshBit;
284 word |= (error & s_errorMask) << s_threshErrorBit;
285 word |= (flag & s_hlFlagMask) << s_hlFlagBit;
286 word |= (source & s_sourceIdMask) << s_sourceIdBit;
287 word |= (s_threshWordId) << s_dataWordIdBit;
288 m_hitsData[ix] = word;
289 }
290}
291
292// Packing/Unpacking routines
293
295{
296 bool rc = false;
297 switch (version()) {
298 case 1:
299 case 2: // <<== CHECK
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: // <<== CHECK
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 presence map index appropriate to format
343
344unsigned int CmxJetSubBlock::mapIndex(const int slice,
345 const int jem) const
346{
347 unsigned int ix = jem;
348 if (format() == NEUTRAL) ix += slice * s_modules;
349 return ix;
350}
351
352// Return parity bits index appropriate to format
353
354unsigned int CmxJetSubBlock::parIndex(const int slice,
355 const int jem) const
356{
357 unsigned int ix = jem;
358 if (format() == NEUTRAL) ix += slice * s_modules;
359 return ix;
360}
361
362// Return tob data index appropriate to format
363
364unsigned int CmxJetSubBlock::tobIndex(const int slice, const int jem,
365 const int tob) const
366{
367 unsigned int ix = jem * s_tobsPerModule + tob;
368 if (format() == NEUTRAL) ix += slice * s_modules * s_tobsPerModule;
369 return ix;
370}
371
372// Return hits data index appropriate to format
373
374unsigned int CmxJetSubBlock::hitIndex(const int slice, const int source,
375 const int flag) const
376{
377 unsigned int ix = (source << 1) | flag;
378 if (format() == NEUTRAL) ix += slice * 2 * MAX_SOURCE_ID;
379 return ix;
380}
381
382// Resize the data vectors according to format
383
385{
386 if (m_tobData.empty()) {
387 int size1 = s_modules * s_tobsPerModule;
388 int size2 = 2 * MAX_SOURCE_ID;
389 int size3 = s_modules;
390 int size4 = s_modules;
391 if (format() == NEUTRAL) {
392 size1 *= timeslices();
393 size2 *= timeslices();
394 size3 *= timeslices();
395 size4 *= timeslices();
396 }
397 m_tobData.resize(size1);
398 m_hitsData.resize(size2);
399 m_presenceMaps.resize(size3);
400 m_parityBits.resize(size4);
401 }
402}
403
404// Pack neutral data
405
407{
408 resize();
409 std::vector<int> locVec(s_tobsPerModule);
410 std::vector<int> energyLgVec(s_tobsPerModule);
411 std::vector<int> energySmVec(s_tobsPerModule);
412 const int slices = timeslices();
413 for (int slice = 0; slice < slices; ++slice) {
414 for (int pin = 0; pin < s_glinkPins; ++pin) {
415 if (pin < s_modules) { // TOB data
416 const int jem = pin;
417 // Presence map
419 // Get tob data for this jem
420 locVec.clear();
421 energyLgVec.clear();
422 energySmVec.clear();
423 for (int tob = 0; tob < s_tobsPerModule; ++tob) {
424 locVec.push_back(localCoord(slice, jem, tob));
425 energyLgVec.push_back(energyLarge(slice, jem, tob));
426 energySmVec.push_back(energySmall(slice, jem, tob));
427 }
428 const int parity = parityBits(slice, jem);
429 // And pack
430 for (int tob = 0; tob < s_tobsPerModule; ++tob) {
431 // Energy small window LSB
432 const int nbitsL = s_energySmBits[2 * tob];
433 packerNeutral(pin, energySmVec[tob], nbitsL);
434 // Local coordinates
435 packerNeutral(pin, locVec[tob], s_coordBits);
436 // Energy large window
437 packerNeutral(pin, energyLgVec[tob], s_energyLgBits);
438 // Backplane parity error
439 packerNeutral(pin, (parity >> tob), s_parityErrorBits);
440 // Energy small window HSB
441 const int nbitsH = s_energySmBits[2 * tob + 1];
442 if (nbitsH > 0) {
443 packerNeutral(pin, (energySmVec[tob] >> nbitsL), nbitsH);
444 }
445 }
446 } else { // Hits and Topo data
447 if (pin < s_glinkPins - 1) {
448 // Remote, local and total hits; parity error
449 const int source1 = pin - s_modules + REMOTE_MAIN;
450 const int source2 = pin - s_modules + REMOTE_FORWARD;
451 packerNeutral(pin, hits(slice, source1, 0), s_threshMainBits);
453 packerNeutral(pin, hits(slice, source1, 1), s_threshMainBits);
454 packerNeutral(pin, (hitsError(slice, source1, 1) >> 1), s_parityErrorBits);
455 packerNeutral(pin, hits(slice, source2, 0), s_threshFwdLBits);
457 packerNeutral(pin, hits(slice, source2, 1), s_threshFwdHBits);
458 packerNeutral(pin, (hitsError(slice, source2, 1) >> 1), s_parityErrorBits);
459 packerNeutral(pin, (hitsError(slice, source1, 0) >> 2), s_roiOverflowBits);
461 } else {
462 // Bunch crossing number, Fifo overflow and Topo data
470 }
471 }
472 // G-Link parity
474 }
475 }
476 return true;
477}
478
479// Pack uncompressed data
480
482{
483 std::vector<uint32_t>::const_iterator pos;
484 for (pos = m_tobData.begin(); pos != m_tobData.end(); ++pos) {
485 if (*pos) packer(*pos, s_wordLength);
486 }
487 for (pos = m_hitsData.begin(); pos != m_hitsData.end(); ++pos) {
488 if (*pos) packer(*pos, s_wordLength);
489 }
490 packerFlush();
491 return true;
492}
493
494// Unpack neutral data
495
497{
498 resize();
499 int bunchCrossing = 0;
500 int fifoOverflow = 0;
501 int glinkParity = 0;
502 std::vector<int> locVec(s_tobsPerModule);
503 std::vector<int> energyLgVec(s_tobsPerModule);
504 std::vector<int> energySmVec(s_tobsPerModule);
505 const int slices = timeslices();
506 for (int slice = 0; slice < slices; ++slice) {
507 for (int pin = 0; pin < s_glinkPins; ++pin) {
508 if (pin < s_modules) { // TOB data
509 // Presence map
510 const unsigned int map = unpackerNeutral(pin, s_presenceBits);
511 locVec.assign(s_tobsPerModule, 0);
512 energyLgVec.assign(s_tobsPerModule, 0);
513 energySmVec.assign(s_tobsPerModule, 0);
514 int parity = 0;
515 for (int tob = 0; tob < s_tobsPerModule; ++tob) {
516 // Energy small window LSB
517 const int nbitsL = s_energySmBits[2 * tob];
518 energySmVec[tob] = unpackerNeutral(pin, nbitsL);
519 // Local coordinates
520 locVec[tob] = unpackerNeutral(pin, s_coordBits);
521 // Energy large window
522 energyLgVec[tob] = unpackerNeutral(pin, s_energyLgBits);
523 // Backplane parity error
524 parity |= (unpackerNeutral(pin, s_parityErrorBits) << tob);
525 // Energy small window HSB
526 const int nbitsH = s_energySmBits[2 * tob + 1];
527 if (nbitsH > 0) {
528 energySmVec[tob] += (unpackerNeutral(pin, nbitsH) << nbitsL);
529 }
530 }
531 const int error = (parity) ? 1 : 0;
532 int tob = 0;
533 const int jem = pin;
534 for (int frame = 0; frame < s_presenceBits && tob < s_tobsPerModule; ++frame) { // <<== CHECK - assuming bit==frame
535 if ((map >> frame) & 1) {
536 setTob(slice, jem, frame, locVec[tob], energyLgVec[tob],
537 energySmVec[tob], error);
538 ++tob;
539 }
540 }
542 setParityBits(slice, jem, parity);
543 } else { // Hits and Topo data
544 if (pin < s_glinkPins - 1) {
545 // Remote, local and total hits; parity error, RoI overflow
546 const int source1 = pin - s_modules + REMOTE_MAIN;
547 const int source2 = pin - s_modules + REMOTE_FORWARD;
548 const unsigned int main0 = unpackerNeutral(pin, s_threshMainBits);
549 int errorMain = unpackerNeutral(pin, s_parityErrorBits);
550 const unsigned int main1 = unpackerNeutral(pin, s_threshMainBits);
551 errorMain |= (unpackerNeutral(pin, s_parityErrorBits) << 1);
552 const unsigned int fwd0 = unpackerNeutral(pin, s_threshFwdLBits);
553 int errorFwd = unpackerNeutral(pin, s_parityErrorBits);
554 const unsigned int fwd1 = unpackerNeutral(pin, s_threshFwdHBits);
555 errorFwd |= (unpackerNeutral(pin, s_parityErrorBits) << 1);
556 const int overflow = (unpackerNeutral(pin, s_roiOverflowBits) << 2);
557 errorMain |= overflow;
558 errorFwd |= overflow;
559 setHits(slice, source1, 0, main0, errorMain);
560 setHits(slice, source1, 1, main1, errorMain);
561 setHits(slice, source2, 0, fwd0, errorFwd);
562 setHits(slice, source2, 1, fwd1, errorFwd);
564 } else {
565 // Bunch crossing number, Fifo overflow and Topo data
567 fifoOverflow |= unpackerNeutral(pin, s_fifoOverflowBits);
568 unsigned int hits = unpackerNeutral(pin, s_topoChecksumBits);
569 int error = 0;
578 }
579 }
580 // G-Link parity errors
582 }
583 }
585 setDaqOverflow(fifoOverflow);
587
588 const bool rc = unpackerSuccess();
590 return rc;
591}
592
593// Unpack uncompressed data
594
596{
597 resize();
598 const int maxHits = m_hitsData.size();
599 m_jemTobCount.assign(s_modules, 0);
600 unpackerInit();
601 uint32_t word = unpacker(s_wordLength);
602 while (unpackerSuccess()) {
603 const int id = dataWordId(word);
604 if (id == s_tobWordId) { // TOB data
605 const int index = jem(word);
606 const int count = m_jemTobCount[index];
607 const int index2 = index * s_tobsPerModule + count;
608 if (count < s_tobsPerModule) {
609 m_tobData[index2] = word;
611 } else {
612 setUnpackErrorCode(UNPACK_EXCESS_TOBS); // New code. Check consequences
613 return false;
614 }
615 } else if (id == s_threshWordId) { // Hits and Topo data
616 const int index = (sourceId(word) << 1) | hlFlag(word);
617 if (index < maxHits && m_hitsData[index] == 0) {
618 m_hitsData[index] = word;
619 } else {
621 return false;
622 }
623 } else {
625 return false;
626 }
627 word = unpacker(s_wordLength);
628 }
629 return true;
630}
631
632} // end namespace
double coord
Type of coordination system.
static Double_t rc
unsigned int parIndex(int slice, int jem) const
static const int s_threshBit
static const uint32_t s_dataWordIdMask
static const uint32_t s_topoCheckMask
static const int s_muxPhases
static const int s_sourceIdBit
int energyLarge(int slice, int jem, int tob) const
Return energy large window size for given jem and tob.
std::vector< unsigned int > m_presenceMaps
Presence maps.
static const int s_threshWordId
bool unpackNeutral()
Unpack neutral data.
static const int s_topoCountsBits
std::vector< uint32_t > m_tobData
TOB data.
static const int s_coordBits
int localCoord(int slice, int jem, int tob) const
Return Local coordinate for given jem and tob.
void setParityBits(int slice, int jem, int parity)
Store parity bits for neutral format.
static const uint32_t s_tobEnergyLgMask
static const int s_topoPaddingBits
static const int s_tobEnergySmBit
bool unpack()
Unpack data.
int frame(int slice, int jem, int tob) const
Return frame for given jem and tob.
bool unpackUncompressed()
Unpack uncompressed data.
static const int s_tobWordId
int jem(uint32_t word) const
static const int s_parityErrorBits
int energySmall(int slice, int jem, int tob) const
Return energy small window size for given jem and tob.
int sourceId(uint32_t word) const
static const int s_energySmBits[8]
bool packUncompressed()
Pack uncompressed data.
unsigned int hits(int slice, int source, int flag) const
Return hit/topo counts for given source ID and HL flag.
static const int s_tobEnergyLgBit
static const int s_topoMapBits
static const uint32_t s_threshMainMask
unsigned int presenceMap(int slice, int jem) const
Return presence map for given JEM.
static const int s_bunchCrossingBits
static const uint32_t s_tobEnergySmMask
static const int s_threshMainBits
unsigned int mapIndex(int slice, int jem) const
int parityBits(int slice, int jem) const
Return parity bits for given JEM.
unsigned int hitIndex(int slice, int source, int flag) const
static const int s_hlFlagBit
static const uint32_t s_threshFwdLMask
static const uint32_t s_sourceIdMask
static const int s_fifoOverflowBits
std::vector< int > m_parityBits
Parity data for neutral format.
static const int s_threshFwdLBits
static const int s_threshFwdHBits
unsigned int tobIndex(int slice, int jem, int tob) const
static const int s_presenceBits
static const uint32_t s_tobJemMask
static const uint32_t s_tobCoordMask
static const int s_dataWordIdBit
void setHits(int slice, int source, int flag, unsigned int hits, int error)
Store hit counts for given source ID and HL flag.
static const int s_energyLgBits
static const int s_tobCoordBit
static const int s_tobFrameBit
static const uint32_t s_topoMapMask
static const uint32_t s_tobFrameMask
static const int s_paddingBits
std::vector< uint32_t > m_hitsData
Hits and topo data.
static const uint32_t s_threshFwdHMask
static const uint32_t s_errorMask
int dataWordId(uint32_t word) const
static const int s_tobErrorBit
static const int s_tobJemBit
static const int s_roiOverflowBits
void setPresenceMap(int slice, int jem, unsigned int map)
Store presence map.
static const int s_modules
void setTob(int slice, int jem, int frame, int loc, int energyLarge, int energySmall, int error)
Store TOB (RoI) data for given JEM, frame, local coord.
static const int s_wordLength
Data word length.
std::vector< int > m_jemTobCount
JEM TOB count vector for unpacking.
void clear()
Clear all data.
static const uint32_t s_topoCountsMask
int hitsError(int slice, int source, int flag) const
Return hit error for given source ID and HL flag.
static const int s_topoChecksumBits
static const uint32_t s_hlFlagMask
static const int s_glinkPins
static const uint32_t s_tobErrorMask
bool packNeutral()
Pack neutral data.
static const int s_threshErrorBit
int tobError(int slice, int jem, int tob) const
Return error bit for given jem and tob.
int hlFlag(uint32_t word) const
static const int s_tobsPerModule
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.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
Definition index.py:1
setEventNumber uint32_t
Extra patterns decribing particle interation process.