CMS 3D CMS Logo

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