CMS 3D CMS Logo

UCTCTP7RawData5BX.h
Go to the documentation of this file.
1 #ifndef UCTCTP7RawData5BX_hh
2 #define UCTCTP7RawData5BX_hh
3 
6 
8 public:
9  enum CaloType { EBEE = 0, HBHE, HF };
10 
11  // read-only constructor
12  UCTCTP7RawData5BX(const uint32_t* d) : myDataPtr(d) {
13  if (myDataPtr == nullptr) {
14  edm::LogError("UCTCTP7RawData5BX") << "You gave me a nullptr :<";
15  }
16  }
17  // read-write constructor, caller must allocate 192*5*sizeof(uint32_t) bytes
19  if (myDataPtr == nullptr) {
20  edm::LogError("UCTCTP7RawData5BX") << "You gave me a nullptr :<";
21  }
22  }
23 
24  // No copy constructor and equality operator are needed
25  UCTCTP7RawData5BX(const UCTCTP7RawData5BX&) = delete;
26  const UCTCTP7RawData5BX& operator=(const UCTCTP7RawData5BX& i) = delete;
27 
28  virtual ~UCTCTP7RawData5BX() { ; }
29 
30  // Access functions for convenience
31 
32  const uint32_t* dataPtr() const { return myDataPtr; }
33 
34  uint32_t sof() { return myDataPtr[0]; }
35 
36  size_t getIndex(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
37  size_t index = 0;
38  if (cType == EBEE || cType == HBHE) {
39  if (iPhi > 3) {
40  edm::LogError("UCTCTP7RawData5BX") << "Incorrect iPhi; iPhi = " << iPhi << "; should be in [0,3]";
41  return index;
42  }
43  if (cEta < 1 || cEta > 28) {
44  edm::LogError("UCTCTP7RawData5BX") << "Incorrect caloEta; cEta = " << cEta << "; should be in [1-28]";
45  return index;
46  }
47  // ECAL/HB+HE fragment size is 3 32-bit words
48  // Each fragment covers 2 eta and 4 phi towers
49  // All four phi towers are in one 32-bit word
50  // Even and odd eta are in neighboring 32-bit words
51  // Now each fragment contains 5 BX instead of just 1
52  // Here BX_n = 0, 1, 2, 3, 4, where 2 is nominal
53  index = (((cEta - 1) / 2) * (3 + 3) * 5 + ((cEta - 1) % 2)) + 3 * BX_n;
54  // But, towers are arranged in a peculiar order for firmware
55  // convenience - the index needs to be computing with these
56  // if statements. This is brittle code that one should be
57  // very careful with.
58  if (negativeEta) {
59  // Add offset for 6 ECAL and 6 HCAL fragments
60  index += (6 * (3 + 3)) * 5;
61  } else {
62  if (cEta > 12) {
63  // Add offset for 14 ECAL, 14 HB+HE and 2 HF fragments
64  // Note that first six are included in the definition of
65  // the variable - index
66  // Note also that HF fragments are larger at 4 32-bit words
67  index += ((14 * (3 + 3) + (2 * 4))) * 5;
68  }
69  }
70  // Data starts with ECAL towers so offset by 3 additional 32-bit words
71  if (cType == HBHE)
72  index += 3 * 5;
73  } else if (cType == HF) {
74  if (iPhi > 1) {
75  edm::LogError("UCTCTP7RawData5BX") << "HF iPhi should be 0 or 1 (for a , b) - invalid iPhi = " << iPhi;
76  return index;
77  }
78  if (cEta < 30 || cEta > 41) {
79  edm::LogError("UCTCTP7RawData5BX") << "HF cEta should be between 30 and 41 - invalid cEta = " << cEta;
80  return index;
81  }
82  if (negativeEta) {
83  if (iPhi == 0) {
84  // Offset by 6 positive eta and 14 negative eta EBEE/HBHE fragments (each 3 32-bit words)
85  // There are four HF cEta towers packed in each 32-bit word
86  // Add additional offset of 1 for (34-37) and 2 for (38-41)
87  index = 20 * (3 + 3) * 5 + ((cEta - 30) / 4) + 4 * BX_n;
88  } else {
89  // Additional HF a fragment offset for HF b channel
90  index = 20 * (3 + 3) * 5 + 1 * 4 * 5 + ((cEta - 30) / 4) + 4 * BX_n;
91  }
92  } else {
93  if (iPhi == 0) {
94  // Offset by all EBEE/HBHE and two HF fragments (4 32-bit words)
95  index = 2 * 14 * (3 + 3) * 5 + 2 * 4 * 5 + ((cEta - 30) / 4) + 4 * BX_n;
96  } else {
97  // Additional HF a fragment offset for HF b channel
98  index = 2 * 14 * (3 + 3) * 5 + 3 * 4 * 5 + ((cEta - 30) / 4) + 4 * BX_n;
99  }
100  }
101  } else {
102  edm::LogError("UCTCTP7RawData5BX") << "Unknown CaloType " << cType;
103  return index;
104  }
105  if (index >= 192 * 5) {
106  edm::LogError("UCTCTP7RawData5BX") << "Managed to calculate an out-of-bounds index, buyer beware";
107  }
108  return index;
109  }
110 
111  size_t getFeatureIndex(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
112  // Get index into the data words for the tower
113  size_t index = getIndex(cType, negativeEta, cEta, iPhi, BX_n);
114  if (cType == EBEE || cType == HBHE) {
115  // Two 32-bit words contain ET, so we should offset the index to
116  // to the feature and link status bits
117  if (((cEta - 1) % 2) == 0) {
118  // [index] is offset to ET of first four towers (0 - 3)
119  // [index + 2] is where the feature and link status bits are
120  index += 2;
121  } else {
122  // In this case [index] is offset to ET of second four towers (4 - 7)
123  // [index + 1] is where the feature and link status bits are
124  index += 1;
125  }
126  } else if (cType == HF) {
127  // HF Fragment has different structure than EBEE and HBHE fragments
128  // First three 32-bit words have ETs for 11 objects (yes, 11 not 12)
129  // cEta = 40 / 41 are double in eta and flop bettween a and b HF fragments
130  // Further the remaining upper byte of the third word actually has feature
131  // bits. This feature index will point to the 4th 32-bit word. It is
132  // expected that the top byte from 3rd 32-bit word will be patched in within
133  // the feature bit access function.
134  // Since there are three instead of if block as above for EBEE, HBHE
135  // I wrote here a more compact implementation of index computation.
136  index += (3 - ((cEta - 30) / 4));
137  if (index == 0) {
138  // Since we sticth index-1, zero is also illegal
139  edm::LogError("UCTCTP7RawData5BX") << "Managed to calculate an out-of-bounds index, buyer beware";
140  }
141  } else {
142  // Unknown calotype error already generated in getIndex()
143  return 0;
144  }
145  if (index >= 192 * 5) {
146  edm::LogError("UCTCTP7RawData5BX") << "Managed to calculate an out-of-bounds index, buyer beware";
147  }
148  return index;
149  }
150 
151  void setET(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t et, uint32_t BX_n) {
152  if (myDataWritePtr == nullptr) {
153  edm::LogError("UCTCTP7RawData5BX") << "I was made in read-only mode";
154  return;
155  }
156  size_t index = getIndex(cType, negativeEta, cEta, iPhi, BX_n);
157  uint32_t& data = myDataWritePtr[index];
158  if (cType == HF) {
159  // Pick out the correct 8-bits for the iEta chosen
160  // Note that cEta = 41 is special, it only occurs for iPhi == 1 and shares cEta = 40 position
161  if (cEta == 41) {
162  data |= (et & 0xFF) << 16;
163  } else {
164  data |= (et & 0xFF) << (((cEta - 30) % 4) * 8);
165  }
166  } else {
167  // Pick out the correct 8-bits for the iPhi chosen
168  data |= (et & 0xFF) << (iPhi * 8);
169  }
170  }
171 
172  uint32_t getET(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
173  size_t index = getIndex(cType, negativeEta, cEta, iPhi, BX_n);
174  const uint32_t data = myDataPtr[index];
175  uint32_t et = 0xDEADBEEF;
176  if (cType == HF) {
177  // Pick out the correct 8-bits for the iEta chosen
178  // Note that cEta = 41 is special, it only occurs for iPhi == 1 and shares cEta = 40 position
179  if (cEta == 41)
180  et = ((data >> 16) & 0xFF);
181  else
182  et = ((data >> ((cEta - 30) % 4) * 8) & 0xFF);
183  } else {
184  // Pick out the correct 8-bits for the iPhi chosen
185  et = ((data >> (iPhi * 8)) & 0xFF);
186  }
187  return et;
188  }
189 
190  void setFB(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t fb, uint32_t BX_n) {
191  if (myDataWritePtr == nullptr) {
192  edm::LogError("UCTCTP7RawData5BX") << "I was made in read-only mode";
193  return;
194  }
195  if (cType == HF) {
196  setHFFeatureBits(negativeEta, cEta, iPhi, fb, BX_n);
197  } else {
198  size_t index = getFeatureIndex(cType, negativeEta, cEta, iPhi, BX_n);
199  uint32_t& data = myDataWritePtr[index];
200 
201  uint32_t tower = iPhi;
202  if (((cEta - 1) % 2) == 1) {
203  tower += 4;
204  }
205  data |= (fb & 0x1) << tower;
206  }
207  }
208 
209  uint32_t getFB(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
210  size_t index = getFeatureIndex(cType, negativeEta, cEta, iPhi, BX_n);
211  const uint32_t data = myDataPtr[index];
212  uint32_t fb = 0;
213  if (cType == HF) {
214  fb = getHFFeatureBits(negativeEta, cEta, iPhi, BX_n);
215  } else {
216  // Pick out the correct bit for the tower chosen
217  uint32_t tower = iPhi;
218  if (((cEta - 1) % 2) == 1) {
219  tower += 4;
220  }
221  fb = ((data & (0x1 << tower)) != 0) ? 1 : 0;
222  }
223  return fb;
224  }
225 
226  void setHFFeatureBits(bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t fb, uint32_t BX_n) {
227  if (myDataWritePtr == nullptr) {
228  edm::LogError("UCTCTP7RawData5BX") << "I was made in read-only mode";
229  return;
230  }
231  size_t index = getFeatureIndex(HF, negativeEta, cEta, iPhi, BX_n);
232  uint32_t shift = (cEta - 30) * 2;
233  if (cEta == 41)
234  shift = 20; // 41 occurs on b-fiber but shares the position of 40
235  if (shift >= 8) {
236  uint32_t& data = myDataWritePtr[index];
237  data |= (fb & 0x3) << (shift - 8);
238  } else {
239  uint32_t& data = myDataWritePtr[index - 1];
240  data |= (fb & 0x3) << (shift + 24);
241  }
242  }
243 
244  uint32_t getHFFeatureBits(bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
245  size_t index = getFeatureIndex(HF, negativeEta, cEta, iPhi, BX_n);
246  // Stitch together the top 8 bits from previous 32-bit word and bottom 14 bits from this word
247  const uint32_t data = ((myDataPtr[index] & 0x3FFF) << 8) + (myDataPtr[index - 1] >> 24);
248  uint32_t shift = (cEta - 30) * 2;
249  if (cEta == 41)
250  shift = 20; // 41 occurs on b-fiber but shares the position of 40
251  return ((data >> shift) & 0x3);
252  }
253 
254  uint32_t getLinkStatus(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
255  size_t index = getFeatureIndex(cType, negativeEta, cEta, iPhi, BX_n);
256  const uint32_t data = myDataPtr[index];
257  return (data >> 16);
258  }
259 
260  size_t getSummaryIndex(bool negativeEta, uint32_t region, uint32_t BX_n) {
261  size_t index = 2 * 14 * (3 + 3) * 5 + 4 * 4 * 5 + (region / 2) + 4 * BX_n;
262  if (negativeEta)
263  index += 4 * 5;
264  if (index >= 192 * 5) {
265  edm::LogError("UCTCTP7RawData5BX") << "Managed to calculate an out-of-bounds index, buyer beware";
266  }
267  return index;
268  }
269 
270  void setRegionSummary(bool negativeEta, uint32_t region, uint32_t regionData, uint32_t BX_n) {
271  if (myDataWritePtr == nullptr) {
272  edm::LogError("UCTCTP7RawData5BX") << "I was made in read-only mode";
273  return;
274  }
275  size_t index = getSummaryIndex(negativeEta, region, BX_n);
276  uint32_t& data = myDataWritePtr[index];
277  data |= (regionData & 0xFFFF) << (16 * (region % 2));
278  }
279 
280  uint32_t getRegionSummary(bool negativeEta, uint32_t region, uint32_t BX_n) {
281  size_t index = getSummaryIndex(negativeEta, region, BX_n);
282  const uint32_t data = myDataPtr[index];
283  return ((data >> (16 * (region % 2))) & 0xFFFF);
284  }
285 
286  uint32_t getRegionET(bool negativeEta, uint32_t region, uint32_t BX_n) {
287  return (getRegionSummary(negativeEta, region, BX_n) & 0x3FF);
288  }
289 
290  bool getRegionEGVeto(bool negativeEta, uint32_t region, uint32_t BX_n) {
291  return (getRegionSummary(negativeEta, region, BX_n) & 0x0400);
292  }
293 
294  bool getRegionTauVeto(bool negativeEta, uint32_t region, uint32_t BX_n) {
295  return (getRegionSummary(negativeEta, region, BX_n) & 0x0800);
296  }
297 
298  uint32_t getRegionHitLocation(bool negativeEta, uint32_t region, uint32_t BX_n) {
299  return ((getRegionSummary(negativeEta, region, BX_n) & 0xF000) >> 12);
300  }
301 
302  bool isTowerMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
303  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi, BX_n);
304  uint32_t tower = iPhi;
305  if ((cEta % 2) == 0)
306  tower += 4;
307  if (cType == HF) {
308  tower = (cEta - 30);
309  if (cEta == 41)
310  tower = 10;
311  }
312  return ((linkStatus & (0x1 << tower)) != 0);
313  }
314 
315  bool isLinkMisaligned(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
316  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi, BX_n);
317  if (cType == EBEE && (cEta == 17 || cEta == 21)) {
318  return ((linkStatus & 0x00000100) != 0);
319  }
320  return ((linkStatus & 0x00001000) != 0);
321  }
322 
323  bool isLinkInError(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
324  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi, BX_n);
325  if (cType == EBEE && (cEta == 17 || cEta == 21)) {
326  return ((linkStatus & 0x00000200) != 0);
327  }
328  return ((linkStatus & 0x00002000) != 0);
329  }
330 
331  bool isLinkDown(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
332  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi, BX_n);
333  if (cType == EBEE && (cEta == 17 || cEta == 21)) {
334  return ((linkStatus & 0x00000400) != 0);
335  }
336  return ((linkStatus & 0x00004000) != 0);
337  }
338 
339  bool isLinkMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n) {
340  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi, BX_n);
341  if (cType == EBEE && (cEta == 17 || cEta == 21)) {
342  return ((linkStatus & 0x00000800) != 0);
343  }
344  return ((linkStatus & 0x00008000) != 0);
345  }
346 
347 private:
348  // Pointer to contiguous array of 192*5 values
349  // We assume instantiator of this class will gurantee that fact
350  const uint32_t* myDataPtr;
351  // == myDataPtr unless read-only
352  uint32_t* myDataWritePtr = nullptr;
353 };
354 
355 #endif
const uint32_t * dataPtr() const
uint32_t getFB(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
const uint32_t * myDataPtr
size_t getFeatureIndex(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
uint32_t getLinkStatus(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
void setET(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t et, uint32_t BX_n)
uint32_t getRegionET(bool negativeEta, uint32_t region, uint32_t BX_n)
Log< level::Error, false > LogError
bool isLinkInError(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
void setHFFeatureBits(bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t fb, uint32_t BX_n)
uint32_t getRegionSummary(bool negativeEta, uint32_t region, uint32_t BX_n)
UCTCTP7RawData5BX(const uint32_t *d)
uint32_t getRegionHitLocation(bool negativeEta, uint32_t region, uint32_t BX_n)
size_t getIndex(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
bool getRegionEGVeto(bool negativeEta, uint32_t region, uint32_t BX_n)
uint32_t getET(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
bool getRegionTauVeto(bool negativeEta, uint32_t region, uint32_t BX_n)
d
Definition: ztail.py:151
uint32_t getHFFeatureBits(bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
virtual ~UCTCTP7RawData5BX()
size_t getSummaryIndex(bool negativeEta, uint32_t region, uint32_t BX_n)
bool isLinkDown(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static unsigned int const shift
bool isLinkMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
bool isTowerMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
void setRegionSummary(bool negativeEta, uint32_t region, uint32_t regionData, uint32_t BX_n)
UCTCTP7RawData5BX(uint32_t *d)
bool isLinkMisaligned(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t BX_n)
void setFB(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t fb, uint32_t BX_n)
const UCTCTP7RawData5BX & operator=(const UCTCTP7RawData5BX &i)=delete