ATLAS Offline Software
Loading...
Searching...
No Matches
JemSubBlockV1.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 "JemSubBlockV1.h"
8
9namespace LVL1BS {
10
11// Constant definitions
12
14
16
20
30
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 JemSubBlockV1::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
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 JemSubBlockV1::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 JemSubBlockV1::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 JemSubBlockV1::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 JemSubBlockV1::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 JemSubBlockV1::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 JemSubBlockV1::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 JemSubBlockV1::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 JemSubBlockV1::index(const int slice) const
246{
247 return (format() == NEUTRAL) ? slice : 0;
248}
249
250// Resize a data vector according to format
251
252void JemSubBlockV1::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
std::vector< uint32_t > m_energySubsums
Energy subsum data.
static const int s_sumIndicator
static const int s_glinkBitsPerSlice
std::vector< uint32_t > m_jetHits
Jet hit counts.
int timeslices() const
Return number of timeslices.
bool packNeutral()
Pack neutral data.
static const int s_mainThreshId
static const int s_pairsPerPin
void clear()
Clear all data.
int index(int slice) const
void fillJetElement(int slice, const JemJetElement &jetEle)
Store jet element data.
static const uint32_t s_threshWordId
std::vector< uint32_t > m_jeData
Jet element data.
bool pack()
Pack data.
void setJemHeader(int version, int format, int slice, int crate, int module, int timeslices)
Store JEM header.
unsigned int et(int slice) const
Return energy subsum Et.
static const int s_jetIndicator
static const int s_mainFwdThreshId
static const int s_jetIndicatorBit
static const int s_jeWordId
unsigned int jetHits(int slice) const
Return jet hit counts.
int sourceId(uint32_t word) const
static const int s_sourceIdBit
void resize(std::vector< uint32_t > &vec, int channels=1)
static const uint32_t s_eyMask
static const int s_exBit
static const int s_wordIdVal
JEM header word ID.
static const uint32_t s_sourceIdMask
bool unpackUncompressed()
Unpack uncompressed data.
static const uint32_t s_etMask
static const int s_jetElementBits
static const uint32_t s_exMask
static const int s_wordLength
Data word length.
bool packUncompressed()
Pack uncompressed data.
static const int s_hitPaddingBits
bool unpackNeutral()
Unpack neutral data.
JemJetElement jetElement(int slice, int channel) const
Return jet element for given channel.
static const uint32_t s_threshMask
static const int s_energyBits
static const int s_jePaddingBits
static const int s_jetHitsBits
static const int s_eyBit
static const int s_etBit
static const int s_bunchCrossingBits
unsigned int ex(int slice) const
Return energy subsum Ex.
static const int s_dataIdBit
static const int s_subsumId
int m_channels
Number of jet element channels.
bool unpack()
Unpack data.
void setJetHits(int slice, unsigned int hits)
Store jet hit counts.
static const uint32_t s_dataIdMask
static const int s_sumIndicatorBit
void setEnergySubsums(int slice, unsigned int ex, unsigned int ey, unsigned int et)
Store energy subsum data.
int dataId(uint32_t word) const
static const int s_threshBit
unsigned int ey(int slice) const
Return energy subsum Ey.
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