ATLAS Offline Software
Loading...
Searching...
No Matches
CmmJetSubBlock.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include "CmmJetSubBlock.h"
7
8namespace LVL1BS {
9
10// Constant definitions
11
13
27
35
36
40
44
45// Clear all data
46
52
53// Return jet hit counts for given jem or source ID
54
55unsigned int CmmJetSubBlock::jetHits(const int slice, const int source) const
56{
57 unsigned int hits = 0;
58 if (slice >= 0 && slice < timeslices() &&
59 source >= 0 && source < s_maxHits && !m_hitsData.empty()) {
60 if (source <= TOTAL_MAIN) {
61 hits = (m_hitsData[index(slice, source)] >> s_threshBit) & s_threshMask;
62 } else if (source >= REMOTE_FORWARD) {
63 hits = (m_hitsData[index(slice, source)] >> s_threshBit) & s_fwdMask;
64 }
65 }
66 return hits;
67}
68
69// Return jet hit error for given jem or source ID
70
71int CmmJetSubBlock::jetHitsError(const int slice, const int source) const
72{
73 int error = 0;
74 if (slice >= 0 && slice < timeslices() &&
75 source >= 0 && source < s_maxHits && !m_hitsData.empty()) {
76 if (source <= TOTAL_MAIN) {
79 } else if (source == REMOTE_FORWARD) {
81 }
82 }
83 return error;
84}
85
86// Return jet ET map
87
88unsigned int CmmJetSubBlock::jetEtMap(const int slice) const
89{
90 unsigned int map = 0;
91 if (slice >= 0 && slice < timeslices() && !m_hitsData.empty()) {
93 }
94 return map;
95}
96
97// Store jet hit counts and error for given jem or source ID
98
99void CmmJetSubBlock::setJetHits(const int slice, const int source,
100 const unsigned int hits, const int error)
101{
102 if (slice >= 0 && slice < timeslices() &&
103 source >= 0 && source < s_maxHits && (hits || error)) {
104 resize();
105 uint32_t word = m_hitsData[index(slice, source)];
106 if (source <= TOTAL_MAIN) {
107 word |= (hits & s_threshMask) << s_threshBit;
108 word |= (error & s_errorMask) << s_threshErrorBit;
109 } else {
110 word |= (hits & s_fwdMask) << s_threshBit;
111 word |= (error & s_errorMask) << s_fwdErrorBit;
112 }
113 word |= (source & s_sourceIdMask) << s_sourceIdBit;
114 word |= (s_dataWordId) << s_dataWordIdBit;
115 m_hitsData[index(slice, source)] = word;
116 }
117}
118
119// Store jet ET map
120
121void CmmJetSubBlock::setJetEtMap(const int slice, const unsigned int map)
122{
123 if (slice >= 0 && slice < timeslices() && map) {
124 resize();
125 uint32_t word = m_hitsData[index(slice, TOTAL_FORWARD)];
126 word |= (map & s_etMapMask) << s_etMapBit;
128 word |= (s_dataWordId) << s_dataWordIdBit;
130 }
131}
132
133// Packing/Unpacking routines
134
136{
137 bool rc = false;
138 switch (version()) {
139 case 1:
140 switch (format()) {
141 case NEUTRAL:
142 rc = packNeutral();
143 break;
144 case UNCOMPRESSED:
146 break;
147 default:
148 break;
149 }
150 break;
151 default:
152 break;
153 }
154 return rc;
155}
156
158{
159 bool rc = false;
160 switch (version()) {
161 case 1:
162 switch (format()) {
163 case NEUTRAL:
164 rc = unpackNeutral();
165 break;
166 case UNCOMPRESSED:
168 break;
169 default:
171 break;
172 }
173 break;
174 default:
176 break;
177 }
178 return rc;
179}
180
181// Return data index appropriate to format
182
183int CmmJetSubBlock::index(const int slice, const int source) const
184{
185 int ix = source;
186 if (format() == NEUTRAL) ix += slice * s_maxHits;
187 return ix;
188}
189
190// Resize the hits vector according to format
191
193{
194 if (m_hitsData.empty()) {
195 int size = s_maxHits;
196 if (format() == NEUTRAL) size *= timeslices();
197 m_hitsData.resize(size);
198 }
199}
200
201// Pack neutral data
202
204{
205 resize();
206 const int slices = timeslices();
207 for (int slice = 0; slice < slices; ++slice) {
208 for (int pin = 0; pin <= TOTAL_MAIN; ++pin) {
209 // Jem hits; remote, local and total main hits; parity error
212 // Bunch crossing number; Fifo overflow
213 if (pin < s_bunchCrossingBits) {
214 packerNeutral(pin, bunchCrossing() >> pin, 1);
215 } else if (pin == s_fifoOverflowPin) {
216 packerNeutral(pin, daqOverflow(), 1);
217 } else packerNeutral(pin, 0, 1);
218 // Padding
219 if (pin < REMOTE_MAIN) packerNeutral(pin, 0, s_paddingBits);
220 }
221 // ET Map + padding
223 // Total forward (left + right)
227 // Remote + Local forward
228 const int lastpin = TOTAL_MAIN + 1;
232 packerNeutral(lastpin, 0, 1);
234 // G-Link parity
235 for (int pin = 0; pin <= lastpin; ++pin) packerNeutralParity(pin);
236 }
237 return true;
238}
239
240// Pack uncompressed data
241
243{
244 std::vector<uint32_t>::const_iterator pos;
245 for (pos = m_hitsData.begin(); pos != m_hitsData.end(); ++pos) {
246 if (*pos) packer(*pos, s_wordLength);
247 }
248 packerFlush();
249 return true;
250}
251
252// Unpack neutral data
253
255{
256 resize();
257 int bunchCrossing = 0;
258 int overflow = 0;
259 int parity = 0;
260 const int slices = timeslices();
261 for (int slice = 0; slice < slices; ++slice) {
262 unsigned int hits = 0;
263 int error = 0;
264 for (int pin = 0; pin <= TOTAL_MAIN; ++pin) {
265 // Jem hits; remote, local and total main hits; parity error
266 hits = unpackerNeutral(pin, s_jetHitsBits);
268 setJetHits(slice, pin, hits, error);
269 // Bunch crossing number; Fifo overflow
270 if (pin < s_bunchCrossingBits) {
271 bunchCrossing |= unpackerNeutral(pin, 1) << pin;
272 } else if (pin == s_fifoOverflowPin) {
273 overflow |= unpackerNeutral(pin, 1);
274 } else unpackerNeutral(pin, 1);
275 // Padding
277 }
278 // ET Map + padding
280 // Total forward (left + right)
283 setJetHits(slice, TOTAL_FORWARD, hits, 0);
284 // Remote + Local forward
285 const int lastpin = TOTAL_MAIN + 1;
286 hits = unpackerNeutral(lastpin, s_fwdHitsBits);
289 unpackerNeutral(lastpin, 1);
291 unpackerNeutral(lastpin, s_fwdHitsBits), 0);
292 // G-Link parity errors
293 for (int pin = 0; pin <= lastpin; ++pin) {
294 parity |= unpackerNeutralParityError(pin);
295 }
296 }
298 setDaqOverflow(overflow);
299 setGlinkParity(parity);
300
301 const bool rc = unpackerSuccess();
303 return rc;
304}
305
306// Unpack uncompressed data
307
309{
310 resize();
311 unpackerInit();
312 uint32_t word = unpacker(s_wordLength);
313 while (unpackerSuccess()) {
314 const int source = sourceId(word);
315 if (source < s_maxHits && m_hitsData[source] == 0) m_hitsData[source] = word;
316 else {
318 return false;
319 }
320 word = unpacker(s_wordLength);
321 }
322 return true;
323}
324
325} // end namespace
static Double_t rc
static const int s_paddingBits
unsigned int jetHits(int slice, int source) const
Return jet hit counts for given jem or source ID.
bool unpackUncompressed()
Unpack uncompressed data.
std::vector< uint32_t > m_hitsData
JEM hits and sums data.
static const uint32_t s_etMapMask
bool packNeutral()
Pack neutral data.
static const int s_fwdHitsBits
static const int s_wordLength
Data word length.
static const int s_bunchCrossingBits
int jetHitsError(int slice, int source) const
Return jet hit error for given jem or source ID.
static const int s_threshErrorBit
static const int s_rightBit
bool packUncompressed()
Pack uncompressed data.
static const int s_dataWordId
static const uint32_t s_errorMask
static const int s_fifoOverflowPin
void setJetHits(int slice, int source, unsigned int hits, int error)
Store jet hit counts and error for given jem or source ID.
static const uint32_t s_sourceIdMask
static const uint32_t s_fwdMask
static const int s_fwdErrorBit
static const int s_threshBit
int sourceId(uint32_t word) const
int index(int slice, int source) const
static const int s_maxHits
void setJetEtMap(int slice, unsigned int map)
Store jet ET map.
static const int s_jetHitsBits
static const uint32_t s_threshMask
static const int s_dataWordIdBit
unsigned int jetEtMap(int slice) const
Return jet ET map.
void clear()
Clear all data.
bool unpackNeutral()
Unpack neutral data.
bool unpack()
Unpack data.
static const int s_sourceIdBit
static const int s_jetHitsErrorBits
static const int s_etMapBit
int timeslices() const
void setDaqOverflow(int bit=1)
Set DAQ FIFO Overflow bit in Sub-status word.
void setGlinkParity(int bit=1)
Set G-Link Parity bit in Sub-status word.
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.
bool unpackerNeutralParityError(int pin)
Unpack and test G-Link parity bit for given pin.
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)
STL class.
Definition index.py:1
setEventNumber uint32_t