CMS 3D CMS Logo

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