CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
UCTCTP7RawData.h
Go to the documentation of this file.
1 #ifndef UCTCTP7RawData_hh
2 #define UCTCTP7RawData_hh
3 
6 using namespace edm;
7 
8 
10 public:
11 
12  enum CaloType {EBEE=0, HBHE, HF};
13 
14  UCTCTP7RawData(const uint32_t *d) : myDataPtr(d) {
15  if(myDataPtr != 0) {
16  if(sof() != 0xA110CA7E) {
17  LogError("UCTCTP7RawData") << "Failed to see 0xA110CA7E at start - but continuing" << std::endl;
18  }
19  }
20  }
21 
22  virtual ~UCTCTP7RawData() {;}
23 
24  // Access functions for convenience
25 
26  const uint32_t *dataPtr() const {return myDataPtr;}
27 
28  uint32_t sof() {return myDataPtr[0];}
29 
30  uint32_t caloLinkBXID() {return (myDataPtr[1] & 0x00000FFF);}
31 
32  uint32_t nBXPerL1A() {return ((myDataPtr[1] & 0x000F0000) >> 16);}
33 
34  uint32_t getIndex(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
35  uint32_t index = 0xDEADBEEF;
36  if(cType == EBEE || cType == HBHE) {
37  if(iPhi > 3) {
38  LogError("UCTCTP7RawData") << "Incorrect iPhi; iPhi = " << iPhi << "; should be in [0,3]" << std::endl;
39  return 0xDEADBEEF;
40  }
41  if(cEta < 1 || cEta > 28) {
42  LogError("UCTCTP7RawData") << "Incorrect caloEta; cEta = " << cEta << "; should be in [1-28]" << std::endl;
43  return 0xDEADBEEF;
44  }
45  // ECAL/HB+HE fragment size is 3 32-bit words
46  // Each fragment covers 2 eta and 4 phi towers
47  // All four phi towers are in one 32-bit word
48  // Even and odd eta are in neighboring 32-bit words
49  index = 2 + ( ((cEta - 1) / 2) * (3 + 3) + ((cEta - 1) % 2) );
50  // But, towers are arranged in a peculiar order for firmware
51  // convenience - the index needs to be computing with these
52  // if statements. This is brittle code that one should be
53  // very careful with.
54  if(negativeEta) {
55  // Add offset for 6 ECAL and 6 HCAL fragments
56  index += (6 * (3 + 3));
57  }
58  else {
59  if(cEta > 12) {
60  // Add offset for 14 ECAL, 14 HB+HE and 2 HF fragments
61  // Note that first six are included in the definition of
62  // the variable - index
63  // Note also that HF fragments are larger at 4 32-bit words
64  index += ((14 * (3 + 3) + (2 * 4)));
65  }
66  }
67  // Data starts with ECAL towers so offset by 3 additional 32-bit words
68  if(cType == HBHE) index += 3;
69  }
70  else if(cType == HF) {
71  if(iPhi > 1) {
72  LogError("UCTCTP7RawData") << "HF iPhi should be 0 or 1 (for a , b) - invalid iPhi = " << iPhi << std::endl;
73  return 0xDEADBEEF;
74  }
75  if(cEta < 30 || cEta > 41) {
76  LogError("UCTCTP7RawData") << "HF cEta should be between 30 and 41 - invalid cEta = " << cEta << std::endl;
77  return 0xDEADBEEF;
78  }
79  if(negativeEta) {
80  if(iPhi == 0) {
81  // Offset by 6 positive eta and 14 negative eta EBEE/HBHE fragments (each 3 32-bit words)
82  // There are four HF cEta towers packed in each 32-bit word
83  // Add additional offset of 1 for (34-37) and 2 for (38-41)
84  index = 2 + 20 * (3 + 3) + ((cEta - 30) / 4);
85  }
86  else {
87  // Additional HF a fragment offset for HF b channel
88  index = 2 + 20 * (3 + 3) + 1 * 4 + ((cEta - 30) / 4);
89  }
90  }
91  else {
92  if(iPhi == 0) {
93  // Offset by all EBEE/HBHE and two HF fragments (4 32-bit words)
94  index = 2 + 2 * 14 * (3 + 3) + 2 * 4 + ((cEta - 30) / 4);
95  }
96  else {
97  // Additional HF a fragment offset for HF b channel
98  index = 2 + 2 * 14 * (3 + 3) + 3 * 4 + ((cEta - 30) / 4);
99  }
100  }
101  }
102  else {
103  LogError("UCTCTP7RawData") << "Unknown CaloType " << cType << std::endl;
104  return 0xDEADBEEF;
105  }
106  return index;
107  }
108 
109  uint32_t getFeatureIndex(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
110  // Get index into the data words for the tower
111  uint32_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  }
120  else {
121  // In this case [index] is offset to ET of second four towers (4 - 7)
122  // [index + 1] is where the feature and link status bits are
123  index += 1;
124  }
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  }
138  else {
139  return 0xDEADBEEF;
140  }
141  return index;
142  }
143 
144  uint32_t getET(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
145  uint32_t index = getIndex(cType, negativeEta, cEta, iPhi);
146  const uint32_t data = myDataPtr[index];
147  uint32_t et = 0xDEADBEEF;
148  if(cType == HF) {
149  // Pick out the correct 8-bits for the iEta chosen
150  // Note that cEta = 41 is special, it only occurs for iPhi == 1 and shares cEta = 40 position
151  if(cEta == 41) et = ((data >> 16) & 0xFF);
152  else et = ((data >> ((cEta - 30) % 4) * 8) & 0xFF);
153  }
154  else {
155  // Pick out the correct 8-bits for the iPhi chosen
156  et = ((data >> (iPhi * 8)) & 0xFF);
157  }
158  return et;
159  }
160 
161  bool getFB(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
162  uint32_t index = getFeatureIndex(cType, negativeEta, cEta, iPhi);
163  const uint32_t data = myDataPtr[index];
164  bool fb = false;
165  if(cType == HF) {
166  // Two bits are expected from HF - this is interface to get one compressed bit!
167  fb = (getHFFeatureBits(negativeEta, cEta, iPhi) != 0);
168  }
169  else {
170  // Pick out the correct bit for the tower chosen
171  uint32_t tower = iPhi;
172  if(((cEta - 1) % 2) == 1) {
173  tower += 4;
174  }
175  fb = ((data & (0x1 << tower)) != 0);
176  }
177  return fb;
178  }
179 
180  uint32_t getHFFeatureBits(bool negativeEta, uint32_t cEta, uint32_t iPhi) {
181  uint32_t index = getFeatureIndex(HF, negativeEta, cEta, iPhi);
182  // Stitch together the top 8 bits from previous 32-bit word and bottom 14 bits from this word
183  const uint32_t data = ((myDataPtr[index] & 0x3FFF) << 8) + (myDataPtr[index - 1] >> 24);
184  uint32_t shift = (cEta - 30) * 2;
185  if(cEta == 41) shift = 20; // 41 occurs on b-fiber but shares the position of 40
186  return ((data >> shift) & 0x3);
187  }
188 
189  uint32_t getLinkStatus(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
190  uint32_t index = getFeatureIndex(cType, negativeEta, cEta, iPhi);
191  const uint32_t data = myDataPtr[index];
192  return (data >> 16);
193  }
194 
195  bool isTowerMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
196  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi);
197  uint32_t tower = iPhi;
198  if(((cEta - 1) % 2) == 1) tower += 4;
199  if(cType == HF) {
200  tower = (cEta - 30);
201  if(cEta == 41) tower = 10;
202  }
203  return ((linkStatus & (0x1 << tower)) != 0);
204  }
205 
206  bool isLinkMisaligned(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
207  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi);
208  return ((linkStatus & 0x00001000) != 0);
209  }
210 
211  bool isLinkInError(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
212  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi);
213  return ((linkStatus & 0x00002000) != 0);
214  }
215 
216  bool isLinkDown(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
217  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi);
218  return ((linkStatus & 0x00004000) != 0);
219  }
220 
221  bool isLinkMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi) {
222  uint32_t linkStatus = getLinkStatus(cType, negativeEta, cEta, iPhi);
223  return ((linkStatus & 0x00008000) != 0);
224  }
225 
226  void print() {
227  using namespace std;
228  cout << "CTP7 Payload Header:" << endl;
229  cout << "No BX per L1A = " << dec << nBXPerL1A() << endl;
230  cout << "Calo BX ID = " << dec << caloLinkBXID() << endl;
231  CaloType cType = EBEE;
232  bool negativeEta = false;
233  bool first = true;
234  for(uint32_t i = 0; i < 2; i++) {
235  if(i != 0) negativeEta = true;
236  first = true;
237  cType = EBEE;
238  for(uint32_t cEta = 1; cEta <= 28; cEta++) {
239  for(uint32_t iPhi = 0; iPhi < 4; iPhi++) {
240  if(getLinkStatus(cType, negativeEta, cEta, iPhi) != 0 ||
241  getET(cType, negativeEta, cEta, iPhi) != 0) {
242  if(first) cout << "EcalET FG LinkStatus" << endl;
243  first = false;
244  cout << dec << setfill(' ') << setw(6) << getET(cType, negativeEta, cEta, iPhi) << " "
245  << getFB(cType, negativeEta, cEta, iPhi) << " "
246  << showbase << internal << setfill('0') << setw(10) << hex << getLinkStatus(cType, negativeEta, cEta, iPhi)
247  << " (" << dec << getIndex(cType, negativeEta, cEta, iPhi) << ", " << negativeEta << ", " << cEta << ", " << iPhi << ")"
248  << endl;
249  }
250  }
251  }
252  first = true;
253  cType = HBHE;
254  for(uint32_t cEta = 1; cEta <= 28; cEta++) {
255  for(uint32_t iPhi = 0; iPhi < 4; iPhi++) {
256  if(getLinkStatus(cType, negativeEta, cEta, iPhi) != 0 ||
257  getET(cType, negativeEta, cEta, iPhi) != 0) {
258  if(first) cout << "HcalET Feature LinkStatus" << endl;
259  first = false;
260  cout << dec << setfill(' ') << setw(6) << getET(cType, negativeEta, cEta, iPhi) << " "
261  << getFB(cType, negativeEta, cEta, iPhi) << " "
262  << showbase << internal << setfill('0') << setw(10) << hex << getLinkStatus(cType, negativeEta, cEta, iPhi)
263  << " (" << dec << getIndex(cType, negativeEta, cEta, iPhi) << ", " << negativeEta << ", " << cEta << ", " << iPhi << ")"
264  << endl;
265  }
266  }
267  }
268  first = true;
269  cType = HF;
270  for(uint32_t cEta = 30; cEta <= 40; cEta++) {
271  for(uint32_t iPhi = 0; iPhi < 2; iPhi++) {
272  if(iPhi == 1 && cEta == 40) cEta = 41;
273  if(getLinkStatus(cType, negativeEta, cEta, iPhi) != 0 ||
274  getET(cType, negativeEta, cEta, iPhi) != 0) {
275  if(first) cout << "HF-ET Feature LinkStatus" << endl;
276  first = false;
277  cout << dec << setfill(' ') << setw(6) << getET(cType, negativeEta, cEta, iPhi) << " "
278  << dec << setfill(' ') << setw(2) << getHFFeatureBits(negativeEta, cEta, iPhi) << " "
279  << showbase << internal << setfill('0') << setw(10) << hex << getLinkStatus(cType, negativeEta, cEta, iPhi)
280  << " (" << dec << getIndex(cType, negativeEta, cEta, iPhi) << ", " << negativeEta << ", " << cEta << ", " << iPhi << ")"
281  << endl;
282  }
283  }
284  }
285  }
286  }
287 
288 private:
289 
290  // No copy constructor and equality operator are needed
291 
293  const UCTCTP7RawData& operator=(const UCTCTP7RawData& i);
294 
295  // RawData data
296 
297  const uint32_t* myDataPtr;
298 
299 };
300 
301 #endif
int i
Definition: DBlmapReader.cc:9
uint32_t getHFFeatureBits(bool negativeEta, uint32_t cEta, uint32_t iPhi)
uint32_t caloLinkBXID()
bool isLinkMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
uint32_t sof()
const uint32_t * myDataPtr
bool isLinkDown(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
int const HF
Definition: Constants.h:86
tuple d
Definition: ztail.py:151
uint32_t nBXPerL1A()
bool isLinkInError(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
bool isTowerMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
uint32_t getLinkStatus(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
uint32_t getIndex(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
UCTCTP7RawData(const uint32_t *d)
uint32_t getET(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool getFB(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
const uint32_t * dataPtr() const
static unsigned int const shift
tuple cout
Definition: gather_cfg.py:145
virtual ~UCTCTP7RawData()
T first(std::pair< T, U > const &p)
uint32_t getFeatureIndex(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
bool isLinkMisaligned(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)