ATLAS Offline Software
JemSubBlockV2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "JemJetElement.h"
7 #include "JemSubBlockV2.h"
8 
9 namespace LVL1BS {
10 
11 // Constant definitions
12 
14 
16 
20 
24 const int JemSubBlockV2::s_etId;
25 const int JemSubBlockV2::s_exEyId;
26 const int JemSubBlockV2::s_exBit;
27 const int JemSubBlockV2::s_eyBit;
28 const int JemSubBlockV2::s_etBit;
32 
40 
41 
42 JemSubBlockV2::JemSubBlockV2() : m_channels(44), m_energyWords(2)
43 {
44 }
45 
47 {
48 }
49 
50 // Clear all data
51 
53 {
55  m_jeData.clear();
56  m_energySubsums.clear();
57 }
58 
59 // Store JEM header
60 
61 void JemSubBlockV2::setJemHeader(const int version, const int format,
62  const int slice, const int crate,
63  const int module, const int timeslices)
64 {
66 }
67 
68 // Store jet element data
69 
70 void JemSubBlockV2::fillJetElement(const int slice, const JemJetElement& jetEle)
71 {
72  if (jetEle.data()) {
73  const int channel = jetEle.channel();
74  if (channel < m_channels) {
76  m_jeData[index(slice, m_channels) + channel] = jetEle.data();
77  }
78  }
79 }
80 
81 // Store energy subsum data
82 
83 void JemSubBlockV2::setEnergySubsums(const int slice, const unsigned int ex,
84  const unsigned int ey, const unsigned int et)
85 {
86  uint32_t word1 = 0;
87  uint32_t word2 = 0;
88  word1 |= (et & s_etMask) << s_etBit;
89  word2 |= (ex & s_exMask) << s_exBit;
90  word2 |= (ey & s_eyMask) << s_eyBit;
91  if (word1 || word2) {
93  const int ix = index(slice, m_energyWords);
94  if (word1) {
97  m_energySubsums[ix] = word1;
98  }
99  if (word2) {
100  word2 |= s_exEyId << s_sourceIdBit;
101  word2 |= s_energyWordId << s_dataIdBit;
102  m_energySubsums[ix+1] = word2;
103  }
104  }
105 }
106 
107 // Return jet element for given channel
108 
110 {
111  uint32_t je = 0;
112  if (slice >= 0 && slice < timeslices() &&
113  channel >= 0 && channel < m_channels && !m_jeData.empty()) {
115  }
116  return JemJetElement(je);
117 }
118 
119 // Return energy subsum Ex
120 
121 unsigned int JemSubBlockV2::ex(const int slice) const
122 {
123  unsigned int ex = 0;
124  if (slice >= 0 && slice < timeslices() && !m_energySubsums.empty()) {
126  }
127  return ex;
128 }
129 
130 // Return energy subsum Ey
131 
132 unsigned int JemSubBlockV2::ey(const int slice) const
133 {
134  unsigned int ey = 0;
135  if (slice >= 0 && slice < timeslices() && !m_energySubsums.empty()) {
137  }
138  return ey;
139 }
140 
141 // Return energy subsum Et
142 
143 unsigned int JemSubBlockV2::et(const int slice) const
144 {
145  unsigned int et = 0;
146  if (slice >= 0 && slice < timeslices() && !m_energySubsums.empty()) {
148  }
149  return et;
150 }
151 
152 // Return number of timeslices
153 
155 {
156  int slices = slices1();
157  if (slices == 0 && format() == NEUTRAL) {
159  }
160  if (slices == 0) slices = 1;
161  return slices;
162 }
163 
164 // Packing/Unpacking routines
165 
167 {
168  bool rc = false;
169  switch (version()) {
170  case 2: //<< CHECK
171  switch (format()) {
172  case NEUTRAL:
173  rc = packNeutral();
174  break;
175  case UNCOMPRESSED:
176  rc = packUncompressed();
177  break;
178  default:
179  break;
180  }
181  break;
182  default:
183  break;
184  }
185  return rc;
186 }
187 
189 {
190  bool rc = false;
191  switch (version()) {
192  case 1: //<< CHECK
193  switch (format()) {
194  case NEUTRAL:
195  rc = unpackNeutral();
196  break;
197  case UNCOMPRESSED:
198  rc = unpackUncompressed();
199  break;
200  default:
202  break;
203  }
204  break;
205  default:
207  break;
208  }
209  return rc;
210 }
211 
212 // Return data index appropriate to format
213 
214 int JemSubBlockV2::index(const int slice, const int channels) const
215 {
216  return (format() == NEUTRAL) ? slice*channels : 0;
217 }
218 
219 // Resize a data vector according to format
220 
221 void JemSubBlockV2::resize(std::vector<uint32_t>& vec, const int channels)
222 {
223  if (vec.empty()) {
224  int size = channels;
225  if (format() == NEUTRAL) size *= timeslices();
226  vec.resize(size);
227  }
228 }
229 
230 // Pack neutral data
231 
233 {
236  const int slices = timeslices();
237  for (int slice = 0; slice < slices; ++slice) {
238  // Jet element data
239  for (int channel = 0; channel < m_channels; ++channel) {
240  const int pin = channel / s_pairsPerPin;
241  const JemJetElement je = jetElement(slice, channel);
243  packerNeutral(pin, je.emParity(), 1);
244  packerNeutral(pin, je.linkError(), 1);
246  packerNeutral(pin, je.hadParity(), 1);
247  packerNeutral(pin, (je.linkError() >> 1), 1);
248  }
249  // Pad out last jet element pin
250  int lastpin = (m_channels - 1) / s_pairsPerPin;
251  packerNeutral(lastpin, 0, s_jePaddingBits);
252  // Energy Sums
253  ++lastpin;
254  packerNeutral(lastpin, ex(slice), s_energyBits);
255  packerNeutral(lastpin, ey(slice), s_energyBits);
256  packerNeutral(lastpin, et(slice), s_energyBits);
257  // Bunch Crossing number and padding
259  packerNeutral(lastpin, 0, s_energyPaddingBits);
260  // G-Link parity
261  for (int pin = 0; pin <= lastpin; ++pin) packerNeutralParity(pin);
262  }
263  return true;
264 }
265 
266 // Pack uncompressed data
267 
269 {
270  // Jet element data
271  std::vector<uint32_t>::const_iterator pos;
272  for (pos = m_jeData.begin(); pos != m_jeData.end(); ++pos) {
273  if (*pos) packer(*pos, s_wordLength);
274  }
275 
276  // Subsum data
277  if ( !m_energySubsums.empty() ) {
280  }
281  packerFlush();
282  return true;
283 }
284 
285 // Unpack neutral data
286 
288 {
291  const int slices = timeslices();
292  for (int slice = 0; slice < slices; ++slice) {
293  // Jet element data
294  for (int channel = 0; channel < m_channels; ++channel) {
295  const int pin = channel / s_pairsPerPin;
296  const int emData = unpackerNeutral(pin, s_jetElementBits);
297  const int emParity = unpackerNeutral(pin, 1);
298  int linkError = unpackerNeutral(pin, 1);
299  const int hadData = unpackerNeutral(pin, s_jetElementBits);
300  const int hadParity = unpackerNeutral(pin, 1);
301  linkError |= unpackerNeutral(pin, 1) << 1;
302  const JemJetElement je(channel, emData, hadData, emParity,
303  hadParity, linkError);
304  fillJetElement(slice, je);
305  }
306  // Padding from last jet element pin
307  int lastpin = (m_channels - 1) / s_pairsPerPin;
309  // Energy Sums
310  ++lastpin;
311  const unsigned int ex = unpackerNeutral(lastpin, s_energyBits);
312  const unsigned int ey = unpackerNeutral(lastpin, s_energyBits);
313  const unsigned int et = unpackerNeutral(lastpin, s_energyBits);
315  // Bunch Crossing number and padding
318  // G-Link parity errors
319  for (int pin = 0; pin <= lastpin; ++pin) unpackerNeutralParityError(pin);
320  }
321  const bool rc = unpackerSuccess();
323  return rc;
324 }
325 
326 // Unpack uncompressed data
327 
329 {
332  unpackerInit();
334  while (unpackerSuccess()) {
335  const int id = dataId(word);
336  bool err = false;
337  // Jet element data
338  if (id == s_jeWordId) {
339  const JemJetElement jetEle(word);
340  const int channel = jetEle.channel();
341  if (channel < m_channels && m_jeData[channel] == 0) {
342  m_jeData[channel] = word;
343  } else err = true;
344  // Energy subsums
345  } else if (id == s_energyWordId) {
346  switch (sourceId(word)) {
347  case s_etId: {
348  if (m_energySubsums[0] == 0) m_energySubsums[0] = word;
349  else err = true;
350  break;
351  }
352  case s_exEyId: {
353  if (m_energySubsums[1] == 0) m_energySubsums[1] = word;
354  else err = true;
355  break;
356  }
357  default:
358  err = true;
359  break;
360  }
361  } else err = true;
362  if (err) {
364  return false;
365  }
366  word = unpacker(s_wordLength);
367  }
368  return true;
369 }
370 
371 } // end namespace
LVL1BS::JemSubBlockV2::jetElement
JemJetElement jetElement(int slice, int channel) const
Return jet element for given channel.
Definition: JemSubBlockV2.cxx:109
LVL1BS::L1CaloSubBlock::setBunchCrossing
void setBunchCrossing(int bc)
Set the Bunch Crossing number (neutral format only)
Definition: L1CaloSubBlock.h:328
et
Extra patterns decribing particle interation process.
LVL1BS::JemJetElement
JEM jet element dataword class.
Definition: JemJetElement.h:20
xAOD::word1
word1
Definition: eFexEMRoI_v1.cxx:82
LVL1BS::JemSubBlockV2::s_wordLength
static const int s_wordLength
Data word length.
Definition: JemSubBlockV2.h:63
LVL1BS::JemSubBlockV2::unpackUncompressed
bool unpackUncompressed()
Unpack uncompressed data.
Definition: JemSubBlockV2.cxx:328
LVL1BS::JemSubBlockV2::s_bunchCrossingBits
static const int s_bunchCrossingBits
Definition: JemSubBlockV2.h:85
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
LVL1BS::L1CaloSubBlock::clear
void clear()
Clear all data.
Definition: L1CaloSubBlock.cxx:82
LVL1BS::JemSubBlockV2::s_exEyId
static const int s_exEyId
Definition: JemSubBlockV2.h:73
vtune_athena.format
format
Definition: vtune_athena.py:14
LVL1BS::JemSubBlockV2::ey
unsigned int ey(int slice) const
Return energy subsum Ey.
Definition: JemSubBlockV2.cxx:132
LVL1BS::L1CaloSubBlock::packerNeutral
void packerNeutral(int pin, uint32_t datum, int nbits)
Pack given neutral data from given pin.
Definition: L1CaloSubBlock.cxx:413
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LVL1BS::JemSubBlockV2::unpackNeutral
bool unpackNeutral()
Unpack neutral data.
Definition: JemSubBlockV2.cxx:287
LVL1BS::L1CaloSubBlock::unpackerInit
void unpackerInit()
Initialise unpacker.
Definition: L1CaloSubBlock.cxx:393
LVL1BS::JemJetElement::emParity
int emParity() const
Definition: JemJetElement.h:81
LVL1BS::JemJetElement::hadData
int hadData() const
Definition: JemJetElement.h:76
LVL1BS::JemSubBlockV2::clear
void clear()
Clear all data.
Definition: JemSubBlockV2.cxx:52
LVL1BS::JemSubBlockV2::s_jeWordId
static const int s_jeWordId
Definition: JemSubBlockV2.h:66
LVL1BS::JemJetElement::hadParity
int hadParity() const
Definition: JemJetElement.h:86
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
LVL1BS::L1CaloSubBlock::NEUTRAL
@ NEUTRAL
Definition: L1CaloSubBlock.h:28
LVL1BS::L1CaloSubBlock::setHeader
void setHeader(int wordId, int version, int format, int seqno, int crate, int module, int slices2, int slices1)
Store header data.
Definition: L1CaloSubBlock.cxx:99
LVL1BS::L1CaloSubBlock::UNPACK_SOURCE_ID
@ UNPACK_SOURCE_ID
Definition: L1CaloSubBlock.h:41
LVL1BS::JemSubBlockV2::m_channels
int m_channels
Number of jet element channels.
Definition: JemSubBlockV2.h:108
LVL1BS::JemSubBlockV2::s_exMask
static const uint32_t s_exMask
Definition: JemSubBlockV2.h:77
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::JemSubBlockV2::s_energyBits
static const int s_energyBits
Definition: JemSubBlockV2.h:84
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
LVL1BS::JemSubBlockV2::m_jeData
std::vector< uint32_t > m_jeData
Jet element data.
Definition: JemSubBlockV2.h:104
LVL1BS::L1CaloSubBlock::crate
int crate() const
Definition: L1CaloSubBlock.h:263
LVL1BS::JemSubBlockV2::s_sourceIdMask
static const uint32_t s_sourceIdMask
Definition: JemSubBlockV2.h:71
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
python.PyAthena.module
module
Definition: PyAthena.py:134
LVL1BS::JemSubBlockV2::s_etMask
static const uint32_t s_etMask
Definition: JemSubBlockV2.h:79
LVL1BS::L1CaloSubBlock::packer
void packer(uint32_t datum, int nbits)
Pack given data into given number of bits.
Definition: L1CaloSubBlock.cxx:302
LVL1BS::JemSubBlockV2::s_glinkBitsPerSlice
static const int s_glinkBitsPerSlice
Definition: JemSubBlockV2.h:87
LVL1BS::JemSubBlockV2::m_energySubsums
std::vector< uint32_t > m_energySubsums
Energy subsum data.
Definition: JemSubBlockV2.h:106
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
perfmonmt-refit.slice
slice
Definition: perfmonmt-refit.py:52
LVL1BS::L1CaloSubBlock::UNPACK_DATA_TRUNCATED
@ UNPACK_DATA_TRUNCATED
Definition: L1CaloSubBlock.h:40
LVL1BS::JemSubBlockV2::~JemSubBlockV2
~JemSubBlockV2()
Definition: JemSubBlockV2.cxx:46
LVL1BS::JemSubBlockV2::dataId
int dataId(uint32_t word) const
Definition: JemSubBlockV2.h:119
LVL1BS::JemSubBlockV2::packNeutral
bool packNeutral()
Pack neutral data.
Definition: JemSubBlockV2.cxx:232
LVL1BS::JemSubBlockV2::et
unsigned int et(int slice) const
Return energy subsum Et.
Definition: JemSubBlockV2.cxx:143
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::L1CaloSubBlock::unpacker
uint32_t unpacker(int nbits)
Unpack given number of bits of data.
Definition: L1CaloSubBlock.cxx:345
LVL1BS::JemSubBlockV2::s_wordIdVal
static const int s_wordIdVal
JEM header word ID.
Definition: JemSubBlockV2.h:61
LVL1BS::JemSubBlockV2::setEnergySubsums
void setEnergySubsums(int slice, unsigned int ex, unsigned int ey, unsigned int et)
Store energy subsum data.
Definition: JemSubBlockV2.cxx:83
LVL1BS::JemSubBlockV2::s_eyBit
static const int s_eyBit
Definition: JemSubBlockV2.h:75
LVL1BS::L1CaloSubBlock::UNPACK_VERSION
@ UNPACK_VERSION
Definition: L1CaloSubBlock.h:38
LVL1BS::JemSubBlockV2::s_dataIdBit
static const int s_dataIdBit
Definition: JemSubBlockV2.h:65
LVL1BS::JemSubBlockV2::s_eyMask
static const uint32_t s_eyMask
Definition: JemSubBlockV2.h:78
LVL1BS::JemSubBlockV2::s_jePaddingBits
static const int s_jePaddingBits
Definition: JemSubBlockV2.h:83
LVL1BS::JemSubBlockV2::s_jetElementBits
static const int s_jetElementBits
Definition: JemSubBlockV2.h:82
LVL1BS::L1CaloSubBlock::version
int version() const
Definition: L1CaloSubBlock.h:243
LVL1BS::JemSubBlockV2::packUncompressed
bool packUncompressed()
Pack uncompressed data.
Definition: JemSubBlockV2.cxx:268
LVL1BS::L1CaloSubBlock::unpackerSuccess
bool unpackerSuccess() const
Return unpacker success flag.
Definition: L1CaloSubBlock.h:354
LVL1BS::L1CaloSubBlock::slices1
int slices1() const
Definition: L1CaloSubBlock.h:278
LVL1BS::L1CaloSubBlock::dataWords
int dataWords() const
Return number of data words.
Definition: L1CaloSubBlock.h:233
LVL1BS::JemSubBlockV2::s_etId
static const int s_etId
Definition: JemSubBlockV2.h:72
LVL1BS::JemSubBlockV2::ex
unsigned int ex(int slice) const
Return energy subsum Ex.
Definition: JemSubBlockV2.cxx:121
LVL1BS::JemSubBlockV2::m_energyWords
int m_energyWords
Number of energy data words.
Definition: JemSubBlockV2.h:110
LVL1BS::JemJetElement::data
uint32_t data() const
Definition: JemJetElement.h:111
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
LVL1BS::JemSubBlockV2::s_energyPaddingBits
static const int s_energyPaddingBits
Definition: JemSubBlockV2.h:86
LVL1BS::L1CaloSubBlock::module
int module() const
Definition: L1CaloSubBlock.h:268
get_generator_info.version
version
Definition: get_generator_info.py:33
LVL1BS::JemSubBlockV2::timeslices
int timeslices() const
Return number of timeslices.
Definition: JemSubBlockV2.cxx:154
JemJetElement.h
JemSubBlockV2.h
LVL1BS
Definition: ZdcByteStreamReadV1V2Tool.h:47
LVL1BS::JemSubBlockV2::s_etBit
static const int s_etBit
Definition: JemSubBlockV2.h:76
LVL1BS::JemSubBlockV2::fillJetElement
void fillJetElement(int slice, const JemJetElement &jetEle)
Store jet element data.
Definition: JemSubBlockV2.cxx:70
LVL1BS::L1CaloSubBlock::setUnpackErrorCode
void setUnpackErrorCode(int code)
Set the unpacking error code.
Definition: L1CaloSubBlock.h:338
LVL1BS::JemSubBlockV2::s_pairsPerPin
static const int s_pairsPerPin
Definition: JemSubBlockV2.h:81
LVL1BS::JemSubBlockV2::pack
bool pack()
Pack data.
Definition: JemSubBlockV2.cxx:166
LVL1BS::JemJetElement::emData
int emData() const
Definition: JemJetElement.h:71
LVL1BS::JemSubBlockV2::s_exBit
static const int s_exBit
Definition: JemSubBlockV2.h:74
LVL1BS::JemSubBlockV2::setJemHeader
void setJemHeader(int version, int format, int slice, int crate, int module, int timeslices)
Store JEM header.
Definition: JemSubBlockV2.cxx:61
LVL1BS::JemSubBlockV2::resize
void resize(std::vector< uint32_t > &vec, int channels)
Definition: JemSubBlockV2.cxx:221
LVL1BS::JemSubBlockV2::index
int index(int slice, int channels) const
Definition: JemSubBlockV2.cxx:214
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
LVL1BS::JemSubBlockV2::unpack
bool unpack()
Unpack data.
Definition: JemSubBlockV2.cxx:188
LVL1BS::JemSubBlockV2::s_sourceIdBit
static const int s_sourceIdBit
Definition: JemSubBlockV2.h:70
LVL1BS::JemSubBlockV2::sourceId
int sourceId(uint32_t word) const
Definition: JemSubBlockV2.h:114
LVL1BS::JemJetElement::linkError
int linkError() const
Definition: JemJetElement.h:91
LVL1BS::JemSubBlockV2::s_energyWordId
static const uint32_t s_energyWordId
Definition: JemSubBlockV2.h:69
keylayer_zslicemap.slices
slices
Definition: keylayer_zslicemap.py:112
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
LVL1BS::JemSubBlockV2::s_dataIdMask
static const uint32_t s_dataIdMask
Definition: JemSubBlockV2.h:67
LVL1BS::JemJetElement::channel
int channel() const
Definition: JemJetElement.h:66
LVL1BS::JemSubBlockV2::JemSubBlockV2
JemSubBlockV2()
Definition: JemSubBlockV2.cxx:42