ATLAS Offline Software
CmmCpSubBlock.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 "CmmCpSubBlock.h"
7 
8 namespace LVL1BS {
9 
10 // Constant definitions
11 
13 
19 const int CmmCpSubBlock::s_maxHits;
23 
29 
30 
32 {
33 }
34 
36 {
37 }
38 
39 // Clear all data
40 
42 {
44  m_hitsData.clear();
45 }
46 
47 // Return hit counts for given CPM or source ID
48 
49 unsigned int CmmCpSubBlock::hits(const int slice, int source) const
50 {
51  --source;
52  unsigned int hits = 0;
53  if (slice >= 0 && slice < timeslices() &&
54  source >= 0 && source < s_maxHits && !m_hitsData.empty()) {
56  }
57  return hits;
58 }
59 
60 // Return hit error for given CPM or source ID
61 
62 int CmmCpSubBlock::hitsError(const int slice, int source) const
63 {
64  --source;
65  int error = 0;
66  if (slice >= 0 && slice < timeslices() &&
67  source >= 0 && source < s_maxHits && !m_hitsData.empty()) {
69  & s_errorMask;
70  }
71  return error;
72 }
73 
74 // Store hit counts for given CPM or source ID
75 
76 void CmmCpSubBlock::setHits(const int slice, int source,
77  const unsigned int hits, const int error)
78 {
79  --source;
80  if (slice >= 0 && slice < timeslices() &&
81  source >= 0 && source < s_maxHits && (hits || error)) {
82  resize();
84  word |= (hits & s_threshMask) << s_threshBit;
85  word |= (error & s_errorMask) << s_threshErrorBit;
86  word |= (source & s_sourceIdMask) << s_sourceIdBit;
87  word |= (s_dataWordId) << s_dataWordIdBit;
88  m_hitsData[index(slice, source)] = word;
89  }
90 }
91 
92 // Packing/Unpacking routines
93 
95 {
96  bool rc = false;
97  switch (version()) {
98  case 1:
99  switch (format()) {
100  case NEUTRAL:
101  rc = packNeutral();
102  break;
103  case UNCOMPRESSED:
104  rc = packUncompressed();
105  break;
106  default:
107  break;
108  }
109  break;
110  default:
111  break;
112  }
113  return rc;
114 }
115 
117 {
118  bool rc = false;
119  switch (version()) {
120  case 1:
121  switch (format()) {
122  case NEUTRAL:
123  rc = unpackNeutral();
124  break;
125  case UNCOMPRESSED:
126  rc = unpackUncompressed();
127  break;
128  default:
130  break;
131  }
132  break;
133  default:
135  break;
136  }
137  return rc;
138 }
139 
140 // Return data index appropriate to format
141 
142 int CmmCpSubBlock::index(const int slice, const int source) const
143 {
144  int ix = source;
145  if (format() == NEUTRAL) ix += slice * s_maxHits;
146  return ix;
147 }
148 
149 // Resize the hits vector according to format
150 
152 {
153  if (m_hitsData.empty()) {
154  int size = s_maxHits;
155  if (format() == NEUTRAL) size *= timeslices();
156  m_hitsData.resize(size);
157  }
158 }
159 
160 // Pack neutral data
161 
163 {
164  resize();
165  const int slices = timeslices();
166  for (int slice = 0; slice < slices; ++slice) {
167  for (int source = 1; source < MAX_SOURCE_ID; ++source) {
168  const int pin = source - 1;
169  // CPM hits; remote(3), local and total hits; parity error
172  // Bunch crossing number; Fifo overflow
173  if (pin < s_bunchCrossingBits) {
174  packerNeutral(pin, bunchCrossing() >> pin, 1);
175  } else if (pin == s_fifoOverflowPin) {
176  packerNeutral(pin, daqOverflow(), 1);
177  } else packerNeutral(pin, 0, 1);
178  // Padding
179  packerNeutral(pin, 0, s_paddingBits);
180  // G-Link parity
181  packerNeutralParity(pin);
182  }
183  }
184  return true;
185 }
186 
187 // Pack uncompressed data
188 
190 {
191  std::vector<uint32_t>::const_iterator pos;
192  for (pos = m_hitsData.begin(); pos != m_hitsData.end(); ++pos) {
193  if (*pos) packer(*pos, s_wordLength);
194  }
195  packerFlush();
196  return true;
197 }
198 
199 // Unpack neutral data
200 
202 {
203  resize();
204  int bunchCrossing = 0;
205  int overflow = 0;
206  int parity = 0;
207  const int slices = timeslices();
208  for (int slice = 0; slice < slices; ++slice) {
209  for (int source = 1; source < MAX_SOURCE_ID; ++source) {
210  const int pin = source - 1;
211  // CPM hits; remote(3), local and total hits; parity error
212  const unsigned int hits = unpackerNeutral(pin, s_hitsBits);
213  const int error = unpackerNeutral(pin, s_hitsErrorBits);
215  // Bunch crossing number; Fifo overflow
216  if (pin < s_bunchCrossingBits) {
217  bunchCrossing |= unpackerNeutral(pin, 1) << pin;
218  } else if (pin == s_fifoOverflowPin) {
219  overflow |= unpackerNeutral(pin, 1);
220  } else unpackerNeutral(pin, 1);
221  // Padding
223  // G-Link parity errors
224  parity |= unpackerNeutralParityError(pin);
225  }
226  }
228  setDaqOverflow(overflow);
229  setGlinkParity(parity);
230 
231  const bool rc = unpackerSuccess();
233  return rc;
234 }
235 
236 // Unpack uncompressed data
237 
239 {
240  resize();
241  unpackerInit();
243  while (unpackerSuccess()) {
244  const int source = sourceId(word);
245  if (source < s_maxHits && m_hitsData[source] == 0) m_hitsData[source] = word;
246  else {
248  return false;
249  }
250  word = unpacker(s_wordLength);
251  }
252  return true;
253 }
254 
255 } // end namespace
LVL1BS::L1CaloSubBlock::setBunchCrossing
void setBunchCrossing(int bc)
Set the Bunch Crossing number (neutral format only)
Definition: L1CaloSubBlock.h:328
LVL1BS::CmmCpSubBlock::unpackNeutral
bool unpackNeutral()
Unpack neutral data.
Definition: CmmCpSubBlock.cxx:201
LVL1BS::CmmCpSubBlock::s_sourceIdMask
static const uint32_t s_sourceIdMask
Definition: CmmCpSubBlock.h:62
LVL1BS::CmmCpSubBlock::sourceId
int sourceId(uint32_t word) const
Definition: CmmCpSubBlock.h:88
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
LVL1BS::CmmCpSubBlock::m_hitsData
std::vector< uint32_t > m_hitsData
CPM hits and sums data.
Definition: CmmCpSubBlock.h:84
LVL1BS::L1CaloSubBlock::clear
void clear()
Clear all data.
Definition: L1CaloSubBlock.cxx:82
LVL1BS::L1CaloSubBlock::packerNeutral
void packerNeutral(int pin, uint32_t datum, int nbits)
Pack given neutral data from given pin.
Definition: L1CaloSubBlock.cxx:413
LVL1BS::CmmCpSubBlock::unpackUncompressed
bool unpackUncompressed()
Unpack uncompressed data.
Definition: CmmCpSubBlock.cxx:238
LVL1BS::CmmCpSubBlock::s_sourceIdBit
static const int s_sourceIdBit
Definition: CmmCpSubBlock.h:56
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LVL1BS::CmmCpSubBlock::s_maxHits
static const int s_maxHits
Definition: CmmCpSubBlock.h:59
LVL1BS::CmmCpSubBlock::s_threshErrorBit
static const int s_threshErrorBit
Definition: CmmCpSubBlock.h:55
LVL1BS::CmmCpSubBlock::hits
unsigned int hits(int slice, int source) const
Return hit counts for given CPM or source ID.
Definition: CmmCpSubBlock.cxx:49
LVL1BS::CmmCpSubBlock::setHits
void setHits(int slice, int source, unsigned int hits, int error)
Store hit counts for given CPM or source ID.
Definition: CmmCpSubBlock.cxx:76
LVL1BS::L1CaloSubBlock::setGlinkParity
void setGlinkParity(int bit=1)
Set G-Link Parity bit in Sub-status word.
Definition: L1CaloSubBlock.cxx:217
LVL1BS::L1CaloSubBlock::unpackerInit
void unpackerInit()
Initialise unpacker.
Definition: L1CaloSubBlock.cxx:393
LVL1BS::CmmCpSubBlock::resize
void resize()
Definition: CmmCpSubBlock.cxx:151
LVL1BS::CmmCpSubBlock::s_dataWordId
static const int s_dataWordId
Definition: CmmCpSubBlock.h:58
LVL1BS::CmmSubBlock::timeslices
int timeslices() const
Definition: CmmSubBlock.cxx:48
LVL1BS::CmmCpSubBlock::s_hitsBits
static const int s_hitsBits
Definition: CmmCpSubBlock.h:64
LVL1BS::L1CaloSubBlock::NEUTRAL
@ NEUTRAL
Definition: L1CaloSubBlock.h:28
LVL1BS::L1CaloSubBlock::UNPACK_SOURCE_ID
@ UNPACK_SOURCE_ID
Definition: L1CaloSubBlock.h:41
LVL1BS::CmmCpSubBlock::s_threshMask
static const uint32_t s_threshMask
Definition: CmmCpSubBlock.h:60
CmmCpSubBlock.h
LVL1BS::CmmCpSubBlock::hitsError
int hitsError(int slice, int source) const
Return hit error for given CPM or source ID.
Definition: CmmCpSubBlock.cxx:62
LVL1BS::CmmCpSubBlock::s_errorMask
static const uint32_t s_errorMask
Definition: CmmCpSubBlock.h:61
LVL1BS::L1CaloSubBlock::slice
int slice() const
Definition: L1CaloSubBlock.h:258
LVL1BS::L1CaloSubBlock::packerFlush
void packerFlush()
Flush the current data word padded with zeros.
Definition: L1CaloSubBlock.cxx:331
LVL1BS::L1CaloSubBlock::bunchCrossing
int bunchCrossing() const
Return the Bunch Crossing number (neutral format only)
Definition: L1CaloSubBlock.h:333
LVL1BS::CmmCpSubBlock::packNeutral
bool packNeutral()
Pack neutral data.
Definition: CmmCpSubBlock.cxx:162
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
LVL1BS::CmmCpSubBlock::s_fifoOverflowPin
static const int s_fifoOverflowPin
Definition: CmmCpSubBlock.h:68
LVL1BS::CmmCpSubBlock::pack
bool pack()
Pack data.
Definition: CmmCpSubBlock.cxx:94
LVL1BS::L1CaloSubBlock::packer
void packer(uint32_t datum, int nbits)
Pack given data into given number of bits.
Definition: L1CaloSubBlock.cxx:302
LVL1BS::CmmCpSubBlock::s_hitsErrorBits
static const int s_hitsErrorBits
Definition: CmmCpSubBlock.h:65
LVL1BS::CmmCpSubBlock::unpack
bool unpack()
Unpack data.
Definition: CmmCpSubBlock.cxx:116
perfmonmt-refit.slice
slice
Definition: perfmonmt-refit.py:52
LVL1BS::CmmCpSubBlock::s_paddingBits
static const int s_paddingBits
Definition: CmmCpSubBlock.h:67
LVL1BS::L1CaloSubBlock::UNPACK_DATA_TRUNCATED
@ UNPACK_DATA_TRUNCATED
Definition: L1CaloSubBlock.h:40
LVL1BS::L1CaloSubBlock::setDaqOverflow
void setDaqOverflow(int bit=1)
Set DAQ FIFO Overflow bit in Sub-status word.
Definition: L1CaloSubBlock.cxx:206
LVL1BS::CmmCpSubBlock::s_threshBit
static const int s_threshBit
Definition: CmmCpSubBlock.h:54
LVL1BS::CmmCpSubBlock::~CmmCpSubBlock
~CmmCpSubBlock()
Definition: CmmCpSubBlock.cxx:35
LVL1BS::L1CaloSubBlock::unpackerNeutralParityError
bool unpackerNeutralParityError(int pin)
Unpack and test G-Link parity bit for given pin.
Definition: L1CaloSubBlock.cxx:464
LVL1BS::L1CaloSubBlock::format
int format() const
Definition: L1CaloSubBlock.h:248
LVL1BS::CmmCpSubBlock::CmmCpSubBlock
CmmCpSubBlock()
Definition: CmmCpSubBlock.cxx:31
LVL1BS::L1CaloSubBlock::unpacker
uint32_t unpacker(int nbits)
Unpack given number of bits of data.
Definition: L1CaloSubBlock.cxx:345
LVL1BS::L1CaloSubBlock::daqOverflow
bool daqOverflow() const
Definition: L1CaloSubBlock.h:303
LVL1BS::L1CaloSubBlock::UNPACK_VERSION
@ UNPACK_VERSION
Definition: L1CaloSubBlock.h:38
LVL1BS::CmmCpSubBlock::s_wordLength
static const int s_wordLength
Data word length.
Definition: CmmCpSubBlock.h:52
LVL1BS::L1CaloSubBlock::version
int version() const
Definition: L1CaloSubBlock.h:243
LVL1BS::L1CaloSubBlock::unpackerSuccess
bool unpackerSuccess() const
Return unpacker success flag.
Definition: L1CaloSubBlock.h:354
LVL1BS::CmmCpSubBlock::packUncompressed
bool packUncompressed()
Pack uncompressed data.
Definition: CmmCpSubBlock.cxx:189
LVL1BS::CmmCpSubBlock::MAX_SOURCE_ID
@ MAX_SOURCE_ID
Definition: CmmCpSubBlock.h:29
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
LVL1BS::CmmCpSubBlock::clear
void clear()
Clear all data.
Definition: CmmCpSubBlock.cxx:41
LVL1BS::CmmCpSubBlock::s_dataWordIdBit
static const int s_dataWordIdBit
Definition: CmmCpSubBlock.h:57
LVL1BS
Definition: ZdcModifySlices.h:10
LVL1BS::L1CaloSubBlock::setUnpackErrorCode
void setUnpackErrorCode(int code)
Set the unpacking error code.
Definition: L1CaloSubBlock.h:338
LVL1BS::CmmCpSubBlock::index
int index(int slice, int source) const
Definition: CmmCpSubBlock.cxx:142
copySelective.source
string source
Definition: copySelective.py:32
LVL1BS::L1CaloSubBlock::unpackerNeutral
uint32_t unpackerNeutral(int pin, int nbits)
Unpack given number of bits of neutral data for given pin.
Definition: L1CaloSubBlock.cxx:445
get_generator_info.error
error
Definition: get_generator_info.py:40
error
Definition: IImpactPoint3dEstimator.h:70
keylayer_zslicemap.slices
slices
Definition: keylayer_zslicemap.py:112
LVL1BS::CmmCpSubBlock::s_bunchCrossingBits
static const int s_bunchCrossingBits
Definition: CmmCpSubBlock.h:66
LVL1BS::L1CaloSubBlock::UNCOMPRESSED
@ UNCOMPRESSED
Definition: L1CaloSubBlock.h:28
LVL1BS::L1CaloSubBlock::UNPACK_FORMAT
@ UNPACK_FORMAT
Definition: L1CaloSubBlock.h:39
LVL1BS::L1CaloSubBlock::packerNeutralParity
void packerNeutralParity(int pin)
Pack current G-Link parity bit for given pin.
Definition: L1CaloSubBlock.cxx:434