ATLAS Offline Software
Loading...
Searching...
No Matches
CmxCpSubBlock.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 "CmxCpSubBlock.h"
7
8namespace LVL1BS {
9
10// Constant definitions
11
13
28
40
61
62
66
70
71// Clear all data
72
74{
76 m_tobData.clear();
77 m_hitsData.clear();
78 m_presenceMaps.clear();
79 m_overflow.clear();
80}
81
82// Return presence map for given CPM
83
84unsigned int CmxCpSubBlock::presenceMap(const int slice,
85 const int cpm) const
86{
87 unsigned int map = 0;
88 const unsigned int ix = mapIndex(slice, cpm);
89 if (ix < m_presenceMaps.size()) map = m_presenceMaps[ix];
90 return map;
91}
92
93// Return chip for given cpm and tob
94
95int CmxCpSubBlock::chip(const int slice, const int cpm, const int tob) const
96{
97 int ch = 0;
98 const unsigned int ix = tobIndex(slice, cpm, tob);
99 if (ix < m_tobData.size()) {
100 ch = (m_tobData[ix] >> s_tobChipBit) & s_tobChipMask;
101 }
102 return ch;
103}
104
105// Return Local coordinate for given cpm and tob
106
107int CmxCpSubBlock::localCoord(const int slice, const int cpm, const int tob) const
108{
109 int coord = 0;
110 const unsigned int ix = tobIndex(slice, cpm, tob);
111 if (ix < m_tobData.size()) {
113 }
114 return coord;
115}
116
117// Return isolation for given cpm and tob
118
119int CmxCpSubBlock::isolation(const int slice, const int cpm, const int tob) const
120{
121 int isol = 0;
122 const unsigned int ix = tobIndex(slice, cpm, tob);
123 if (ix < m_tobData.size()) {
125 }
126 return isol;
127}
128
129// Return energy for given cpm and tob
130
131int CmxCpSubBlock::energy(const int slice, const int cpm, const int tob) const
132{
133 int et = 0;
134 const unsigned int ix = tobIndex(slice, cpm, tob);
135 if (ix < m_tobData.size()) {
137 }
138 return et;
139}
140
141// Return error bits for given cpm and tob
142
143int CmxCpSubBlock::tobError(int slice, int cpm, int tob) const
144{
145 int error = 0;
146 const unsigned int ix = tobIndex(slice, cpm, tob);
147 if (ix < m_tobData.size()) {
149 }
150 return error;
151}
152
153// Return hit/topo counts for given source ID and HL flag
154
155unsigned int CmxCpSubBlock::hits(const int slice, const int source,
156 const int flag) const
157{
158 unsigned int hits = 0;
159 const unsigned int ix = hitIndex(slice, source, flag);
160 if (ix < m_hitsData.size()) {
162 }
163 return hits;
164}
165
166// Return hit error for given source ID and HL flag
167
168int CmxCpSubBlock::hitsError(const int slice, const int source,
169 const int flag) const
170{
171 int error = 0;
172 const unsigned int ix = hitIndex(slice, source, flag);
173 if (ix < m_hitsData.size()) {
175 }
176 return error;
177}
178
179// Return RoI overflow for given source ID
180
181int CmxCpSubBlock::roiOverflow(const int slice, const int source) const
182{
183 int overflow = 0;
184 const unsigned int ix = ovfIndex(slice, source);
185 if (ix < m_overflow.size()) overflow = m_overflow[ix];
186 return overflow;
187}
188
189// Store presence map
190
191void CmxCpSubBlock::setPresenceMap(const int slice, const int cpm,
192 const unsigned int map)
193{
194 resize();
195 if (map) {
196 const unsigned int ix = mapIndex(slice, cpm);
197 if (ix < m_presenceMaps.size()) m_presenceMaps[ix] = map;
198 }
199}
200
201// Store TOB (RoI) data for given CPM, chip, local coord
202
203void CmxCpSubBlock::setTob(const int slice, const int cpm, const int chip,
204 const int loc, const int energy, const int isol,
205 const int error)
206{
207 resize();
208 if (energy || isol || error) {
209 uint32_t word = 0;
211 word |= (isol & s_tobIsolationMask) << s_tobIsolationBit;
212 word |= (error & s_tobErrorMask) << s_tobErrorBit;
213 word |= (loc & s_tobCoordMask) << s_tobCoordBit;
214 word |= (chip & s_tobChipMask) << s_tobChipBit;
215 word |= (cpm & s_tobCpmMask) << s_tobCpmBit;
216 word |= (s_tobWordId) << s_dataWordIdBit;
217 // Order by chip == presence bit // <<== CHECK
218 for (int tob = 0; tob < s_tobsPerModule; ++tob) {
219 const unsigned int ix = tobIndex(slice, cpm, tob);
220 if (m_tobData[ix] == 0) {
221 m_tobData[ix] = word;
222 break;
223 } else {
224 const int chipOld = (m_tobData[ix]>>s_tobChipBit)&s_tobChipMask;
225 if (chip < chipOld) {
226 for (int i = s_tobsPerModule-tob-1; i > 0; --i) {
227 m_tobData[ix + i] = m_tobData[ix + i - 1];
228 }
229 m_tobData[ix] = word;
230 break;
231 }
232 }
233 }
234 }
235}
236
237// Store hit counts for given source ID and HL flag
238
239void CmxCpSubBlock::setHits(const int slice, const int source, const int flag,
240 const unsigned int hits, const int error)
241{
242 resize();
243 const unsigned int ix = hitIndex(slice, source, flag);
244 if (ix < m_hitsData.size() && (hits || error)) {
245 uint32_t word = m_hitsData[ix];
246 word |= (hits & s_threshMask) << s_threshBit;
247 word |= (error & s_errorMask) << s_threshErrorBit;
248 word |= (flag & s_hlFlagMask) << s_hlFlagBit;
249 word |= (source & s_sourceIdMask) << s_sourceIdBit;
250 word |= (s_threshWordId) << s_dataWordIdBit;
251 m_hitsData[ix] = word;
252 }
253}
254
255// Store RoI overflow for given source ID
256
257void CmxCpSubBlock::setRoiOverflow(const int slice, const int source,
258 const int overflow)
259{
260 resize();
261 if (overflow) {
262 const unsigned int ix = ovfIndex(slice, source);
263 if (ix < m_overflow.size()) m_overflow[ix] = overflow;
264 }
265}
266
267// Packing/Unpacking routines
268
270{
271 bool rc = false;
272 switch (version()) {
273 case 1:
274 case 2:
275 switch (format()) {
276 case NEUTRAL:
277 rc = packNeutral();
278 break;
279 case UNCOMPRESSED:
281 break;
282 default:
283 break;
284 }
285 break;
286 default:
287 break;
288 }
289 return rc;
290}
291
293{
294 bool rc = false;
295 switch (version()) {
296 case 1:
297 case 2: // <<== CHECK
298 switch (format()) {
299 case NEUTRAL:
300 rc = unpackNeutral();
301 break;
302 case UNCOMPRESSED:
304 break;
305 default:
307 break;
308 }
309 break;
310 default:
312 break;
313 }
314 return rc;
315}
316
317// Return presence map index appropriate to format
318
319unsigned int CmxCpSubBlock::mapIndex(const int slice,
320 const int cpm) const
321{
322 unsigned int ix = cpm - 1;
323 if (format() == NEUTRAL) ix += slice * s_modules;
324 return ix;
325}
326
327// Return tob data index appropriate to format
328
329unsigned int CmxCpSubBlock::tobIndex(const int slice, const int cpm,
330 const int tob) const
331{
332 unsigned int ix = (cpm - 1) * s_tobsPerModule + tob;
333 if (format() == NEUTRAL) ix += slice * s_modules * s_tobsPerModule;
334 return ix;
335}
336
337// Return hits data index appropriate to format
338
339unsigned int CmxCpSubBlock::hitIndex(const int slice, const int source,
340 const int flag) const
341{
342 unsigned int ix = (source<<1)|flag;
343 if (format() == NEUTRAL) ix += slice * 2 * MAX_SOURCE_ID;
344 return ix;
345}
346
347// Return overflow index appropriate to format
348
349unsigned int CmxCpSubBlock::ovfIndex(const int slice, const int source) const
350{
351 unsigned int ix = source;
352 if (format() == NEUTRAL) ix += slice * MAX_SOURCE_ID;
353 return ix;
354}
355
356// Resize the data vectors according to format
357
359{
360 if (m_tobData.empty()) {
361 int size1 = s_modules * s_tobsPerModule;
362 int size2 = 2 * MAX_SOURCE_ID;
363 int size3 = s_modules;
364 int size4 = MAX_SOURCE_ID;
365 if (format() == NEUTRAL) {
366 size1 *= timeslices();
367 size2 *= timeslices();
368 size3 *= timeslices();
369 size4 *= timeslices();
370 }
371 m_tobData.resize(size1);
372 m_hitsData.resize(size2);
373 m_presenceMaps.resize(size3);
374 m_overflow.resize(size4);
375 }
376}
377
378// Pack neutral data
379
381{
382 resize();
383 std::vector<int> locVec(s_tobsPerModule);
384 std::vector<int> isolVec(s_tobsPerModule);
385 std::vector<int> parityVec(s_muxPhases);
386 std::vector<int> energyVec(s_tobsPerModule);
387 const int slices = timeslices();
388 for (int slice = 0; slice < slices; ++slice) {
389 for (int pin = 0; pin < s_glinkPins; ++pin) {
390 if (pin < s_modules) { // TOB data
391 const int cpm = pin + 1;
392 // Presence map
394 // Get tob data for this cpm
395 locVec.clear();
396 isolVec.clear();
397 parityVec.clear();
398 energyVec.clear();
399 int parityMerge = 0;
400 for (int tob = 0; tob < s_tobsPerModule; ++tob) {
401 locVec.push_back(localCoord(slice, cpm, tob));
402 isolVec.push_back(isolation(slice, cpm, tob));
403 energyVec.push_back(energy(slice, cpm, tob));
404 if (tob == 0) {
405 const int err = tobError(slice, cpm, tob);
406 parityMerge = err&s_parityErrorMask;
407 for (int mux = 0; mux < s_muxPhases; ++mux) {
408 parityVec.push_back((err>>(mux+s_parityErrorBits))&s_parityErrorMask);
409 }
410 }
411 }
412 // And pack
413 int locCount = 0;
414 int isolCount = 0;
415 int parityCount = 0;
416 int energyCount = 0;
417 for (int tob = 0; tob < s_tobsPerModule-2; ++tob) {
418 // Local coordinates (2 bit)
419 packerNeutral(pin, locVec[locCount++], s_coordBits);
420 // isolation
421 packerNeutral(pin, isolVec[isolCount++], s_isolationBits);
422 // backplane parity error
423 packerNeutral(pin, parityVec[parityCount++], s_parityErrorBits);
424 // energy
425 packerNeutral(pin, energyVec[energyCount++], s_energyBits);
426 if (tob < s_tobsPerModule-3) {
427 packerNeutral(pin, energyVec[energyCount++], s_energyBits);
428 } else {
429 packerNeutral(pin, locVec[locCount++], s_coordBits);
430 packerNeutral(pin, isolVec[isolCount++], s_isolationBits);
431 packerNeutral(pin, parityMerge, s_parityErrorBits);
432 packerNeutral(pin, locVec[locCount++], s_coordBits);
433 packerNeutral(pin, isolVec[isolCount++], s_isolationBits);
434 packerNeutral(pin, parityVec[parityCount++], s_parityErrorBits);
435 }
436 }
437 } else { // Hits and Topo data
438 if (pin < s_glinkPins-1) {
439 // Remote(3), local and total hits; parity error
440 const int source = pin - s_modules;
441 packerNeutral(pin, hits(slice, source, 0), s_hitsBits);
442 packerNeutral(pin, hitsError(slice, source, 0), s_hitsErrorBits);
443 packerNeutral(pin, hits(slice, source, 1), s_hitsBits);
444 packerNeutral(pin, hitsError(slice, source, 1), s_hitsErrorBits);
447 } else {
448 // Bunch crossing number, Fifo overflow and Topo data
456 }
457 }
458 // G-Link parity
460 }
461 }
462 return true;
463}
464
465// Pack uncompressed data
466
468{
469 std::vector<uint32_t>::const_iterator pos;
470 for (pos = m_tobData.begin(); pos != m_tobData.end(); ++pos) {
471 if (*pos) packer(*pos, s_wordLength);
472 }
473 for (pos = m_hitsData.begin(); pos != m_hitsData.end(); ++pos) {
474 if (*pos) packer(*pos, s_wordLength);
475 }
476 packerFlush();
477 return true;
478}
479
480// Unpack neutral data
481
483{
484 resize();
485 int bunchCrossing = 0;
486 int fifoOverflow = 0;
487 int glinkParity = 0;
488 std::vector<int> locVec(s_tobsPerModule);
489 std::vector<int> isolVec(s_tobsPerModule);
490 std::vector<int> parityVec(s_muxPhases);
491 std::vector<int> energyVec(s_tobsPerModule);
492 const int slices = timeslices();
493 for (int slice = 0; slice < slices; ++slice) {
494 for (int pin = 0; pin < s_glinkPins; ++pin) {
495 if (pin < s_modules) { // TOB data
496 // Presence map
497 const unsigned int map = unpackerNeutral(pin, s_presenceBits);
498 locVec.clear();
499 isolVec.clear();
500 parityVec.clear();
501 energyVec.clear();
502 int parityMerge = 0;
503 for (int tob = 0; tob < s_tobsPerModule-2; ++tob) {
504 // Local coordinates (2 bit)
505 locVec.push_back(unpackerNeutral(pin, s_coordBits));
506 // isolation
507 isolVec.push_back(unpackerNeutral(pin, s_isolationBits));
508 // backplane parity error
509 parityVec.push_back(unpackerNeutral(pin, s_parityErrorBits));
510 // energy
511 energyVec.push_back(unpackerNeutral(pin, s_energyBits));
512 if (tob < s_tobsPerModule-3) {
513 energyVec.push_back(unpackerNeutral(pin, s_energyBits));
514 } else {
515 locVec.push_back(unpackerNeutral(pin, s_coordBits));
516 isolVec.push_back(unpackerNeutral(pin, s_isolationBits));
517 parityMerge = unpackerNeutral(pin, s_parityErrorBits);
518 locVec.push_back(unpackerNeutral(pin, s_coordBits));
519 isolVec.push_back(unpackerNeutral(pin, s_isolationBits));
520 parityVec.push_back(unpackerNeutral(pin, s_parityErrorBits));
521 }
522 }
523 int ntobs = 0;
524 for (int bit = 0; bit < s_presenceBits; ++bit) ntobs += (map>>bit)&1;
525 int error = parityMerge;
526 for (int mux = 0; mux < s_muxPhases; ++mux) {
527 error |= (parityVec[mux]<<(mux+s_parityErrorBits));
528 }
529 if (ntobs > s_tobsPerModule) error |= (1<<(s_muxPhases+s_parityErrorBits)); // overflow
530 int tob = 0;
531 const int cpm = pin + 1;
532 for (int chip = 0; chip < s_presenceBits && tob < s_tobsPerModule; ++chip) { // <<== CHECK - assuming bit==chip
533 if ((map>>chip)&1) {
534 setTob(slice, cpm, chip, locVec[tob], energyVec[tob], isolVec[tob], error);
535 ++tob;
536 }
537 }
539 } else { // Hits and Topo data
540 if (pin < s_glinkPins-1) {
541 // Remote(3), local and total hits; parity error
542 const int source = pin - s_modules;
543 unsigned int hits = unpackerNeutral(pin, s_hitsBits);
545 setHits(slice, source, 0, hits, error);
548 setHits(slice, source, 1, hits, error);
550 setRoiOverflow(slice, source, error);
552 } else {
553 // Bunch crossing number, Fifo overflow and Topo data
555 fifoOverflow |= unpackerNeutral(pin, s_fifoOverflowBits);
556 unsigned int hits = unpackerNeutral(pin, s_topoChecksumBits);
557 int error = 0;
566 }
567 }
568 // G-Link parity errors
570 }
571 }
573 setDaqOverflow(fifoOverflow);
575
576 const bool rc = unpackerSuccess();
578 return rc;
579}
580
581// Unpack uncompressed data
582
584{
585 resize();
586 const int maxHits = m_hitsData.size();
587 m_cpmTobCount.assign(s_modules, 0);
588 unpackerInit();
589 uint32_t word = unpacker(s_wordLength);
590 while (unpackerSuccess()) {
591 const int id = dataWordId(word);
592 if (id == s_tobWordId) { // TOB data
593 const int index = cpm(word)-1;
594 const int count = m_cpmTobCount[index];
595 const int index2 = index*s_tobsPerModule + count;
596 if (count < s_tobsPerModule) {
597 m_tobData[index2] = word;
599 } else {
600 setUnpackErrorCode(UNPACK_EXCESS_TOBS); // New code. Check consequences
601 return false;
602 }
603 } else if (id == s_threshWordId) { // Hits and Topo data
604 const int index = (sourceId(word)<<1) | hlFlag(word);
605 if (index < maxHits && m_hitsData[index] == 0) {
606 m_hitsData[index] = word;
607 } else {
609 return false;
610 }
611 } else {
613 return false;
614 }
615 word = unpacker(s_wordLength);
616 }
617 return true;
618}
619
620} // end namespace
double coord
Type of coordination system.
static Double_t rc
static const int s_isolationBits
static const uint32_t s_tobChipMask
bool unpackNeutral()
Unpack neutral 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_parityErrorMask
static const int s_parityErrorBits
int roiOverflow(int slice, int source) const
Return RoI overflow for given source ID.
static const int s_threshErrorBit
static const int s_tobIsolationBit
static const int s_tobOverflowBit
static const int s_tobChipBit
static const int s_bunchCrossingBits
static const int s_threshBit
bool packUncompressed()
Pack uncompressed data.
static const int s_tobsPerModule
void clear()
Clear all data.
bool unpackUncompressed()
Unpack uncompressed data.
static const uint32_t s_sourceIdMask
static const int s_tobWordId
static const int s_hlFlagBit
int energy(int slice, int cpm, int tob) const
Return energy for given cpm and tob.
static const int s_sourceIdBit
static const int s_hitsErrorBits
static const uint32_t s_tobCoordMask
bool unpack()
Unpack data.
std::vector< int > m_overflow
RoI overflows for neutral data.
static const int s_fifoOverflowBits
static const int s_glinkPins
static const uint32_t s_hlFlagMask
std::vector< uint32_t > m_tobData
TOB data.
static const int s_energyBits
static const int s_topoChecksumBits
static const int s_tobEnergyBit
static const uint32_t s_threshMask
static const int s_tobCoordBit
void setPresenceMap(int slice, int cpm, unsigned int map)
Store presence map.
int sourceId(uint32_t word) const
static const int s_topoPaddingBits
unsigned int tobIndex(int slice, int cpm, int tob) const
static const int s_coordBits
int hitsError(int slice, int source, int flag) const
Return hit error for given source ID and HL flag.
static const uint32_t s_dataWordIdMask
bool packNeutral()
Pack neutral data.
static const int s_modules
static const int s_roiOverflowBits
static const int s_tobCpmBit
std::vector< int > m_cpmTobCount
CPM TOB count vector for unpacking.
static const uint32_t s_tobCpmMask
static const int s_muxPhases
unsigned int mapIndex(int slice, int cpm) const
unsigned int presenceMap(int slice, int cpm) const
Return presence map for given CPM.
unsigned int ovfIndex(int slice, int source) const
static const int s_presenceBits
static const int s_hitsBits
int dataWordId(uint32_t word) const
bool pack()
Pack data.
static const uint32_t s_tobEnergyMask
std::vector< uint32_t > m_hitsData
Hits and topo data.
static const int s_wordLength
Data word length.
static const int s_threshWordId
void setHits(int slice, int source, int flag, unsigned int hits, int error)
Store hit counts for given source ID and HL flag.
void setRoiOverflow(int slice, int source, int overflow)
Store RoI overflow for given source ID.
int chip(int slice, int cpm, int tob) const
Return chip for given cpm and tob.
static const int s_paddingBits
int localCoord(int slice, int cpm, int tob) const
Return Local coordinate for given cpm and tob.
int isolation(int slice, int cpm, int tob) const
Return isolation for given cpm and tob.
static const uint32_t s_errorMask
int hlFlag(uint32_t word) const
static const int s_topoCountsBits
int tobError(int slice, int cpm, int tob) const
Return error bits for given cpm and tob.
static const int s_dataWordIdBit
static const int s_topoMapBits
std::vector< unsigned int > m_presenceMaps
Presence maps.
static const int s_tobErrorBit
int cpm(uint32_t word) const
void setTob(int slice, int cpm, int chip, int loc, int energy, int isol, int error)
Store TOB (RoI) data for given CPM, chip, local coord.
static const uint32_t s_tobIsolationMask
static const uint32_t s_tobErrorMask
unsigned int hitIndex(int slice, int source, int flag) const
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.