ATLAS Offline Software
Loading...
Searching...
No Matches
JemSubBlockV2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include "JemJetElement.h"
7#include "JemSubBlockV2.h"
8
9namespace LVL1BS {
10
11// Constant definitions
12
14
16
20
24const int JemSubBlockV2::s_etId;
32
40
41
45
49
50// Clear all data
51
53{
55 m_jeData.clear();
56 m_energySubsums.clear();
57}
58
59// Store JEM header
60
61void 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
71{
72 if (jetEle.data()) {
73 const int channel = jetEle.channel();
74 if (channel < 0) [[unlikely]] { return;}
75 if (channel < m_channels) {
77 m_jeData[index(slice, m_channels) + channel] = jetEle.data();
78 }
79 }
80}
81
82// Store energy subsum data
83
84void JemSubBlockV2::setEnergySubsums(const int slice, const unsigned int ex,
85 const unsigned int ey, const unsigned int et)
86{
87 uint32_t word1 = 0;
88 uint32_t word2 = 0;
89 word1 |= (et & s_etMask) << s_etBit;
90 word2 |= (ex & s_exMask) << s_exBit;
91 word2 |= (ey & s_eyMask) << s_eyBit;
92 if (word1 || word2) {
94 const int ix = index(slice, m_energyWords);
95 if (word1) {
96 word1 |= s_etId << s_sourceIdBit;
97 word1 |= s_energyWordId << s_dataIdBit;
98 m_energySubsums[ix] = word1;
99 }
100 if (word2) {
101 word2 |= s_exEyId << s_sourceIdBit;
102 word2 |= s_energyWordId << s_dataIdBit;
103 m_energySubsums[ix+1] = word2;
104 }
105 }
106}
107
108// Return jet element for given channel
109
110JemJetElement JemSubBlockV2::jetElement(const int slice, const int channel) const
111{
112 uint32_t je = 0;
113 if (slice >= 0 && slice < timeslices() &&
114 channel >= 0 && channel < m_channels && !m_jeData.empty()) {
115 je = m_jeData[index(slice, m_channels) + channel];
116 }
117 return JemJetElement(je);
118}
119
120// Return energy subsum Ex
121
122unsigned int JemSubBlockV2::ex(const int slice) const
123{
124 unsigned int ex = 0;
125 if (slice >= 0 && slice < timeslices() && !m_energySubsums.empty()) {
127 }
128 return ex;
129}
130
131// Return energy subsum Ey
132
133unsigned int JemSubBlockV2::ey(const int slice) const
134{
135 unsigned int ey = 0;
136 if (slice >= 0 && slice < timeslices() && !m_energySubsums.empty()) {
138 }
139 return ey;
140}
141
142// Return energy subsum Et
143
144unsigned int JemSubBlockV2::et(const int slice) const
145{
146 unsigned int et = 0;
147 if (slice >= 0 && slice < timeslices() && !m_energySubsums.empty()) {
149 }
150 return et;
151}
152
153// Return number of timeslices
154
156{
157 int slices = slices1();
158 if (slices == 0 && format() == NEUTRAL) {
159 slices = dataWords() / s_glinkBitsPerSlice;
160 }
161 if (slices == 0) slices = 1;
162 return slices;
163}
164
165// Packing/Unpacking routines
166
168{
169 bool rc = false;
170 switch (version()) {
171 case 2: //<< CHECK
172 switch (format()) {
173 case NEUTRAL:
174 rc = packNeutral();
175 break;
176 case UNCOMPRESSED:
178 break;
179 default:
180 break;
181 }
182 break;
183 default:
184 break;
185 }
186 return rc;
187}
188
190{
191 bool rc = false;
192 switch (version()) {
193 case 1: //<< CHECK
194 switch (format()) {
195 case NEUTRAL:
196 rc = unpackNeutral();
197 break;
198 case UNCOMPRESSED:
200 break;
201 default:
203 break;
204 }
205 break;
206 default:
208 break;
209 }
210 return rc;
211}
212
213// Return data index appropriate to format
214
215int JemSubBlockV2::index(const int slice, const int channels) const
216{
217 return (format() == NEUTRAL) ? slice*channels : 0;
218}
219
220// Resize a data vector according to format
221
222void JemSubBlockV2::resize(std::vector<uint32_t>& vec, const int channels)
223{
224 if (vec.empty()) {
225 int size = channels;
226 if (format() == NEUTRAL) size *= timeslices();
227 vec.resize(size);
228 }
229}
230
231// Pack neutral data
232
234{
237 const int slices = timeslices();
238 for (int slice = 0; slice < slices; ++slice) {
239 // Jet element data
240 for (int channel = 0; channel < m_channels; ++channel) {
241 const int pin = channel / s_pairsPerPin;
242 const JemJetElement je = jetElement(slice, channel);
244 packerNeutral(pin, je.emParity(), 1);
245 packerNeutral(pin, je.linkError(), 1);
247 packerNeutral(pin, je.hadParity(), 1);
248 packerNeutral(pin, (je.linkError() >> 1), 1);
249 }
250 // Pad out last jet element pin
251 int lastpin = (m_channels - 1) / s_pairsPerPin;
252 packerNeutral(lastpin, 0, s_jePaddingBits);
253 // Energy Sums
254 ++lastpin;
258 // Bunch Crossing number and padding
261 // G-Link parity
262 for (int pin = 0; pin <= lastpin; ++pin) packerNeutralParity(pin);
263 }
264 return true;
265}
266
267// Pack uncompressed data
268
270{
271 // Jet element data
272 std::vector<uint32_t>::const_iterator pos;
273 for (pos = m_jeData.begin(); pos != m_jeData.end(); ++pos) {
274 if (*pos) packer(*pos, s_wordLength);
275 }
276
277 // Subsum data
278 if ( !m_energySubsums.empty() ) {
281 }
282 packerFlush();
283 return true;
284}
285
286// Unpack neutral data
287
289{
292 const int slices = timeslices();
293 for (int slice = 0; slice < slices; ++slice) {
294 // Jet element data
295 for (int channel = 0; channel < m_channels; ++channel) {
296 const int pin = channel / s_pairsPerPin;
297 const int emData = unpackerNeutral(pin, s_jetElementBits);
298 const int emParity = unpackerNeutral(pin, 1);
299 int linkError = unpackerNeutral(pin, 1);
300 const int hadData = unpackerNeutral(pin, s_jetElementBits);
301 const int hadParity = unpackerNeutral(pin, 1);
302 linkError |= unpackerNeutral(pin, 1) << 1;
303 const JemJetElement je(channel, emData, hadData, emParity,
304 hadParity, linkError);
306 }
307 // Padding from last jet element pin
308 int lastpin = (m_channels - 1) / s_pairsPerPin;
310 // Energy Sums
311 ++lastpin;
312 const unsigned int ex = unpackerNeutral(lastpin, s_energyBits);
313 const unsigned int ey = unpackerNeutral(lastpin, s_energyBits);
314 const unsigned int et = unpackerNeutral(lastpin, s_energyBits);
316 // Bunch Crossing number and padding
319 // G-Link parity errors
320 for (int pin = 0; pin <= lastpin; ++pin) unpackerNeutralParityError(pin);
321 }
322 const bool rc = unpackerSuccess();
324 return rc;
325}
326
327// Unpack uncompressed data
328
330{
333 unpackerInit();
334 uint32_t word = unpacker(s_wordLength);
335 while (unpackerSuccess()) {
336 const int id = dataId(word);
337 bool err = false;
338 // Jet element data
339 if (id == s_jeWordId) {
340 const JemJetElement jetEle(word);
341 const int channel = jetEle.channel();
342 if (channel < m_channels && m_jeData[channel] == 0) {
343 m_jeData[channel] = word;
344 } else err = true;
345 // Energy subsums
346 } else if (id == s_energyWordId) {
347 switch (sourceId(word)) {
348 case s_etId: {
349 if (m_energySubsums[0] == 0) m_energySubsums[0] = word;
350 else err = true;
351 break;
352 }
353 case s_exEyId: {
354 if (m_energySubsums[1] == 0) m_energySubsums[1] = word;
355 else err = true;
356 break;
357 }
358 default:
359 err = true;
360 break;
361 }
362 } else err = true;
363 if (err) {
365 return false;
366 }
367 word = unpacker(s_wordLength);
368 }
369 return true;
370}
371
372} // end namespace
std::vector< size_t > vec
static Double_t rc
JEM jet element dataword class.
uint32_t data() const
static const int s_etId
int timeslices() const
Return number of timeslices.
void fillJetElement(int slice, const JemJetElement &jetEle)
Store jet element data.
void clear()
Clear all data.
static const int s_etBit
std::vector< uint32_t > m_energySubsums
Energy subsum data.
static const int s_dataIdBit
static const int s_jePaddingBits
static const int s_eyBit
static const uint32_t s_eyMask
int dataId(uint32_t word) const
static const int s_energyBits
bool unpack()
Unpack data.
static const uint32_t s_dataIdMask
unsigned int ey(int slice) const
Return energy subsum Ey.
void resize(std::vector< uint32_t > &vec, int channels)
void setEnergySubsums(int slice, unsigned int ex, unsigned int ey, unsigned int et)
Store energy subsum data.
bool unpackNeutral()
Unpack neutral data.
bool packNeutral()
Pack neutral data.
static const int s_energyPaddingBits
unsigned int ex(int slice) const
Return energy subsum Ex.
static const int s_glinkBitsPerSlice
static const uint32_t s_exMask
int m_channels
Number of jet element channels.
static const int s_exEyId
void setJemHeader(int version, int format, int slice, int crate, int module, int timeslices)
Store JEM header.
static const int s_wordLength
Data word length.
static const int s_sourceIdBit
std::vector< uint32_t > m_jeData
Jet element data.
int sourceId(uint32_t word) const
static const int s_bunchCrossingBits
int m_energyWords
Number of energy data words.
static const int s_jeWordId
static const int s_wordIdVal
JEM header word ID.
bool unpackUncompressed()
Unpack uncompressed data.
static const int s_exBit
unsigned int et(int slice) const
Return energy subsum Et.
static const uint32_t s_energyWordId
static const uint32_t s_sourceIdMask
static const uint32_t s_etMask
int index(int slice, int channels) const
bool pack()
Pack data.
static const int s_pairsPerPin
bool packUncompressed()
Pack uncompressed data.
static const int s_jetElementBits
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.
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
#define unlikely(x)