ATLAS Offline Software
Loading...
Searching...
No Matches
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
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 < m_channels) {
76 m_jeData[index(slice, m_channels) + channel] = jetEle.data();
77 }
78 }
79}
80
81// Store energy subsum data
82
83void 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) {
95 word1 |= s_etId << s_sourceIdBit;
96 word1 |= s_energyWordId << s_dataIdBit;
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
109JemJetElement JemSubBlockV2::jetElement(const int slice, const int channel) const
110{
111 uint32_t je = 0;
112 if (slice >= 0 && slice < timeslices() &&
113 channel >= 0 && channel < m_channels && !m_jeData.empty()) {
114 je = m_jeData[index(slice, m_channels) + channel];
115 }
116 return JemJetElement(je);
117}
118
119// Return energy subsum Ex
120
121unsigned 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
132unsigned 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
143unsigned 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) {
158 slices = dataWords() / s_glinkBitsPerSlice;
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:
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:
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
214int 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
221void 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;
257 // Bunch Crossing number and padding
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);
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();
333 uint32_t word = unpacker(s_wordLength);
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
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