ATLAS Offline Software
Loading...
Searching...
No Matches
JemSubBlock.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 "JemSubBlock.h"
8
9namespace LVL1BS {
10
11// Constant definitions
12
14
16
20
30
31const int JemSubBlock::s_exBit;
32const int JemSubBlock::s_eyBit;
33const int JemSubBlock::s_etBit;
40
49
50
54
58
59// Clear all data
60
62{
64 m_jeData.clear();
65 m_jetHits.clear();
66 m_energySubsums.clear();
67}
68
69// Store JEM header
70
71void JemSubBlock::setJemHeader(const int version, const int format,
72 const int slice, const int crate,
73 const int module, const int timeslices)
74{
76}
77
78// Store jet element data
79
80void JemSubBlock::fillJetElement(const int slice, const JemJetElement& jetEle)
81{
82 if (jetEle.data()) {
83 const int channel = jetEle.channel();
84 if (channel < m_channels) {
86 m_jeData[index(slice)*m_channels + channel] = jetEle.data();
87 }
88 }
89}
90
91// Store jet hit counts
92
93void JemSubBlock::setJetHits(const int slice, const unsigned int hits)
94{
95 if (hits) {
96 const int jem = module();
97 const int sourceId = (jem == 0 || jem == 7 || jem == 8 || jem == 15)
99 uint32_t word = 0;
100 word |= (hits & s_threshMask) << s_threshBit;
103 word |= s_threshWordId << s_dataIdBit;
105 m_jetHits[index(slice)] = word;
106 }
107}
108
109// Store energy subsum data
110
111void JemSubBlock::setEnergySubsums(const int slice, const unsigned int ex,
112 const unsigned int ey, const unsigned int et)
113{
114 uint32_t word = 0;
115 word |= (ex & s_exMask) << s_exBit;
116 word |= (ey & s_eyMask) << s_eyBit;
117 word |= (et & s_etMask) << s_etBit;
118 if (word) {
120 word |= s_subsumId << s_sourceIdBit;
121 word |= s_threshWordId << s_dataIdBit;
123 m_energySubsums[index(slice)] = word;
124 }
125}
126
127// Return jet element for given channel
128
129JemJetElement JemSubBlock::jetElement(const int slice, const int channel) const
130{
131 uint32_t je = 0;
132 if (slice >= 0 && slice < timeslices() &&
133 channel >= 0 && channel < m_channels && !m_jeData.empty()) {
134 je = m_jeData[index(slice)*m_channels + channel];
135 }
136 return JemJetElement(je);
137}
138
139// Return jet hit counts
140
141unsigned int JemSubBlock::jetHits(const int slice) const
142{
143 unsigned int hits = 0;
144 if (slice >= 0 && slice < timeslices() && !m_jetHits.empty()) {
146 }
147 return hits;
148}
149
150// Return energy subsum Ex
151
152unsigned int JemSubBlock::ex(const int slice) const
153{
154 unsigned int ex = 0;
155 if (slice >= 0 && slice < timeslices() && !m_energySubsums.empty()) {
157 }
158 return ex;
159}
160
161// Return energy subsum Ey
162
163unsigned int JemSubBlock::ey(const int slice) const
164{
165 unsigned int ey = 0;
166 if (slice >= 0 && slice < timeslices() && !m_energySubsums.empty()) {
168 }
169 return ey;
170}
171
172// Return energy subsum Et
173
174unsigned int JemSubBlock::et(const int slice) const
175{
176 unsigned int et = 0;
177 if (slice >= 0 && slice < timeslices() && !m_energySubsums.empty()) {
179 }
180 return et;
181}
182
183// Return number of timeslices
184
186{
187 int slices = slices1();
188 if (slices == 0 && format() == NEUTRAL) {
189 slices = dataWords() / s_glinkBitsPerSlice;
190 }
191 if (slices == 0) slices = 1;
192 return slices;
193}
194
195// Packing/Unpacking routines
196
198{
199 bool rc = false;
200 switch (version()) {
201 case 1:
202 switch (format()) {
203 case NEUTRAL:
204 rc = packNeutral();
205 break;
206 case UNCOMPRESSED:
208 break;
209 default:
210 break;
211 }
212 break;
213 default:
214 break;
215 }
216 return rc;
217}
218
220{
221 bool rc = false;
222 switch (version()) {
223 case 1:
224 switch (format()) {
225 case NEUTRAL:
226 rc = unpackNeutral();
227 break;
228 case UNCOMPRESSED:
230 break;
231 default:
233 break;
234 }
235 break;
236 default:
238 break;
239 }
240 return rc;
241}
242
243// Return data index appropriate to format
244
245int JemSubBlock::index(const int slice) const
246{
247 return (format() == NEUTRAL) ? slice : 0;
248}
249
250// Resize a data vector according to format
251
252void JemSubBlock::resize(std::vector<uint32_t>& vec, const int channels)
253{
254 if (vec.empty()) {
255 int size = channels;
256 if (format() == NEUTRAL) size *= timeslices();
257 vec.resize(size);
258 }
259}
260
261// Pack neutral data
262
264{
268 const int slices = timeslices();
269 for (int slice = 0; slice < slices; ++slice) {
270 // Jet element data
271 for (int channel = 0; channel < m_channels; ++channel) {
272 const int pin = channel / s_pairsPerPin;
273 const JemJetElement je = jetElement(slice, channel);
275 packerNeutral(pin, je.emParity(), 1);
276 packerNeutral(pin, je.linkError(), 1);
278 packerNeutral(pin, je.hadParity(), 1);
279 packerNeutral(pin, (je.linkError() >> 1), 1);
280 }
281 // Pad out last jet element pin
282 int lastpin = (m_channels - 1) / s_pairsPerPin;
283 packerNeutral(lastpin, 0, s_jePaddingBits);
284 // Jet Hits and Energy Sums with parity bits
285 ++lastpin;
291 int parity = parityBit(1, ex(slice), s_energyBits);
292 parity = parityBit(parity, ey(slice), s_energyBits);
293 parity = parityBit(parity, et(slice), s_energyBits);
294 packerNeutral(lastpin, parity, 1);
295 // Bunch Crossing number and padding
297 packerNeutral(lastpin, 0, s_hitPaddingBits);
298 // G-Link parity
299 for (int pin = 0; pin <= lastpin; ++pin) packerNeutralParity(pin);
300 }
301 return true;
302}
303
304// Pack uncompressed data
305
307{
308 // Jet element data
309 std::vector<uint32_t>::const_iterator pos;
310 for (pos = m_jeData.begin(); pos != m_jeData.end(); ++pos) {
311 if (*pos) packer(*pos, s_wordLength);
312 }
313
314 // Hits and Subsum data
315 if ( !m_jetHits.empty() && m_jetHits[0]) packer(m_jetHits[0], s_wordLength);
316 if ( !m_energySubsums.empty() && m_energySubsums[0]) {
318 }
319 packerFlush();
320 return true;
321}
322
323// Unpack neutral data
324
326{
330 const int slices = timeslices();
331 for (int slice = 0; slice < slices; ++slice) {
332 // Jet element data
333 for (int channel = 0; channel < m_channels; ++channel) {
334 const int pin = channel / s_pairsPerPin;
335 const int emData = unpackerNeutral(pin, s_jetElementBits);
336 const int emParity = unpackerNeutral(pin, 1);
337 int linkError = unpackerNeutral(pin, 1);
338 const int hadData = unpackerNeutral(pin, s_jetElementBits);
339 const int hadParity = unpackerNeutral(pin, 1);
340 linkError |= unpackerNeutral(pin, 1) << 1;
341 const JemJetElement je(channel, emData, hadData, emParity,
342 hadParity, linkError);
344 }
345 // Padding from last jet element pin
346 int lastpin = (m_channels - 1) / s_pairsPerPin;
348 // Jet Hits and Energy Sums
349 ++lastpin;
351 unpackerNeutral(lastpin, 1); // parity bit
352 const unsigned int ex = unpackerNeutral(lastpin, s_energyBits);
353 const unsigned int ey = unpackerNeutral(lastpin, s_energyBits);
354 const unsigned int et = unpackerNeutral(lastpin, s_energyBits);
356 unpackerNeutral(lastpin, 1); // parity bit
357 // Bunch Crossing number and padding
360 // G-Link parity errors
361 for (int pin = 0; pin <= lastpin; ++pin) unpackerNeutralParityError(pin);
362 }
363 const bool rc = unpackerSuccess();
365 return rc;
366}
367
368// Unpack uncompressed data
369
371{
375 unpackerInit();
376 uint32_t word = unpacker(s_wordLength);
377 while (unpackerSuccess()) {
378 const int id = dataId(word);
379 bool err = false;
380 // Jet element data
381 if (id == s_jeWordId) {
382 const JemJetElement jetEle(word);
383 const int channel = jetEle.channel();
384 if (channel < m_channels && m_jeData[channel] == 0) {
385 m_jeData[channel] = word;
386 } else err = true;
387 // Other data
388 } else {
389 switch (sourceId(word)) {
390 // Jet hit counts/thresholds
391 case s_mainThreshId:
392 case s_mainFwdThreshId: {
393 if (m_jetHits[0] == 0) m_jetHits[0] = word;
394 else err = true;
395 break;
396 }
397 // Energy subsums
398 case s_subsumId: {
399 if (m_energySubsums[0] == 0) m_energySubsums[0] = word;
400 else err = true;
401 break;
402 }
403 default:
404 err = true;
405 break;
406 }
407 }
408 if (err) {
410 return false;
411 }
412 word = unpacker(s_wordLength);
413 }
414 return true;
415}
416
417} // end namespace
std::vector< size_t > vec
static Double_t rc
JEM jet element dataword class.
uint32_t data() const
static const int s_eyBit
Definition JemSubBlock.h:84
static const int s_sourceIdBit
Definition JemSubBlock.h:74
static const int s_jeWordId
Definition JemSubBlock.h:70
int sourceId(uint32_t word) const
void setJemHeader(int version, int format, int slice, int crate, int module, int timeslices)
Store JEM header.
static const int s_jetHitsBits
Definition JemSubBlock.h:96
std::vector< uint32_t > m_jetHits
Jet hit counts.
static const int s_exBit
Definition JemSubBlock.h:83
static const int s_jetIndicatorBit
Definition JemSubBlock.h:75
static const uint32_t s_etMask
Definition JemSubBlock.h:91
int dataId(uint32_t word) const
void fillJetElement(int slice, const JemJetElement &jetEle)
Store jet element data.
static const uint32_t s_eyMask
Definition JemSubBlock.h:90
bool packUncompressed()
Pack uncompressed data.
static const int s_hitPaddingBits
Definition JemSubBlock.h:99
bool unpack()
Unpack data.
static const int s_jetElementBits
Definition JemSubBlock.h:94
static const int s_sumIndicatorBit
Definition JemSubBlock.h:86
bool unpackNeutral()
Unpack neutral data.
static const int s_dataIdBit
Definition JemSubBlock.h:69
bool pack()
Pack data.
static const uint32_t s_dataIdMask
Definition JemSubBlock.h:71
static const uint32_t s_threshMask
Definition JemSubBlock.h:80
static const int s_threshBit
Definition JemSubBlock.h:73
static const int s_sumIndicator
Definition JemSubBlock.h:87
int index(int slice) const
static const int s_wordLength
Data word length.
Definition JemSubBlock.h:67
std::vector< uint32_t > m_jeData
Jet element data.
unsigned int ex(int slice) const
Return energy subsum Ex.
static const int s_wordIdVal
JEM header word ID.
Definition JemSubBlock.h:65
bool unpackUncompressed()
Unpack uncompressed data.
static const int s_mainThreshId
Definition JemSubBlock.h:77
int timeslices() const
Return number of timeslices.
bool packNeutral()
Pack neutral data.
void clear()
Clear all data.
void setJetHits(int slice, unsigned int hits)
Store jet hit counts.
unsigned int jetHits(int slice) const
Return jet hit counts.
unsigned int et(int slice) const
Return energy subsum Et.
void resize(std::vector< uint32_t > &vec, int channels=1)
static const int s_energyBits
Definition JemSubBlock.h:97
static const int s_etBit
Definition JemSubBlock.h:85
static const int s_pairsPerPin
Definition JemSubBlock.h:93
static const int s_bunchCrossingBits
Definition JemSubBlock.h:98
static const int s_jetIndicator
Definition JemSubBlock.h:76
std::vector< uint32_t > m_energySubsums
Energy subsum data.
static const int s_mainFwdThreshId
Definition JemSubBlock.h:78
static const int s_subsumId
Definition JemSubBlock.h:88
static const uint32_t s_exMask
Definition JemSubBlock.h:89
static const uint32_t s_sourceIdMask
Definition JemSubBlock.h:81
static const int s_glinkBitsPerSlice
static const uint32_t s_threshWordId
Definition JemSubBlock.h:79
int m_channels
Number of jet element channels.
unsigned int ey(int slice) const
Return energy subsum Ey.
void setEnergySubsums(int slice, unsigned int ex, unsigned int ey, unsigned int et)
Store energy subsum data.
static const int s_jePaddingBits
Definition JemSubBlock.h:95
JemJetElement jetElement(int slice, int channel) const
Return jet element for given channel.
void packer(uint32_t datum, int nbits)
Pack given data into given number of bits.
int parityBit(int init, uint32_t datum, int nbits) const
Return the parity bit for given data.
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.
void setHeader(int wordId, int version, int format, int seqno, int crate, int module, int slices2, int slices1)
Store header data.
bool unpackerNeutralParityError(int pin)
Unpack and test G-Link parity bit for given pin.
int dataWords() const
Return number of data words.
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)
Definition index.py:1
setEventNumber uint32_t