ATLAS Offline Software
Loading...
Searching...
No Matches
CmmCpSubBlock.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 "CmmCpSubBlock.h"
7
8namespace LVL1BS {
9
10// Constant definitions
11
13
23
29
30
34
38
39// Clear all data
40
42{
44 m_hitsData.clear();
45}
46
47// Return hit counts for given CPM or source ID
48
49unsigned int CmmCpSubBlock::hits(const int slice, int source) const
50{
51 --source;
52 unsigned int hits = 0;
53 if (slice >= 0 && slice < timeslices() &&
54 source >= 0 && source < s_maxHits && !m_hitsData.empty()) {
56 }
57 return hits;
58}
59
60// Return hit error for given CPM or source ID
61
62int CmmCpSubBlock::hitsError(const int slice, int source) const
63{
64 --source;
65 int error = 0;
66 if (slice >= 0 && slice < timeslices() &&
67 source >= 0 && source < s_maxHits && !m_hitsData.empty()) {
70 }
71 return error;
72}
73
74// Store hit counts for given CPM or source ID
75
76void CmmCpSubBlock::setHits(const int slice, int source,
77 const unsigned int hits, const int error)
78{
79 --source;
80 if (slice >= 0 && slice < timeslices() &&
81 source >= 0 && source < s_maxHits && (hits || error)) {
82 resize();
83 uint32_t word = m_hitsData[index(slice, source)];
84 word |= (hits & s_threshMask) << s_threshBit;
85 word |= (error & s_errorMask) << s_threshErrorBit;
86 word |= (source & s_sourceIdMask) << s_sourceIdBit;
87 word |= (s_dataWordId) << s_dataWordIdBit;
88 m_hitsData[index(slice, source)] = word;
89 }
90}
91
92// Packing/Unpacking routines
93
95{
96 bool rc = false;
97 switch (version()) {
98 case 1:
99 switch (format()) {
100 case NEUTRAL:
101 rc = packNeutral();
102 break;
103 case UNCOMPRESSED:
105 break;
106 default:
107 break;
108 }
109 break;
110 default:
111 break;
112 }
113 return rc;
114}
115
117{
118 bool rc = false;
119 switch (version()) {
120 case 1:
121 switch (format()) {
122 case NEUTRAL:
123 rc = unpackNeutral();
124 break;
125 case UNCOMPRESSED:
127 break;
128 default:
130 break;
131 }
132 break;
133 default:
135 break;
136 }
137 return rc;
138}
139
140// Return data index appropriate to format
141
142int CmmCpSubBlock::index(const int slice, const int source) const
143{
144 int ix = source;
145 if (format() == NEUTRAL) ix += slice * s_maxHits;
146 return ix;
147}
148
149// Resize the hits vector according to format
150
152{
153 if (m_hitsData.empty()) {
154 int size = s_maxHits;
155 if (format() == NEUTRAL) size *= timeslices();
156 m_hitsData.resize(size);
157 }
158}
159
160// Pack neutral data
161
163{
164 resize();
165 const int slices = timeslices();
166 for (int slice = 0; slice < slices; ++slice) {
167 for (int source = 1; source < MAX_SOURCE_ID; ++source) {
168 const int pin = source - 1;
169 // CPM hits; remote(3), local and total hits; parity error
170 packerNeutral(pin, hits(slice, source), s_hitsBits);
172 // Bunch crossing number; Fifo overflow
173 if (pin < s_bunchCrossingBits) {
174 packerNeutral(pin, bunchCrossing() >> pin, 1);
175 } else if (pin == s_fifoOverflowPin) {
176 packerNeutral(pin, daqOverflow(), 1);
177 } else packerNeutral(pin, 0, 1);
178 // Padding
180 // G-Link parity
182 }
183 }
184 return true;
185}
186
187// Pack uncompressed data
188
190{
191 std::vector<uint32_t>::const_iterator pos;
192 for (pos = m_hitsData.begin(); pos != m_hitsData.end(); ++pos) {
193 if (*pos) packer(*pos, s_wordLength);
194 }
195 packerFlush();
196 return true;
197}
198
199// Unpack neutral data
200
202{
203 resize();
204 int bunchCrossing = 0;
205 int overflow = 0;
206 int parity = 0;
207 const int slices = timeslices();
208 for (int slice = 0; slice < slices; ++slice) {
209 for (int source = 1; source < MAX_SOURCE_ID; ++source) {
210 const int pin = source - 1;
211 // CPM hits; remote(3), local and total hits; parity error
212 const unsigned int hits = unpackerNeutral(pin, s_hitsBits);
213 const int error = unpackerNeutral(pin, s_hitsErrorBits);
214 setHits(slice, source, hits, error);
215 // Bunch crossing number; Fifo overflow
216 if (pin < s_bunchCrossingBits) {
217 bunchCrossing |= unpackerNeutral(pin, 1) << pin;
218 } else if (pin == s_fifoOverflowPin) {
219 overflow |= unpackerNeutral(pin, 1);
220 } else unpackerNeutral(pin, 1);
221 // Padding
223 // G-Link parity errors
224 parity |= unpackerNeutralParityError(pin);
225 }
226 }
228 setDaqOverflow(overflow);
229 setGlinkParity(parity);
230
231 const bool rc = unpackerSuccess();
233 return rc;
234}
235
236// Unpack uncompressed data
237
239{
240 resize();
241 unpackerInit();
242 uint32_t word = unpacker(s_wordLength);
243 while (unpackerSuccess()) {
244 const int source = sourceId(word);
245 if (source < s_maxHits && m_hitsData[source] == 0) m_hitsData[source] = word;
246 else {
248 return false;
249 }
250 word = unpacker(s_wordLength);
251 }
252 return true;
253}
254
255} // end namespace
static Double_t rc
static const int s_fifoOverflowPin
static const int s_sourceIdBit
static const int s_bunchCrossingBits
static const int s_maxHits
static const int s_paddingBits
static const uint32_t s_errorMask
static const int s_threshBit
static const int s_wordLength
Data word length.
bool unpackNeutral()
Unpack neutral data.
static const int s_hitsBits
static const int s_dataWordIdBit
static const int s_threshErrorBit
bool unpack()
Unpack data.
void clear()
Clear all data.
static const int s_dataWordId
int index(int slice, int source) const
unsigned int hits(int slice, int source) const
Return hit counts for given CPM or source ID.
void setHits(int slice, int source, unsigned int hits, int error)
Store hit counts for given CPM or source ID.
static const int s_hitsErrorBits
bool unpackUncompressed()
Unpack uncompressed data.
static const uint32_t s_threshMask
int hitsError(int slice, int source) const
Return hit error for given CPM or source ID.
bool packNeutral()
Pack neutral data.
std::vector< uint32_t > m_hitsData
CPM hits and sums data.
bool packUncompressed()
Pack uncompressed data.
int sourceId(uint32_t word) const
static const uint32_t s_sourceIdMask
bool pack()
Pack data.
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)
Definition index.py:1
setEventNumber uint32_t