CMS 3D CMS Logo

HcalLogicalMapGenerator.cc
Go to the documentation of this file.
7 
8 #include <string>
9 #include <sstream>
10 #include <cstdio>
11 #include <iostream>
12 #include <cstring>
13 
14 using namespace std;
15 
16 /***************************************/
17 
19  //adc and qie table; qie is entry 0, adc is entry 1. Constant across HB, HE, HO
20  // int iadcquiHBHE[NRMFIBR][NFCH][2];
21 
22  for (i = 0; i < NRMFIBR; i++) {
23  for (j = 0; j < NFCH; j++) {
24  //Intentionally relying on integer truncation here
25  iadcquiHBHE[i][j][0] = i / 2 + 1;
26 
27  if (i % 2 == 0)
28  iadcquiHBHE[i][j][1] = j;
29  else
30  iadcquiHBHE[i][j][1] = NFCH + (j + 1) % 3;
31  }
32  }
33 }
34 
36 
38  mapIOV_ = mapIOV;
39 
40  std::vector<HBHEHFLogicalMapEntry> HBHEHFEntries;
41  std::vector<HOHXLogicalMapEntry> HOHXEntries;
42  std::vector<CALIBLogicalMapEntry> CALIBEntries;
43  std::vector<ZDCLogicalMapEntry> ZDCEntries;
44  std::vector<HTLogicalMapEntry> HTEntries;
45  std::vector<uint32_t> LinearIndex2Entry;
46  std::vector<uint32_t> HbHash2Entry;
47  std::vector<uint32_t> HeHash2Entry;
48  std::vector<uint32_t> HfHash2Entry;
49  std::vector<uint32_t> HtHash2Entry;
50  std::vector<uint32_t> HoHash2Entry;
51  std::vector<uint32_t> HxCalibHash2Entry;
52  //std::vector <uint32_t> CalibHash2Entry;
53  std::vector<uint32_t> ZdcHash2Entry;
54 
55  int HbHalf = 1296;
56  int HeHalf = 1296;
57  //if (h2mode_) HeHalf = 4032;
58  int HoHalf = 1080;
59  int HfHalf = 864;
60  int HtHalf = 2088;
61  int ZdcHalf = 11;
62  int CalibFull = 216 + 425 + 8;
63 
64  uint32_t illegal_value = 0;
65  for (int i = 0; i <= HcalElectronicsId::maxLinearIndex; i++)
66  LinearIndex2Entry.push_back(illegal_value);
67  HbHash2Entry.reserve(2 * HbHalf);
68  for (int iHb = 0; iHb < 2 * HbHalf; iHb++)
69  HbHash2Entry.push_back(illegal_value);
70  HeHash2Entry.reserve(2 * HeHalf);
71  for (int iHe = 0; iHe < 2 * HeHalf; iHe++)
72  HeHash2Entry.push_back(illegal_value);
73  HfHash2Entry.reserve(2 * HfHalf);
74  for (int iHf = 0; iHf < 2 * HfHalf; iHf++)
75  HfHash2Entry.push_back(illegal_value);
76  HtHash2Entry.reserve(2 * HtHalf);
77  for (int iHt = 0; iHt < 2 * HtHalf; iHt++)
78  HtHash2Entry.push_back(illegal_value);
79  HoHash2Entry.reserve(2 * HoHalf);
80  for (int iHo = 0; iHo < 2 * HoHalf; iHo++)
81  HoHash2Entry.push_back(illegal_value);
82  HxCalibHash2Entry.reserve(CalibFull);
83  for (int iHcalib = 0; iHcalib < CalibFull; iHcalib++)
84  HxCalibHash2Entry.push_back(illegal_value);
85  ZdcHash2Entry.reserve(2 * ZdcHalf);
86  for (int iZdc = 0; iZdc < 2 * ZdcHalf; iZdc++)
87  ZdcHash2Entry.push_back(illegal_value);
88 
89  buildHBEFTMap(
90  topo, HBHEHFEntries, HTEntries, LinearIndex2Entry, HbHash2Entry, HeHash2Entry, HfHash2Entry, HtHash2Entry);
91  buildHOXMap(topo, HOHXEntries, LinearIndex2Entry, HoHash2Entry, HxCalibHash2Entry);
92  buildCALIBMap(topo, CALIBEntries, LinearIndex2Entry, HxCalibHash2Entry);
93  buildZDCMap(topo, ZDCEntries, LinearIndex2Entry, ZdcHash2Entry);
94 
95  return HcalLogicalMap(topo,
96  HBHEHFEntries,
97  HOHXEntries,
98  CALIBEntries,
99  ZDCEntries,
100  HTEntries,
101  LinearIndex2Entry,
102  HbHash2Entry,
103  HeHash2Entry,
104  HfHash2Entry,
105  HtHash2Entry,
106  HoHash2Entry,
107  HxCalibHash2Entry,
108  /*CalibHash2Entry,*/ ZdcHash2Entry);
109 }
110 
112  std::vector<HBHEHFLogicalMapEntry>& HBHEHFEntries,
113  std::vector<HTLogicalMapEntry>& HTEntries,
114  std::vector<uint32_t>& LinearIndex2Entry,
115  std::vector<uint32_t>& HbHash2Entry,
116  std::vector<uint32_t>& HeHash2Entry,
117  std::vector<uint32_t>& HfHash2Entry,
118  std::vector<uint32_t>& HtHash2Entry) {
119  /******************************/
120  /* HBHE crate numbering */
121  int hbhecrate_loc[NHBHECR] = {0, 1, 4, 5, 10, 11, 14, 15, 17};
122  memcpy(hbhecrate, hbhecrate_loc, sizeof(int) * NHBHECR);
123  /* HBHE FED numbering of DCCs */
124  int fedhbhenum_loc[NHBHECR][2] = {
125  {702, 703}, {704, 705}, {700, 701}, {706, 707}, {716, 717}, {708, 709}, {714, 715}, {710, 711}, {712, 713}};
126  memcpy(fedhbhenum, fedhbhenum_loc, sizeof(int) * NHBHECR * 2);
127  /* HBHE/HF htr slot offsets for set of three htrs */
128  int ihslot_loc[NHSETS] = {2, 5, 13, 16};
129  memcpy(ihslot, ihslot_loc, sizeof(int) * NHSETS);
130  /* iphi (lower) starting index for each HBHE crate */
131  int ihbhephis_loc[NHBHECR] = {11, 19, 3, 27, 67, 35, 59, 43, 51};
132  memcpy(ihbhephis, ihbhephis_loc, sizeof(int) * NHBHECR);
133  /* ihbheetadepth - unique HBHE {eta,depth} assignments per fiber and fiber channel */
134  int ihbheetadepth_loc[NHTRS][NTOPBOT][NFBR][NFCH][2] = {{{{{11, 1}, {7, 1}, {3, 1}}, /* htr 0 (HB) -bot(+top) */
135  {{5, 1}, {1, 1}, {9, 1}},
136  {{11, 1}, {7, 1}, {3, 1}},
137  {{5, 1}, {1, 1}, {9, 1}},
138  {{10, 1}, {6, 1}, {2, 1}},
139  {{8, 1}, {4, 1}, {12, 1}},
140  {{10, 1}, {6, 1}, {2, 1}},
141  {{8, 1}, {4, 1}, {12, 1}}},
142  {{{11, 1}, {7, 1}, {3, 1}}, /* htr 0 (HB) +bot(-top) */
143  {{5, 1}, {1, 1}, {9, 1}},
144  {{11, 1}, {7, 1}, {3, 1}},
145  {{5, 1}, {1, 1}, {9, 1}},
146  {{10, 1}, {6, 1}, {2, 1}},
147  {{8, 1}, {4, 1}, {12, 1}},
148  {{10, 1}, {6, 1}, {2, 1}},
149  {{8, 1}, {4, 1}, {12, 1}}}},
150  {{{{16, 2}, {15, 2}, {14, 1}}, /* htr 1 (HBHE) -bot(+top) */
151  {{15, 1}, {13, 1}, {16, 1}},
152  {{16, 2}, {15, 2}, {14, 1}},
153  {{15, 1}, {13, 1}, {16, 1}},
154  {{17, 1}, {16, 3}, {26, 1}},
155  {{18, 1}, {18, 2}, {26, 2}},
156  {{17, 1}, {16, 3}, {25, 1}},
157  {{18, 1}, {18, 2}, {25, 2}}},
158  {{{16, 2}, {15, 2}, {14, 1}}, /* htr 1 (HBHE) +bot(-top) */
159  {{15, 1}, {13, 1}, {16, 1}},
160  {{16, 2}, {15, 2}, {14, 1}},
161  {{15, 1}, {13, 1}, {16, 1}},
162  {{17, 1}, {16, 3}, {25, 1}},
163  {{18, 1}, {18, 2}, {25, 2}},
164  {{17, 1}, {16, 3}, {26, 1}},
165  {{18, 1}, {18, 2}, {26, 2}}}},
166  {{{{28, 1}, {28, 2}, {29, 1}}, /* htr 2 (HE) -bot(+top) */
167  {{28, 3}, {24, 2}, {24, 1}},
168  {{27, 1}, {27, 2}, {29, 2}},
169  {{27, 3}, {23, 2}, {23, 1}},
170  {{19, 2}, {20, 1}, {22, 2}},
171  {{19, 1}, {20, 2}, {22, 1}},
172  {{19, 2}, {20, 1}, {21, 2}},
173  {{19, 1}, {20, 2}, {21, 1}}},
174  {{{27, 1}, {27, 2}, {29, 2}}, /* htr 2 (HE) +bot(-top) */
175  {{27, 3}, {23, 2}, {23, 1}},
176  {{28, 1}, {28, 2}, {29, 1}},
177  {{28, 3}, {24, 2}, {24, 1}},
178  {{19, 2}, {20, 1}, {21, 2}},
179  {{19, 1}, {20, 2}, {21, 1}},
180  {{19, 2}, {20, 1}, {22, 2}},
181  {{19, 1}, {20, 2}, {22, 1}}}}};
182  memcpy(ihbheetadepth, ihbheetadepth_loc, sizeof(int) * NHTRS * NTOPBOT * NFBR * NFCH * 2);
183 
184  //Aram's insert: I shall now define an array which contains the RM and the RM fiber for HB HE
185  //and variables associated with this table
186  int irm_rmfiHBHE_loc[NHTRS][NTOPBOT][NFBR][2] = {
187  {{{6, 1}, {7, 1}, {6, 2}, {7, 2}, {4, 1}, {5, 1}, {4, 2}, {5, 2}}, // HTR 0 top
188  {{6, 3}, {7, 3}, {6, 4}, {7, 4}, {4, 3}, {5, 3}, {4, 4}, {5, 4}}}, // HTR 0 bot
189  {{{2, 1}, {3, 1}, {2, 2}, {3, 2}, {2, 1}, {3, 1}, {2, 2}, {3, 2}}, // HTR 1 top
190  {{2, 3}, {3, 3}, {2, 4}, {3, 4}, {2, 3}, {3, 3}, {2, 4}, {3, 4}}}, // HTR 1 bot
191  {{{4, 1}, {5, 1}, {4, 2}, {5, 2}, {6, 1}, {7, 1}, {6, 2}, {7, 2}}, // HTR 2 top
192  {{4, 3}, {5, 3}, {4, 4}, {5, 4}, {6, 3}, {7, 3}, {6, 4}, {7, 4}}} // HTR 2 bot
193  };
194  memcpy(irm_rmfiHBHE, irm_rmfiHBHE_loc, sizeof(int) * NHTRS * NTOPBOT * NFBR * 2);
195  //Pixel tables as a function of rm, rm fiber and fiber channel
196 
197  int ipixelHB_loc[NRMFIBR][NFCH][NRMSLOT] = {
198  // fch = 0 fch = 1 fch = 2
199  {{18, 17, 3, 2}, {13, 3, 17, 7}, {14, 1, 19, 6}}, //rmfiber = 2
200  {{19, 2, 18, 1}, {15, 7, 13, 5}, {17, 19, 1, 3}}, //rmfiber = 3
201  {{9, 4, 16, 11}, {5, 8, 12, 15}, {2, 13, 7, 18}}, //rmfiber = 4
202  {{12, 11, 9, 8}, {7, 15, 5, 13}, {16, 6, 14, 4}}, //rmfiber = 5
203  {{8, 5, 15, 12}, {4, 9, 11, 16}, {1, 14, 6, 19}}, //rmfiber = 6
204  {{6, 16, 4, 14}, {3, 18, 2, 17}, {11, 12, 8, 9}} //rmfiber = 7
205  };
206  memcpy(ipixelHB, ipixelHB_loc, sizeof(int) * NRMFIBR * NFCH * NRMSLOT);
207 
208  int ipixelHE_loc[NRMFIBR][NFCH][NRMSLOT] = {
209  // fch = 0 fch = 1 fch = 2
210  {{12, 12, 12, 12}, {16, 7, 16, 7}, {7, 16, 7, 16}}, //rmfiber = 2
211  {{11, 11, 11, 11}, {19, 3, 19, 3}, {3, 19, 3, 19}}, //rmfiber = 3
212  {{15, 15, 6, 6}, {2, 18, 2, 18}, {6, 6, 15, 15}}, //rmfiber = 4
213  {{5, 14, 5, 14}, {14, 5, 14, 5}, {18, 2, 18, 2}}, //rmfiber = 5
214  {{17, 1, 17, 1}, {9, 9, 9, 9}, {1, 17, 1, 17}}, //rmfiber = 6
215  {{13, 4, 13, 4}, {8, 8, 8, 8}, {4, 13, 4, 13}} //rmfiber = 7
216  };
217  memcpy(ipixelHE, ipixelHE_loc, sizeof(int) * NRMFIBR * NFCH * NRMSLOT);
218 
219  //slb and rct tables
220 
221  //HB and HE
222 
223  const char* S_slbin_odd_loc[] = {"A1", "B0", "B1", "A0", "A1", "B0", "B1", "A0"};
224  for (int gg = 0; gg < 8; gg++) {
225  S_slbin_odd[gg] = S_slbin_odd_loc[gg];
226  }
227  const char* S_slbin_even_loc[] = {"C1", "D0", "D1", "C0", "C1", "D0", "D1", "C0"};
228  for (int gg = 0; gg < 8; gg++) {
229  S_slbin_even[gg] = S_slbin_even_loc[gg];
230  }
231  const char* rct_rackHBHE_loc[] = {"S2E01-RH",
232  "S2E03-RH",
233  "S2E05-RH",
234  "S2E07-RH",
235  "S2E09-RH",
236  "S2E08-RL",
237  "S2E06-RL",
238  "S2E04-RL",
239  "S2E02-RL",
240  "S2E02-RH",
241  "S2E04-RH",
242  "S2E06-RH",
243  "S2E08-RH",
244  "S2E09-RL",
245  "S2E07-RL",
246  "S2E05-RL",
247  "S2E03-RL",
248  "S2E01-RL"};
249  for (int gg = 0; gg < 18; gg++) {
250  rct_rackHBHE[gg] = rct_rackHBHE_loc[gg];
251  }
252 
253  int slb_table_loc[29] = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, // 1<=eta<=12
254  1, 1, 2, 2, 3, 3, 1, 1, // 13<=eta<=20
255  2, 2, 3, 3, 4, 4, 4, 4, 4}; // 21<=eta<=29
256  memcpy(slb_table, slb_table_loc, sizeof(int) * 29);
257  /********************/
258 
259  char tempbuff[30]{0};
260 
261  //Stream variable
262  stringstream mystream;
263 
264  /* all HBHE crates */
265  for (ic = 0; ic < NHBHECR; ic++) {
266  /* four sets of three htrs per crate */
267  for (is = 0; is < NHSETS; is++) {
268  /* three htrs per set */
269  for (ih = 0; ih < NHTRS; ih++) {
270  /* top and bottom */
271  for (itb = 0; itb < NTOPBOT; itb++) {
272  /* eight fibers per HTR FPGA */
273  for (ifb = 0; ifb < NFBR; ifb++) {
274  /* three channels per fiber */
275  for (ifc = 0; ifc < NFCH; ifc++) {
276  icrate = hbhecrate[ic];
277  iside = is < NHSETS / 2 ? -1 : 1;
278  ifwtb = (is / 2 + itb + 1) % 2;
279  ieta = ihbheetadepth[ih][ifwtb][ifb][ifc][0];
280  idepth = ihbheetadepth[ih][ifwtb][ifb][ifc][1];
281  ihtr = ihslot[is] + ih;
282  (ieta > 16 || idepth > 2) ? det = "HE" : det = "HB";
283  (itb % 2) == 1 ? fpga = "bot" : fpga = "top";
284  ihtr_fi = ifb + 1;
285  ifi_ch = ifc;
286  iphi = (ieta > 20) ? (ihbhephis[ic] + (is % 2) * 4 + itb * 2 - 1) % 72 + 1
287  : (ihbhephis[ic] + (is % 2) * 4 + itb * 2 + (ifb / 2 + is / 2 + 1) % 2 - 1) % 72 + 1;
288  ispigot = (is % 2) * 6 + ih * 2 + itb;
289  idcc = is < NHSETS / 2 ? 1 : 2;
290  idcc_sl = idcc == 1 ? 10 : 20;
291  ifed = fedhbhenum[ic][idcc - 1];
292  //Aram's insert: rm variables, rbx, wedge
293  //Careful here: per Pawel's map, the rm fiber is the first entry an the rm itself is the second.
294 
295  //If iside == -1, switch top and bottom. Why?
296  if (iside == -1) {
297  S_side = '-';
298  sidesign = 'M';
299  irm = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][1];
300  irm_fi = irm_rmfiHBHE[ih][(itb + 1) % 2][ifb][0];
301 
302  //For eta >=21, the phi's cover 10 degrees rather than 5 (see HCAL TDR)
303  if (ieta >= 21 && (irm == 1 || irm == 3))
304  iwedge = (iphi + 1 + irm + 1) / 4;
305  else
306  iwedge = (iphi + irm + 1) / 4;
307 
308  //Roll over the wedge
309  if (iwedge > 18)
310  iwedge -= 18;
311  } else {
312  S_side = '+';
313  sidesign = 'P';
314  irm = irm_rmfiHBHE[ih][itb][ifb][1];
315  irm_fi = irm_rmfiHBHE[ih][itb][ifb][0];
316 
317  //For eta >=21, the phi's cover 10 degrees rather than 5 (see HCAL TDR)
318  if (ieta >= 21 && (irm == 4 || irm == 2))
319  iwedge = (iphi + 1 - irm + 6) / 4;
320  else
321  iwedge = (iphi - irm + 6) / 4;
322 
323  //Roll over the wedge
324  if (iwedge > 18)
325  iwedge -= 18;
326  }
327 
328  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
329  mystream << tempbuff;
330  rbx = mystream.str();
331  mystream.str("");
332 
333  //Note that irm_fi ranges from 2 to 7 whereas arrays start at 0 so
334  //I use irm_fi - 2. Likewise, irm goes from 1 to 4 so use irm - 1
335 
336  //Pixel is split by HB and HE
337  if (ieta > 16 || idepth > 2)
338  ipixel = ipixelHE[irm_fi - 2][ifc][irm - 1]; //HE
339  else
340  ipixel = ipixelHB[irm_fi - 2][ifc][irm - 1]; //HB
341 
342  iqie = iadcquiHBHE[irm_fi - 2][ifc][0];
343  iadc = iadcquiHBHE[irm_fi - 2][ifc][1];
344 
345  phideg = iphi - 3;
346  if (phideg < 0)
347  phideg = phideg + 72;
348  phideg = (phideg / 4) * 20 + 10;
349  irctcra = ((89 - phideg + 720) % 360) / 20;
350  oddcard = irctcra % 2;
351  irctcra /= 2;
352  if (iside > 0)
353  irctcra = irctcra + 9;
354 
355  etaslb = ((ieta - 1) / 2) * 2 + 1;
356  if (etaslb > 27)
357  etaslb = 27;
358 
359  snprintf(tempbuff, sizeof tempbuff, "SLB_H_%3.3d%c%2.2d", phideg, S_side, etaslb);
360  mystream << tempbuff;
361  slnam = mystream.str();
362  mystream.str("");
363 
364  islb = slb_table[ieta - 1];
365 
366  // calculate RCT destination (that is, rctcon, rctcar and rctnam
367  if (ieta <= 24) { // these are the normal cards 0-5
368  irctcar = 2 * ((ieta - 1) / 8) + oddcard;
369  irctcon = 2 * (((ieta - 1) / 2) % 4);
370  } else { // these are on the special card 6 which folds back eta on the odd card half
371  irctcar = 6;
372  eta2 = ieta;
373  if (eta2 > 28)
374  eta2 = 28;
375  if (oddcard == 0)
376  eta3 = eta2;
377  else
378  eta3 = 57 - eta2;
379  irctcon = 2 * (((eta3 - 1) / 2) % 4);
380  }
381  irctcon = 11 * irctcon + 1;
382 
383  snprintf(tempbuff, sizeof tempbuff, "%s-%1d-HD%2.2d", rct_rackHBHE[irctcra], irctcar, irctcon);
384  mystream << tempbuff;
385  rctnam = mystream.str();
386  mystream.str("");
387 
388  //Finally, the slbin
389 
390  phimod8 = iphi % 8;
391 
392  for (i = 0; i < 18; i++) {
393  if (iphi < i * 4 + 3) {
394  crazy = i % 2;
395  break;
396  }
397  }
398 
399  int ietamod; // determine if eta is "odd" or "even".
400  if (ieta == 29)
401  ietamod = 0;
402  else
403  ietamod = ieta % 2;
404  if (ieta < 25) { // use the regular table
405  if (ietamod == 1)
406  mystream << S_slbin_odd[phimod8];
407  else
408  mystream << S_slbin_even[phimod8];
409  } else if (crazy == 0) { // use the regular table
410  if (ietamod == 1)
411  mystream << S_slbin_odd[phimod8];
412  else
413  mystream << S_slbin_even[phimod8];
414  } else { // swap odd/even!!!
415  if (ietamod == 1)
416  mystream << S_slbin_even[phimod8];
417  else
418  mystream << S_slbin_odd[phimod8];
419  }
420 
421  slbin = mystream.str();
422  mystream.str("");
423 
424  if (ieta > 20) {
425  idphi = 2;
426  slbin2 = slbin;
427  slbin2[1] = '1';
428  } else {
429  idphi = 1;
430  slbin2 = "NA";
431  }
432 
433  HBHEHFLogicalMapEntry hbeflmapentry(ifi_ch,
434  ihtr_fi,
435  ispigot,
436  ifed,
437  icrate,
438  ihtr,
439  fpga,
440  det,
441  iside,
442  ieta,
443  iphi,
444  idepth,
445  idphi,
446  iwedge,
447  irm,
448  irm_fi,
449  ipixel,
450  iqie,
451  iadc,
452  islb,
453  irctcra,
454  irctcar,
455  irctcon,
456  rbx,
457  slbin,
458  slbin2,
459  slnam,
460  rctnam);
461  HBHEHFEntries.push_back(hbeflmapentry);
462  LinearIndex2Entry.at(hbeflmapentry.getLinearIndex()) =
463  HcalLogicalMap::makeEntryNumber(true, 0, HBHEHFEntries.size() - 1);
464 
465  const HcalGenericDetId hgdi(hbeflmapentry.getDetId());
466  unsigned int denseId;
467  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenBarrel) {
468  denseId = topo->detId2denseIdHB(hgdi);
469  HbHash2Entry.at(denseId) = HBHEHFEntries.size();
470  }
471  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenEndcap) {
472  denseId = topo->detId2denseIdHE(hgdi);
473  HeHash2Entry.at(denseId) = HBHEHFEntries.size();
474  }
475  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenForward) {
476  denseId = topo->detId2denseIdHF(hgdi);
477  HfHash2Entry.at(denseId) = HBHEHFEntries.size();
478  }
479 
480  ConstructTriggerTower(topo,
481  HTEntries,
482  iside,
483  ieta,
484  iphi,
485  idphi,
486  idepth,
487  det,
488  iwedge,
489  irm,
490  ipixel,
491  iqie,
492  iadc,
493  irm_fi,
494  ifi_ch,
495  icrate,
496  ihtr,
497  fpga,
498  ihtr_fi,
499  ispigot,
500  islb,
501  slbin,
502  slbin2,
503  slnam,
504  irctcra,
505  irctcar,
506  irctcon,
507  rctnam,
508  ifed);
509  }
510  }
511  }
512  }
513  }
514  }
515 
516  /********************/
517  /* HF crate numbering */
518  int hfcrate_loc[NHFCR] = {2, 9, 12};
519  memcpy(hfcrate, hfcrate_loc, sizeof(int) * NHFCR);
520  /* HF FED numbering of DCCs */
521  int fedhfnum_loc[NHFCR][2] = {{718, 719}, {720, 721}, {722, 723}};
522  memcpy(fedhfnum, fedhfnum_loc, sizeof(int) * NHFCR * 2);
523  /* iphi (lower) starting index for each HF crate */
524  int ihfphis_loc[NHFCR] = {3, 27, 51};
525  memcpy(ihfphis, ihfphis_loc, sizeof(int) * NHFCR);
526  /* ihfetadepth - unique HF {eta,depth} assignments per fiber and fiber channel */
527  int ihfetadepth_loc[NTOPBOT][NFBR][NFCH][2] = {{{{33, 1}, {31, 1}, {29, 1}}, /* top */
528  {{32, 1}, {30, 1}, {34, 1}},
529  {{33, 2}, {31, 2}, {29, 2}},
530  {{32, 2}, {30, 2}, {34, 2}},
531  {{34, 2}, {32, 2}, {30, 2}},
532  {{31, 2}, {29, 2}, {33, 2}},
533  {{34, 1}, {32, 1}, {30, 1}},
534  {{31, 1}, {29, 1}, {33, 1}}},
535  {{{41, 1}, {37, 1}, {35, 1}}, /* bot */
536  {{38, 1}, {36, 1}, {39, 1}},
537  {{41, 2}, {37, 2}, {35, 2}},
538  {{38, 2}, {36, 2}, {39, 2}},
539  {{40, 2}, {38, 2}, {36, 2}},
540  {{37, 2}, {35, 2}, {39, 2}},
541  {{40, 1}, {38, 1}, {36, 1}},
542  {{37, 1}, {35, 1}, {39, 1}}}};
543  memcpy(ihfetadepth, ihfetadepth_loc, sizeof(int) * NTOPBOT * NFBR * NFCH * 2);
544 
545  int irm_rmfiHF_loc[NHTRS][NTOPBOT][NFBR][2] = {
546  {{{1, 2}, {2, 2}, {3, 2}, {4, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}}, // HTR 0 top
547  {{5, 2}, {6, 2}, {7, 2}, {8, 2}, {5, 3}, {6, 3}, {7, 3}, {8, 3}}}, // HTR 0 bot
548  {{{1, 1}, {2, 1}, {3, 1}, {4, 1}, {1, 2}, {2, 2}, {3, 2}, {4, 2}}, // HTR 1 top
549  {{5, 1}, {6, 1}, {7, 1}, {8, 1}, {5, 2}, {6, 2}, {7, 2}, {8, 2}}}, // HTR 1 bot
550  {{{1, 3}, {2, 3}, {3, 3}, {4, 3}, {1, 1}, {2, 1}, {3, 1}, {4, 1}}, // HTR 2 top
551  {{5, 3}, {6, 3}, {7, 3}, {8, 3}, {5, 1}, {6, 1}, {7, 1}, {8, 1}}} // HTR 2 bot
552  };
553  memcpy(irm_rmfiHF, irm_rmfiHF_loc, sizeof(int) * NHTRS * NTOPBOT * NFBR * 2);
554 
555  //HF
556  const char* S_slbin_7_loc[] = {"A0", "A1", "B0", "B1"};
557  for (int gg = 0; gg < 4; gg++) {
558  S_slbin_7[gg] = S_slbin_7_loc[gg];
559  }
560  const char* S_slbin_3_loc[] = {"C0", "C1", "D0", "D1"};
561  for (int gg = 0; gg < 4; gg++) {
562  S_slbin_3[gg] = S_slbin_3_loc[gg];
563  }
564  const char* rct_rackHF_loc[] = {"S2E01-FH",
565  "S2E03-FH",
566  "S2E05-FH",
567  "S2E07-FH",
568  "S2E09-FH",
569  "S2E08-FL",
570  "S2E06-FL",
571  "S2E04-FL",
572  "S2E02-FL",
573  "S2E02-FH",
574  "S2E04-FH",
575  "S2E06-FH",
576  "S2E08-FH",
577  "S2E09-FL",
578  "S2E07-FL",
579  "S2E05-FL",
580  "S2E03-FL",
581  "S2E01-FL"};
582  for (int gg = 0; gg < 18; gg++) {
583  rct_rackHF[gg] = rct_rackHF_loc[gg];
584  }
585 
586  /***************/
587 
588  /* all HF crates */
589  for (ic = 0; ic < NHFCR; ic++) {
590  /* four sets of three htrs per crate */
591  for (is = 0; is < NHSETS; is++) {
592  /* three htrs per set */
593  for (ih = 0; ih < NHTRS; ih++) {
594  /* top and bottom */
595  for (itb = 0; itb < NTOPBOT; itb++) {
596  /* eight fibers per HTR FPGA */
597  for (ifb = 0; ifb < NFBR; ifb++) {
598  /* three channels per fiber */
599  for (ifc = 0; ifc < NFCH; ifc++) {
600  icrate = hfcrate[ic];
601  iside = is < NHSETS / 2 ? -1 : 1;
602  ieta = ihfetadepth[itb][ifb][ifc][0];
603  idepth = ihfetadepth[itb][ifb][ifc][1];
604  ihtr = ihslot[is] + ih;
605  det = "HF";
606  (itb % 2) == 1 ? fpga = "bot" : fpga = "top";
607  ihtr_fi = ifb + 1;
608  ifi_ch = ifc;
609  iphi = (ieta > 39) ? (ihfphis[ic] + (is % 2) * 12 + ih * 4 - 1) % 72 + 1
610  : (ihfphis[ic] + (is % 2) * 12 + ih * 4 + (ifb / 4) * 2 - 1) % 72 + 1;
611  ispigot = (is % 2) * 6 + ih * 2 + itb;
612  idcc = is < NHSETS / 2 ? 1 : 2;
613  idcc_sl = idcc == 1 ? 10 : 20;
614  ifed = fedhfnum[ic][idcc - 1];
615 
616  irm_fi = irm_rmfiHF[ih][itb][ifb][0];
617 
618  //Don't switch in the HF. Why?
619  if (iside == -1) {
620  S_side = '-';
621  sidesign = 'M';
622 
623  if (ieta < 40) {
624  if (iphi == 1)
625  iphi = 71;
626  else if (iphi == 71)
627  iphi = 1;
628  else if (iphi % 4 == 1)
629  iphi -= 2;
630  else if (iphi % 4 == 3)
631  iphi += 2;
632  else
633  edm::LogInfo("HcalLogicalMapGenerator") << "Even iphi in HFM" << endl;
634  }
635  } else {
636  S_side = '+';
637  sidesign = 'P';
638  }
639 
640  //RM and RBX number
641  if ((iside == 1 && ieta == 40) || (iside == -1 && ieta == 41)) {
642  irm = ((iphi + 1) / 2) % 36 + 1;
643  hfphi = ((iphi + 1) / 6) % 12 + 1;
644  } else {
645  irm = (iphi + 1) / 2;
646  hfphi = (iphi - 1) / 6 + 1;
647  }
648  irm = (irm - 1) % 3 + 1;
649 
650  //Wedge
651  if (iphi >= 71)
652  iwedge = 1;
653  else
654  iwedge = (iphi + 1) / 4 + 1;
655 
656  //RBX
657  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, hfphi);
658  mystream << tempbuff;
659  rbx = mystream.str();
660  mystream.str("");
661 
662  //No pixel in HF, follow Fedor's convention
663  ipixel = 0;
664 
665  //Integer truncation again consistent with Fedor's map.
666  iqie = (irm_fi - 1) / 2 + 1;
667 
668  if (irm_fi % 2 != 0)
669  iadc = ifi_ch;
670  else
671  iadc = NFCH + (ifi_ch + 1) % 3;
672 
673  //slb and rct variables
674  //rctcrate
675  phideg = iphi - 3;
676  if (phideg < 0)
677  phideg = phideg + 72;
678  phideg = (phideg / 4) * 20 + 10;
679  irctcra = ((89 - phideg + 720) % 360) / 40;
680  if (iside > 0)
681  irctcra = irctcra + 9;
682 
683  //rct card and rct connector appear to be dummy here -- again, I follow Fedor's convention
684  irctcar = 99;
685  irctcon = 0;
686 
687  etaslb = 29;
688 
689  snprintf(tempbuff, sizeof tempbuff, "SLB_H_%3.3d%c%2.2d", phideg, S_side, etaslb);
690  mystream << tempbuff;
691  slnam = mystream.str();
692  mystream.str("");
693 
694  snprintf(tempbuff, sizeof tempbuff, "%s-JSC-HF_IN", rct_rackHF[irctcra]);
695  mystream << tempbuff;
696  rctnam = mystream.str();
697  mystream.str("");
698 
699  islb = 6;
700 
701  int phibin = (iphi + 1) % 8;
702  int etabin = (ieta - 29) / 3;
703  if (etabin < 0)
704  etabin = 0;
705  if (etabin > 3)
706  etabin = 3;
707  if (phibin < 4)
708  mystream << S_slbin_7[etabin];
709  else
710  mystream << S_slbin_3[etabin];
711 
712  slbin = mystream.str();
713  mystream.str("");
714 
715  slbin2 = "NA";
716 
717  if (ieta < 40)
718  idphi = 2;
719  else
720  idphi = 4;
721 
722  HBHEHFLogicalMapEntry hbeflmapentry(ifi_ch,
723  ihtr_fi,
724  ispigot,
725  ifed,
726  icrate,
727  ihtr,
728  fpga,
729  det,
730  iside,
731  ieta,
732  iphi,
733  idepth,
734  idphi,
735  iwedge,
736  irm,
737  irm_fi,
738  ipixel,
739  iqie,
740  iadc,
741  islb,
742  irctcra,
743  irctcar,
744  irctcon,
745  rbx,
746  slbin,
747  slbin2,
748  slnam,
749  rctnam);
750  HBHEHFEntries.push_back(hbeflmapentry);
751  LinearIndex2Entry.at(hbeflmapentry.getLinearIndex()) =
752  HcalLogicalMap::makeEntryNumber(true, 0, HBHEHFEntries.size() - 1);
753 
754  const HcalGenericDetId hgdi(hbeflmapentry.getDetId());
755  unsigned int denseId;
756  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenBarrel) {
757  denseId = topo->detId2denseIdHB(hgdi);
758  HbHash2Entry.at(denseId) = HBHEHFEntries.size();
759  }
760  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenEndcap) {
761  denseId = topo->detId2denseIdHE(hgdi);
762  HeHash2Entry.at(denseId) = HBHEHFEntries.size();
763  }
764  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenForward) {
765  denseId = topo->detId2denseIdHF(hgdi);
766  HfHash2Entry.at(denseId) = HBHEHFEntries.size();
767  }
768 
769  ConstructTriggerTower(topo,
770  HTEntries,
771  iside,
772  ieta,
773  iphi,
774  idphi,
775  idepth,
776  det,
777  iwedge,
778  irm,
779  ipixel,
780  iqie,
781  iadc,
782  irm_fi,
783  ifi_ch,
784  icrate,
785  ihtr,
786  fpga,
787  ihtr_fi,
788  ispigot,
789  islb,
790  slbin,
791  slbin2,
792  slnam,
793  irctcra,
794  irctcar,
795  irctcon,
796  rctnam,
797  ifed);
798  }
799  }
800  }
801  }
802  }
803  }
804 }
805 
807  std::vector<HOHXLogicalMapEntry>& HOHXEntries,
808  std::vector<uint32_t>& LinearIndex2Entry,
809  std::vector<uint32_t>& HoHash2Entry,
810  std::vector<uint32_t>& HxCalibHash2Entry) {
811  /******************************/
812  /* HO crate numbering */
813  int hocrate_loc[NHOCR] = {3, 7, 6, 13};
814  memcpy(hocrate, hocrate_loc, sizeof(int) * NHOCR);
815  /* HO FED numbering of DCCs */
816  int fedhonum_loc[NHOCR][2] = {{724, 725}, {726, 727}, {728, 729}, {730, 731}};
817  memcpy(fedhonum, fedhonum_loc, sizeof(int) * NHOCR * 2);
818  /* HO htr slot offsets for three sets of four htrs */
819  int ihslotho_loc[NHSETSHO][NHTRSHO] = {{2, 3, 4, 5}, {6, 7, 13, 14}, {15, 16, 17, 18}};
820  memcpy(ihslotho, ihslotho_loc, sizeof(int) * NHSETSHO * NHTRSHO);
821  /* iphi (lower) starting index for each HO crate */
822  int ihophis_loc[NHOCR] = {71, 17, 35, 53};
823  memcpy(ihophis, ihophis_loc, sizeof(int) * NHOCR);
824 
825  //RM for the HO as a function of eta, phi and side as implemented in complete_ho_map.txt
826  //There are only 24 phi columns because after that it begins to repeat. The relevant variable is phi mod 24.
827  //HX as the 16th eta entry
828  int HO_RM_table_loc[24][16][2] = {{{2, 2},
829  {2, 2},
830  {2, 2},
831  {2, 2},
832  {2, 2},
833  {2, 2},
834  {2, 2},
835  {2, 2},
836  {2, 2},
837  {2, 2},
838  {4, 2},
839  {4, 2},
840  {4, 2},
841  {4, 2},
842  {4, 2},
843  {4, 2}},
844  {{2, 2},
845  {2, 2},
846  {2, 2},
847  {2, 2},
848  {4, 4},
849  {4, 4},
850  {4, 4},
851  {4, 4},
852  {4, 4},
853  {4, 4},
854  {2, 4},
855  {2, 4},
856  {2, 4},
857  {2, 4},
858  {2, 4},
859  {2, 4}},
860  {{3, 3},
861  {3, 3},
862  {3, 3},
863  {3, 3},
864  {4, 4},
865  {4, 4},
866  {4, 4},
867  {4, 4},
868  {4, 4},
869  {4, 4},
870  {2, 4},
871  {2, 4},
872  {2, 4},
873  {2, 4},
874  {2, 4},
875  {2, 4}},
876  {{3, 3},
877  {3, 3},
878  {3, 3},
879  {3, 3},
880  {4, 4},
881  {4, 4},
882  {4, 4},
883  {4, 4},
884  {4, 4},
885  {4, 4},
886  {2, 4},
887  {2, 4},
888  {2, 4},
889  {2, 4},
890  {2, 4},
891  {2, 4}},
892  {{4, 4},
893  {4, 4},
894  {4, 4},
895  {4, 4},
896  {3, 3},
897  {3, 3},
898  {3, 3},
899  {3, 3},
900  {3, 3},
901  {3, 3},
902  {1, 3},
903  {1, 3},
904  {1, 3},
905  {1, 3},
906  {1, 3},
907  {1, 3}},
908  {{4, 4},
909  {4, 4},
910  {4, 4},
911  {4, 4},
912  {3, 3},
913  {3, 3},
914  {3, 3},
915  {3, 3},
916  {3, 3},
917  {3, 3},
918  {1, 3},
919  {1, 3},
920  {1, 3},
921  {1, 3},
922  {1, 3},
923  {1, 3}},
924  {{3, 3},
925  {3, 3},
926  {3, 3},
927  {3, 3},
928  {3, 3},
929  {3, 3},
930  {3, 3},
931  {3, 3},
932  {3, 3},
933  {3, 3},
934  {1, 3},
935  {1, 3},
936  {1, 3},
937  {1, 3},
938  {1, 3},
939  {1, 3}},
940  {{3, 3},
941  {3, 3},
942  {3, 3},
943  {3, 3},
944  {1, 1},
945  {1, 1},
946  {1, 1},
947  {1, 1},
948  {1, 1},
949  {1, 1},
950  {3, 1},
951  {3, 1},
952  {3, 1},
953  {3, 1},
954  {3, 1},
955  {3, 1}},
956  {{2, 2},
957  {2, 2},
958  {2, 2},
959  {2, 2},
960  {1, 1},
961  {1, 1},
962  {1, 1},
963  {1, 1},
964  {1, 1},
965  {1, 1},
966  {3, 1},
967  {3, 1},
968  {3, 1},
969  {3, 1},
970  {3, 1},
971  {3, 1}},
972  {{2, 2},
973  {2, 2},
974  {2, 2},
975  {2, 2},
976  {1, 1},
977  {1, 1},
978  {1, 1},
979  {1, 1},
980  {1, 1},
981  {1, 1},
982  {3, 1},
983  {3, 1},
984  {3, 1},
985  {3, 1},
986  {3, 1},
987  {3, 1}},
988  {{4, 4},
989  {4, 4},
990  {4, 4},
991  {4, 4},
992  {2, 2},
993  {2, 2},
994  {2, 2},
995  {2, 2},
996  {2, 2},
997  {2, 2},
998  {4, 2},
999  {4, 2},
1000  {4, 2},
1001  {4, 2},
1002  {4, 2},
1003  {4, 2}},
1004  {{4, 4},
1005  {4, 4},
1006  {4, 4},
1007  {4, 4},
1008  {2, 2},
1009  {2, 2},
1010  {2, 2},
1011  {2, 2},
1012  {2, 2},
1013  {2, 2},
1014  {4, 2},
1015  {4, 2},
1016  {4, 2},
1017  {4, 2},
1018  {4, 2},
1019  {4, 2}},
1020  {{3, 3},
1021  {3, 3},
1022  {3, 3},
1023  {3, 3},
1024  {2, 2},
1025  {2, 2},
1026  {2, 2},
1027  {2, 2},
1028  {2, 2},
1029  {2, 2},
1030  {4, 2},
1031  {4, 2},
1032  {4, 2},
1033  {4, 2},
1034  {4, 2},
1035  {4, 2}},
1036  {{3, 3},
1037  {3, 3},
1038  {3, 3},
1039  {3, 3},
1040  {4, 4},
1041  {4, 4},
1042  {4, 4},
1043  {4, 4},
1044  {4, 4},
1045  {4, 4},
1046  {2, 4},
1047  {2, 4},
1048  {2, 4},
1049  {2, 4},
1050  {2, 4},
1051  {2, 4}},
1052  {{2, 2},
1053  {2, 2},
1054  {2, 2},
1055  {2, 2},
1056  {4, 4},
1057  {4, 4},
1058  {4, 4},
1059  {4, 4},
1060  {4, 4},
1061  {4, 4},
1062  {2, 4},
1063  {2, 4},
1064  {2, 4},
1065  {2, 4},
1066  {2, 4},
1067  {2, 4}},
1068  {{2, 2},
1069  {2, 2},
1070  {2, 2},
1071  {2, 2},
1072  {4, 4},
1073  {4, 4},
1074  {4, 4},
1075  {4, 4},
1076  {4, 4},
1077  {4, 4},
1078  {2, 4},
1079  {2, 4},
1080  {2, 4},
1081  {2, 4},
1082  {2, 4},
1083  {2, 4}},
1084  {{1, 1},
1085  {1, 1},
1086  {1, 1},
1087  {1, 1},
1088  {3, 3},
1089  {3, 3},
1090  {3, 3},
1091  {3, 3},
1092  {3, 3},
1093  {3, 3},
1094  {1, 3},
1095  {1, 3},
1096  {1, 3},
1097  {1, 3},
1098  {1, 3},
1099  {1, 3}},
1100  {{1, 1},
1101  {1, 1},
1102  {1, 1},
1103  {1, 1},
1104  {3, 3},
1105  {3, 3},
1106  {3, 3},
1107  {3, 3},
1108  {3, 3},
1109  {3, 3},
1110  {1, 3},
1111  {1, 3},
1112  {1, 3},
1113  {1, 3},
1114  {1, 3},
1115  {1, 3}},
1116  {{2, 2},
1117  {2, 2},
1118  {2, 2},
1119  {2, 2},
1120  {3, 3},
1121  {3, 3},
1122  {3, 3},
1123  {3, 3},
1124  {3, 3},
1125  {3, 3},
1126  {1, 3},
1127  {1, 3},
1128  {1, 3},
1129  {1, 3},
1130  {1, 3},
1131  {1, 3}},
1132  {{2, 2},
1133  {2, 2},
1134  {2, 2},
1135  {2, 2},
1136  {1, 1},
1137  {1, 1},
1138  {1, 1},
1139  {1, 1},
1140  {1, 1},
1141  {1, 1},
1142  {3, 1},
1143  {3, 1},
1144  {3, 1},
1145  {3, 1},
1146  {3, 1},
1147  {3, 1}},
1148  {{3, 3},
1149  {3, 3},
1150  {3, 3},
1151  {3, 3},
1152  {1, 1},
1153  {1, 1},
1154  {1, 1},
1155  {1, 1},
1156  {1, 1},
1157  {1, 1},
1158  {3, 1},
1159  {3, 1},
1160  {3, 1},
1161  {3, 1},
1162  {3, 1},
1163  {3, 1}},
1164  {{3, 3},
1165  {3, 3},
1166  {3, 3},
1167  {3, 3},
1168  {1, 1},
1169  {1, 1},
1170  {1, 1},
1171  {1, 1},
1172  {1, 1},
1173  {1, 1},
1174  {3, 1},
1175  {3, 1},
1176  {3, 1},
1177  {3, 1},
1178  {3, 1},
1179  {3, 1}},
1180  {{1, 1},
1181  {1, 1},
1182  {1, 1},
1183  {1, 1},
1184  {2, 2},
1185  {2, 2},
1186  {2, 2},
1187  {2, 2},
1188  {2, 2},
1189  {2, 2},
1190  {4, 2},
1191  {4, 2},
1192  {4, 2},
1193  {4, 2},
1194  {4, 2},
1195  {4, 2}},
1196  {{1, 1},
1197  {1, 1},
1198  {1, 1},
1199  {1, 1},
1200  {2, 2},
1201  {2, 2},
1202  {2, 2},
1203  {2, 2},
1204  {2, 2},
1205  {2, 2},
1206  {4, 2},
1207  {4, 2},
1208  {4, 2},
1209  {4, 2},
1210  {4, 2},
1211  {4, 2}}};
1212  memcpy(HO_RM_table, HO_RM_table_loc, sizeof(int) * 24 * 16 * 2);
1213 
1214  //For |eta| 5 to 15, rm_fi is a function of |eta| only while htr_fi is a function of side and |eta|
1215  int HO_RM_fi_eta5to15_loc[11] = {3, 2, 5, 4, 7, 6, 3, 2, 5, 4, 7};
1216  memcpy(HO_RM_fi_eta5to15, HO_RM_fi_eta5to15_loc, sizeof(int) * 11);
1217  //For eta=16 it is 6, declared in the header
1218  HO_RM_fi_eta16 = 6;
1219  //For eta in the YB0 region, rm_fi is dependent on side, 4 for -1, and 5 for +1
1220  //but the values won't be any different than when the regular loop is executed
1221  //int HO_RM_fi_etaYB0[2] = {4, 5}
1222 
1223  //For |eta| 1 to 4, it is a function of phi, eta and side. eta 1-3 always have the same value given a side,
1224  //eta 4 is separate and thus gets its own box
1225  //threefold symmetry in iphi, repeats every three groups of 8 i.e., 1to8 == 25to32 == 49to56,
1226  //similarly for the other iphi groups
1227  //[iphi][ieta 1-3/4][side m/p]
1228  //Actually has more modular structure which is not repetitive cyclicly
1229  // groups of 4 in iphi repeat 1to4 == 17to20 == 21to24
1230  // groups of 4 in iphi repeat 5to8 == 9to12 == 13to16
1231  int HO_RM_fi_eta1to4_loc[24][2][2] = {
1232  //side = -1 side = 1
1233  {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{2, 6}, {5, 4}},
1234  {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, //Phi 1 to 8, Phi 25 to 32, Phi 49 to 56
1235  {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}},
1236  {{3, 7}, {5, 4}}, {{2, 6}, {5, 4}}, {{3, 7}, {5, 4}}, //Phi 9 to 16, Phi 33 to 40, Phi 57 to 64
1237  {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}},
1238  {{6, 2}, {4, 5}}, {{7, 3}, {4, 5}}, {{6, 2}, {4, 5}} //Phi 17 to 24, Phi 41 to 48, Phi 65 to 72
1239  };
1240  memcpy(HO_RM_fi_eta1to4, HO_RM_fi_eta1to4_loc, sizeof(int) * 24 * 2 * 2);
1241 
1242  /* new mapping with SiPMs in HO ring-0 */
1243  //The mapping is different for HO ring-0 with HPDs (above) or SiPMs (here)
1244  // as the SiPM mapping is not cyclic in the same way as before
1245  //[iphi][ieta][side m/p]
1246  //threefold symmetry in iphi, repeats every three lines i.e., 1to8 == 25to32 == 49to56,
1247  //similarly for the other iphi groups
1248  //(iphi-1)mod(24)
1249  //ieta4,rm_fi5,fi_ch1 5 -> 3:{minus:evenphi,plus:oddphi}
1250  //ieta4,rm_fi5,fi_ch2 5 -> 2:{minus:oddphi,plus:evenphi}
1251  int HO_RM_fi_eta1to4_sipm_loc[24][4][2] = {
1252  //side = -1 side = 1
1253  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},
1254  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}}, //Phi 1 to 4
1255  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},
1256  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}}, //Phi 5 to 8
1257  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},
1258  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}}, //Phi 9 to 12
1259  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}},
1260  {{2, 4}, {4, 7}, {2, 7}, {2, 6}}, {{3, 5}, {5, 5}, {3, 7}, {3, 6}}, //Phi 13 to 16
1261  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},
1262  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}}, //Phi 17 to 20
1263  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}},
1264  {{5, 3}, {5, 5}, {7, 3}, {6, 3}}, {{4, 2}, {7, 4}, {7, 2}, {6, 2}}, //Phi 21 to 24
1265  };
1266  memcpy(HO_RM_fi_eta1to4_sipm, HO_RM_fi_eta1to4_sipm_loc, sizeof(int) * 24 * 4 * 2);
1267 
1268  // htr_fi
1269  int HO_htr_fi_450eta5to15_loc[2][11] = {{2, 2, 4, 6, 8, 2, 4, 6, 8, 4, 6}, //iside = -1
1270  {2, 8, 6, 4, 2, 8, 6, 4, 2, 4, 2}}; //iside = +1
1271  memcpy(HO_htr_fi_450eta5to15, HO_htr_fi_450eta5to15_loc, sizeof(int) * 2 * 11);
1272  // for the minus side, htr_fi is determined by the RM, will have to shift up one since rm is
1273  //numbered 1-4 not 0-3
1274  int HO_htr_fi_450eta16M_loc[4] = {7, 7, 8, 8}; //iside = -1
1275  memcpy(HO_htr_fi_450eta16M, HO_htr_fi_450eta16M_loc, sizeof(int) * 4);
1276  //For the plus side, there is a new htr so all values can be used, but only 6 are used
1277  //Depend on phi, but also on rm and sector (2,4,6,8,10,12)
1278  int HO_htr_fi_450eta16P_loc[4][6] = {
1279  {4, 2, 4, 4, 2, 6}, {2, 6, 6, 2, 6, 4}, {5, 3, 5, 5, 3, 7}, {3, 7, 7, 3, 7, 5}}; //iside = +1
1280  memcpy(HO_htr_fi_450eta16P, HO_htr_fi_450eta16P_loc, sizeof(int) * 4 * 6);
1281 
1282  //for |eta| <= 4, htr_fi is a function of side and phmod6
1283  int HO_htr_fi_eta4_loc[2][6] = {{6, 6, 8, 8, 7, 7}, //iside = -1
1284  {4, 4, 5, 5, 3, 3}}; //iside = +1
1285  if (mapIOV_ < 5)
1286  memcpy(HO_htr_fi_eta4, HO_htr_fi_eta4_loc, sizeof(int) * 2 * 6);
1287 
1288  int HO_htr_fi_eta123_loc[2][6] = {{6, 5, 4, 3, 8, 7}, //iside = -1
1289  {8, 7, 6, 5, 2, 1}}; //iside = +1
1290  if (mapIOV_ < 5)
1291  memcpy(HO_htr_fi_eta123, HO_htr_fi_eta123_loc, sizeof(int) * 2 * 6);
1292 
1293  //HO_htr_fi_123eta5to15[2][11] is unnecessary because
1294  // HO_htr_fi_123eta5to15[i][j] == int HO_htr_fi_450eta5to15[i][j] - 1
1295 
1296  //post SiPM card swap
1297  // htr_fi is a function of phmod6,eta,rm,side
1298  // rm is a function of phimod6: rm = 1,4 for phimod6 > 3, and 2,3 otherwise
1299  // to index the array, take rm/2 integer division
1300  // cross-talk channels are separate
1301  int HO_htr_fi_eta1234_sipm[6][5][2][2] = {
1302  {/*eta==1*/ /*eta==2*/ /*eta==3*/ /*eta==4*/ /*cross-talk*/
1303  {{4, 8}, {6, 4}},
1304  {{4, 4}, {4, 7}},
1305  {{6, 8}, {6, 7}},
1306  {{5, 8}, {6, 8}},
1307  {{5, 6}, {-1, -1}}}, //phm6==0
1308  {{{6, 7}, {5, 6}}, {{6, 6}, {6, 6}}, {{6, 7}, {5, 7}}, {{5, 7}, {5, 8}}, {{-1, -1}, {4, 8}}}, //phm6==1
1309  {{{4, 5}, {5, 6}}, {{5, 5}, {5, 5}}, {{4, 5}, {4, 6}}, {{4, 6}, {3, 6}}, {{-1, -1}, {3, 8}}}, //phm6==2
1310  {{{3, 8}, {8, 5}}, {{8, 8}, {4, 8}}, {{3, 5}, {4, 5}}, {{3, 6}, {3, 5}}, {{5, 6}, {-1, -1}}}, //phm6==3
1311  {
1312  {{3, 2}, {8, 3}},
1313  {{3, 3}, {3, 1}},
1314  {{8, 2}, {8, 1}},
1315  {{7, 2}, {8, 2}},
1316  {{7, 7}, {-1, -1}}}, //phm6==4
1317  {{{7, 1}, {7, 7}}, {{8, 7}, {7, 7}}, {{8, 1}, {7, 1}}, {{7, 1}, {7, 2}}, {{-1, -1}, {3, 2}}}, //phm6==5
1318  };
1319 
1320  // Pixel and letter code for HO.
1321  // Ring 0 is separate and goes into entry 0, Rings +/- 1,2 are all the same and go to entry 1.
1322  // Pixel and let_code for HO ring 0 on the crosstalk channels: on rm_fi 4, pixel = 18, let_code = X
1323  // Pixel and let_code for HO ring 0 on the crosstalk channels: on rm_fi 5, pixel = 2, let_code = X
1324  // Fiber Channel 0 1 2
1325  int ipixelHO_loc[NRMFIBR][NFCH][2] = {{{12, 12}, {7, 7}, {6, 3}}, //RM fiber 2
1326  {{4, 4}, {8, 8}, {5, 1}}, //RM fiber 3
1327  {{19, 11}, {18, 6}, {17, 2}}, //RM fiber 4
1328  {{2, 9}, {1, 13}, {3, 5}}, //RM fiber 5
1329  {{11, 19}, {16, 18}, {15, 17}}, //RM fiber 6
1330  {{13, 15}, {9, 14}, {14, 16}}}; //RM fiber 7
1331  //changes for SiPM ring-0, interface card now identical to the cards in ring-1/2
1332  int ipixelHO_sipm[NRMFIBR][NFCH][2] = {{{12, 12}, {7, 7}, {3, 3}}, //RM fibers 2
1333  {{4, 4}, {8, 8}, {1, 1}}, //RM fibers 3
1334  {{11, 11}, {6, 6}, {2, 2}}, //RM fibers 4
1335  {{9, 9}, {13, 13}, {5, 5}}, //RM fibers 5
1336  {{19, 19}, {18, 18}, {17, 17}}, //RM fibers 6
1337  {{15, 15}, {14, 14}, {16, 16}}}; //RM fibers 7
1338  if (mapIOV_ < 5)
1339  memcpy(ipixelHO, ipixelHO_loc, sizeof(int) * NRMFIBR * NFCH * 2);
1340  else
1341  memcpy(ipixelHO, ipixelHO_sipm, sizeof(int) * NRMFIBR * NFCH * 2);
1342 
1343  // Fiber Channel 0 1 2
1344  std::string letterHO_loc[NRMFIBR][NFCH][2] = {{{"E", "E"}, {"G", "L"}, {"F", "S"}}, //RM fiber 2
1345  {{"Q", "M"}, {"N", "T"}, {"P", "F"}}, //RM fiber 3
1346  {{"A", "C"}, {"X", "J"}, {"J", "Q"}}, //RM fiber 4
1347  {{"X", "K"}, {"R", "R"}, {"H", "D"}}, //RM fiber 5
1348  {{"D", "A"}, {"C", "G"}, {"B", "N"}}, //RM fiber 6
1349  {{"L", "H"}, {"M", "P"}, {"K", "B"}}}; //RM fiber 7
1350  //changes for SiPM ring-0, interface card now identical to the cards in ring-1/2
1351  std::string letterHO_sipm[NRMFIBR][NFCH][2] = {{{"E", "E"}, {"G", "L"}, {"H", "S"}}, //RM fibers 2
1352  {{"Q", "M"}, {"N", "T"}, {"R", "F"}}, //RM fibers 3
1353  {{"D", "C"}, {"F", "J"}, {"X", "Q"}}, //RM fibers 4
1354  {{"M", "K"}, {"L", "R"}, {"P", "D"}}, //RM fibers 5
1355  {{"A", "A"}, {"X", "G"}, {"J", "N"}}, //RM fibers 6
1356  {{"B", "H"}, {"K", "P"}, {"C", "B"}}}; //RM fibers 7
1357 
1358  for (int jj = 0; jj < NRMFIBR; jj++) {
1359  for (int kk = 0; kk < NFCH; kk++) {
1360  for (int ll = 0; ll < 2; ll++) {
1361  if (mapIOV_ < 5)
1362  letterHO[jj][kk][ll] = letterHO_loc[jj][kk][ll];
1363  else
1364  letterHO[jj][kk][ll] = letterHO_sipm[jj][kk][ll];
1365  }
1366  }
1367  }
1368 
1369  /******************************************************************************************/
1370  // Here is the section that deals with the miscabled HO RBXs.
1371  // To modify the code between IOVs, just note that inverted corresponds to -infinity to end of 2008
1372  // and otherwise, to 2009 to infinity.
1373  // Except for some small but major caveats:
1374  // HO2M04 (phi=16) was not able to be corrected, thus it is still inverted
1375  // HO2M06 (phi=31) has not been active in 2009, and the cables have not been switched officially
1376  // HO2P12 (phi=67) has not been active in 2009, and the cables have not been switched officially
1377  // In the map, the inactive RBXs have been switched since the changes will be effected when the HO SiPMs
1378  // are installed, also at that time, if it is possible, HO2M04 will be corrected as well.
1379  // Following intervention in May 2009, the aforementioned changes have been implemented.
1380  // All miscablings have been corrected
1381 
1382  // switched HO RM's need reversed eta values
1383  if (mapIOV_ == 1) {
1384  int rmspecialeta_loc[6][6] = {
1385  //there are 6 special cases, corresponding to 6 values of phi
1386  {14, 15, 14, 13, 12, 11}, // ring +2 phi = 5, inverted
1387  {14, 15, 14, 13, 12, 11}, // ring +2 phi = 67, inverted
1388  {10, 9, 8, 7, 6, 5}, // ring -1 phi = 57, inverted
1389  {10, 9, 8, 7, 6, 5}, // ring -1 phi = 65, inverted
1390  {14, 15, 14, 13, 12, 11}, // ring -2 phi = 16, inverted
1391  {14, 15, 14, 13, 12, 11} // ring -2 phi = 31, inverted
1392  };
1393 
1394  std::string rmspeciallet_code_loc[6][6] = {
1395  //there are 6 special cases, corresponding to 6 values of phi
1396  {"X", "B", "C", "D", "E", "F"}, // ring +2 phi = 5, inverted
1397  {"X", "P", "Q", "R", "S", "T"}, // ring +2 phi = 67, inverted
1398  {"G", "H", "J", "K", "L", "M"}, // ring -1 phi = 57, inverted
1399  {"A", "B", "C", "D", "E", "F"}, // ring -1 phi = 65, inverted
1400  {"X", "B", "C", "D", "E", "F"}, // ring -2 phi = 16, inverted
1401  {"X", "P", "Q", "R", "S", "T"} // ring -2 phi = 31, inverted
1402  };
1403 
1404  std::string rmspecialdet_loc[6][6] = {
1405  //there are 6 special cases, corresponding to 6 values of phi
1406  {"HOX", "HO", "HO", "HO", "HO", "HO"}, // ring +2 phi = 5, inverted
1407  {"HOX", "HO", "HO", "HO", "HO", "HO"}, // ring +2 phi = 67, inverted
1408  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 57, inverted
1409  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 65, inverted
1410  {"HOX", "HO", "HO", "HO", "HO", "HO"}, // ring -2 phi = 16, inverted
1411  {"HOX", "HO", "HO", "HO", "HO", "HO"} // ring -2 phi = 31, inverted
1412  };
1413 
1414  memcpy(rmspecialeta, rmspecialeta_loc, sizeof(int) * 6 * 6);
1415  // switched HO RM's need revised letter codes
1416 
1417  for (int jj = 0; jj < 6; jj++) {
1418  for (int kk = 0; kk < 6; kk++) {
1419  rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];
1420  }
1421  }
1422 
1423  for (int jj = 0; jj < 6; jj++) {
1424  for (int kk = 0; kk < 6; kk++) {
1425  rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];
1426  }
1427  }
1428  }
1429 
1430  else if (mapIOV_ == 2) {
1431  int rmspecialeta_loc[6][6] = {
1432  //there are 6 special cases, corresponding to 6 values of phi
1433  {11, 12, 13, 14, 15, 15}, // ring +2 phi = 5
1434  {11, 12, 13, 14, 15, 15}, // ring +2 phi = 67
1435  {5, 6, 7, 8, 9, 10}, // ring -1 phi = 57
1436  {5, 6, 7, 8, 9, 10}, // ring -1 phi = 65
1437  {14, 15, 14, 13, 12, 11}, // ring -2 phi = 16, still inverted
1438  {11, 12, 13, 14, 15, 15} // ring -2 phi = 31
1439  };
1440 
1441  std::string rmspeciallet_code_loc[6][6] = {
1442  //there are 6 special cases, corresponding to 6 values of phi
1443  {"F", "E", "D", "C", "B", "X"}, // ring +2 phi = 5
1444  {"T", "S", "R", "Q", "P", "X"}, // ring +2 phi = 67
1445  {"M", "L", "K", "J", "H", "G"}, // ring -1 phi = 57
1446  {"F", "E", "D", "C", "B", "A"}, // ring -1 phi = 65
1447  {"X", "B", "C", "D", "E", "F"}, // ring -2 phi = 16,still inverted
1448  {"T", "S", "R", "Q", "P", "X"} // ring -2 phi = 31
1449  };
1450 
1451  std::string rmspecialdet_loc[6][6] = {
1452  //there are 6 special cases, corresponding to 6 values of phi
1453  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring +2 phi = 5
1454  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring +2 phi = 67
1455  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 57
1456  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 65
1457  {"HOX", "HO", "HO", "HO", "HO", "HO"}, // ring -2 phi = 16, still inverted
1458  {"HO", "HO", "HO", "HO", "HO", "HOX"} // ring -2 phi = 31
1459  };
1460 
1461  memcpy(rmspecialeta, rmspecialeta_loc, sizeof(int) * 6 * 6);
1462  // switched HO RM's need revised letter codes
1463 
1464  for (int jj = 0; jj < 6; jj++) {
1465  for (int kk = 0; kk < 6; kk++) {
1466  rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];
1467  }
1468  }
1469 
1470  for (int jj = 0; jj < 6; jj++) {
1471  for (int kk = 0; kk < 6; kk++) {
1472  rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];
1473  }
1474  }
1475  }
1476 
1477  else {
1478  int rmspecialeta_loc[6][6] = {
1479  //there are 6 special cases, corresponding to 6 values of phi
1480  {11, 12, 13, 14, 15, 15}, // ring +2 phi = 5
1481  {11, 12, 13, 14, 15, 15}, // ring +2 phi = 67
1482  {5, 6, 7, 8, 9, 10}, // ring -1 phi = 57
1483  {5, 6, 7, 8, 9, 10}, // ring -1 phi = 65
1484  {11, 12, 13, 14, 15, 15}, // ring -2 phi = 16
1485  {11, 12, 13, 14, 15, 15} // ring -2 phi = 31
1486  };
1487 
1488  std::string rmspeciallet_code_loc[6][6] = {
1489  //there are 6 special cases, corresponding to 6 values of phi
1490  {"F", "E", "D", "C", "B", "X"}, // ring +2 phi = 5
1491  {"T", "S", "R", "Q", "P", "X"}, // ring +2 phi = 67
1492  {"M", "L", "K", "J", "H", "G"}, // ring -1 phi = 57
1493  {"F", "E", "D", "C", "B", "A"}, // ring -1 phi = 65
1494  {"F", "E", "D", "C", "B", "X"}, // ring -2 phi = 16
1495  {"T", "S", "R", "Q", "P", "X"} // ring -2 phi = 31
1496  };
1497 
1498  std::string rmspecialdet_loc[6][6] = {
1499  //there are 6 special cases, corresponding to 6 values of phi
1500  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring +2 phi = 5
1501  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring +2 phi = 67
1502  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 57
1503  {"HO", "HO", "HO", "HO", "HO", "HO"}, // ring -1 phi = 65
1504  {"HO", "HO", "HO", "HO", "HO", "HOX"}, // ring -2 phi = 16
1505  {"HO", "HO", "HO", "HO", "HO", "HOX"} // ring -2 phi = 31
1506  };
1507 
1508  memcpy(rmspecialeta, rmspecialeta_loc, sizeof(int) * 6 * 6);
1509  // switched HO RM's need revised letter codes
1510 
1511  for (int jj = 0; jj < 6; jj++) {
1512  for (int kk = 0; kk < 6; kk++) {
1513  rmspeciallet_code[jj][kk] = rmspeciallet_code_loc[jj][kk];
1514  }
1515  }
1516 
1517  for (int jj = 0; jj < 6; jj++) {
1518  for (int kk = 0; kk < 6; kk++) {
1519  rmspecialdet[jj][kk] = rmspecialdet_loc[jj][kk];
1520  }
1521  }
1522  }
1523 
1524  /******************************/
1525 
1526  char tempbuff[30]{0};
1527 
1528  //Stream variable
1529  stringstream mystream;
1530 
1531  //Radical change: HO iterates over eta and phi rather than crate, HTR, etc.
1532  for (isid = -1; isid < 2; isid += 2) {
1533  for (iph = 0; iph < NHOPHI; iph++) {
1534  for (iet = 0; iet < NHOETA; iet++) {
1535  iphi = iph + 1;
1536  ieta = iet + 1;
1537  iside = isid;
1538 
1539  if (iphi >= 71 || iphi < 17)
1540  ic = 0;
1541  else if (iphi >= 17 && iphi < 35)
1542  ic = 1;
1543  else if (iphi >= 35 && iphi < 53)
1544  ic = 2;
1545  else
1546  ic = 3;
1547 
1548  icrate = hocrate[ic];
1549  idepth = 4;
1550  det = "HO";
1551 
1552  //fpga = top/bottom for Ring 0 depends on a pattern that repeats every 30 degrees (6 phi)
1553  //Hence, phmod6 (not phi mod 6 because I don't want to separate 71 and 72, etc.)
1554 
1555  phmod6 = iph % 6;
1556  //Bools associated with phmod6 to be used with htr_fi and the patch panel
1557  phmod6e450 = (phmod6 == 4 || phmod6 == 5 || phmod6 == 0);
1558  phmod6e123 = (phmod6 == 1 || phmod6 == 2 || phmod6 == 3);
1559 
1560  //Ring 0 (HTR type 0) is special
1561  if (ieta <= 3 && (iside < 0 || phmod6 >= 4))
1562  fpga = "bot";
1563  else if (ieta <= 3 && iside > 0 && phmod6 < 4)
1564  fpga = "top";
1565  //new HX HTR
1566  else if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 6))
1567  fpga = "top";
1568  else if ((ieta > 15 && iside > 0) && (icrate == 7 || icrate == 13))
1569  fpga = "bot";
1570  //HTR types 0 and 1
1571  else if (ieta >= 10 && iside > 0)
1572  fpga = "top";
1573  else if (ieta < 10 && ieta >= 6 && iside > 0)
1574  fpga = "bot";
1575  //HTR types 2 and 3
1576  else if ((ieta == 5 && iside > 0) || ieta == 4)
1577  fpga = "top";
1578  else if ((ieta == 5 || ieta >= 10) && iside < 0)
1579  fpga = "bot";
1580  else if ((ieta < 10 && ieta >= 6) && iside < 0)
1581  fpga = "top";
1582  else
1583  edm::LogInfo("HcalLogicalMapGenerator") << "Bad fpga code" << endl;
1584 
1585  //dphi
1586  if (ieta <= 20)
1587  idphi = 1;
1588  else
1589  idphi = -1000;
1590 
1591  //create values usable in arrays from side and fpga
1592  if (iside == 1)
1593  sidear = 1;
1594  else
1595  sidear = 0;
1596 
1597  phmod24 = iph % 24;
1598 
1599  //Again, x - 1 because the array starts at 0 while the variables start at 1
1600  irm = HO_RM_table[phmod24][iet][sidear];
1601 
1602  //x - 5 for the eta array for the same reason
1603  // the new stuff for HX
1604  if (ieta == 16)
1605  irm_fi = HO_RM_fi_eta16;
1606  else if (ieta >= 5)
1607  irm_fi = HO_RM_fi_eta5to15[ieta - 5];
1608  else {
1609  if (mapIOV_ < 5) {
1610  if (ieta <= 3)
1611  irm_fi = HO_RM_fi_eta1to4[phmod24][0][sidear];
1612  else if (ieta == 4)
1613  irm_fi = HO_RM_fi_eta1to4[phmod24][1][sidear];
1614  else
1615  irm_fi = -1000;
1616  } else if (mapIOV_ >= 5) {
1617  irm_fi = HO_RM_fi_eta1to4_sipm[phmod24][ieta - 1][sidear];
1618  }
1619  }
1620 
1621  //HTR fiber
1622 
1623  //
1624  if (ieta >= 5 && phmod6e450)
1625  ihtr_fi = HO_htr_fi_450eta5to15[sidear][ieta - 5];
1626  else if (ieta >= 5 && phmod6e123)
1627  ihtr_fi = HO_htr_fi_450eta5to15[sidear][ieta - 5] - 1;
1628  else if (ieta <= 4) {
1629  if (mapIOV_ < 5) {
1630  if (ieta == 4)
1631  ihtr_fi = HO_htr_fi_eta4[sidear][phmod6];
1632  else if (ieta <= 3)
1633  ihtr_fi = HO_htr_fi_eta123[sidear][phmod6];
1634  } else if (mapIOV_ >= 5) {
1635  ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][ieta - 1][(irm - 1) / 2][sidear];
1636  }
1637  } else
1638  ihtr_fi = -1000;
1639 
1640  //Fiber Channel
1641  //Eta >= 5 bools
1642  phi1458 = (iphi % 12 == 1 || iphi % 12 == 4 || iphi % 12 == 5 || iphi % 12 == 8);
1643  phi271011 = (iphi % 12 == 2 || iphi % 12 == 7 || iphi % 12 == 10 || iphi % 12 == 11);
1644 
1645  //Ring 0 bools
1646  phir0v1 = (iphi % 24 == 0 || iphi % 24 == 2 || iphi % 24 == 4 || iphi % 24 == 18 || iphi % 24 == 20 ||
1647  iphi % 24 == 22);
1648  phir0v2 = (iphi % 24 == 1 || iphi % 24 == 3 || iphi % 24 == 17 || iphi % 24 == 19 || iphi % 24 == 21 ||
1649  iphi % 24 == 23);
1650  //v3: phi 5 to 15 odd; v4: phi 6 to 16 even
1651  phir0v3 = (iphi % 24 == 5 || iphi % 24 == 7 || iphi % 24 == 9 || iphi % 24 == 11 || iphi % 24 == 13 ||
1652  iphi % 24 == 15);
1653  phir0v4 = (iphi % 24 == 6 || iphi % 24 == 8 || iphi % 24 == 10 || iphi % 24 == 12 || iphi % 24 == 14 ||
1654  iphi % 24 == 16);
1655 
1656  if (ieta >= 5) {
1657  if (ieta % 2 == 0 && phi1458)
1658  ifi_ch = 0;
1659  else if (ieta % 2 == 0 && iphi % 3 == 0)
1660  ifi_ch = 1;
1661  else if (ieta % 2 == 0 && phi271011)
1662  ifi_ch = 2;
1663  else if (ieta % 2 == 1 && iphi % 3 == 0)
1664  ifi_ch = 0;
1665  else if (ieta % 2 == 1 && phi271011)
1666  ifi_ch = 1;
1667  else if (ieta % 2 == 1 && phi1458)
1668  ifi_ch = 2;
1669  } else {
1670  if (mapIOV_ < 5) {
1671  if (ieta == 4) {
1672  if (iside == -1) {
1673  if (phir0v1)
1674  ifi_ch = 0;
1675  else if (phir0v4)
1676  ifi_ch = 1;
1677  else if (iphi % 2 == 1)
1678  ifi_ch = 2;
1679  } else {
1680  if (phir0v3)
1681  ifi_ch = 0;
1682  else if (phir0v2)
1683  ifi_ch = 1;
1684  else if (iphi % 2 == 0)
1685  ifi_ch = 2;
1686  }
1687  }
1688  //eta = -3 and eta = +2
1689  else if ((ieta == 3 && iside == -1) || (ieta == 2 && iside == 1)) {
1690  if (phir0v4)
1691  ifi_ch = 0;
1692  else if (phir0v3)
1693  ifi_ch = 1;
1694  else if (phir0v1 || phir0v2)
1695  ifi_ch = 2;
1696  }
1697  //eta = -2 and eta = +3
1698  else if ((ieta == 3 && iside == 1) || (ieta == 2 && iside == -1)) {
1699  if (phir0v2)
1700  ifi_ch = 0;
1701  else if (phir0v1)
1702  ifi_ch = 1;
1703  else if (phir0v3 || phir0v4)
1704  ifi_ch = 2;
1705  }
1706  //ieta = 1
1707  else if (ieta == 1) {
1708  if (phir0v1 || phir0v3)
1709  ifi_ch = 0;
1710  else if (phir0v2 || phir0v4)
1711  ifi_ch = 1;
1712  }
1713  } else {
1714  /*New code here for SiPM handling of rm fiber channel
1715  more challenging and requires some thought*/
1716  if (ieta == 4) {
1717  if (iside == -1) {
1718  if (phir0v1)
1719  ifi_ch = 0;
1720  else if (phir0v4)
1721  ifi_ch = 2;
1722  else if (iphi % 2 == 1)
1723  ifi_ch = 2;
1724  } else {
1725  if (phir0v3)
1726  ifi_ch = 0;
1727  else if (phir0v2)
1728  ifi_ch = 2;
1729  else if (iphi % 2 == 0)
1730  ifi_ch = 2;
1731  }
1732  }
1733  if (ieta == 2) {
1734  if (iside == -1) {
1735  if (iphi % 2 == 0)
1736  ifi_ch = 2;
1737  else if (iphi % 2 == 1)
1738  ifi_ch = 1;
1739  } else {
1740  if (iphi % 2 == 0)
1741  ifi_ch = 1;
1742  else if (iphi % 2 == 1)
1743  ifi_ch = 2;
1744  }
1745  }
1746  if (ieta == 3) {
1747  if (iside == -1) {
1748  if (iphi % 2 == 0)
1749  ifi_ch = 0;
1750  else if (iphi % 2 == 1)
1751  ifi_ch = 1;
1752  } else {
1753  if (iphi % 2 == 1)
1754  ifi_ch = 0;
1755  else if (iphi % 2 == 0)
1756  ifi_ch = 1;
1757  }
1758  }
1759  if (ieta == 1) {
1760  if (iside == -1) {
1761  if (phir0v1)
1762  ifi_ch = 0;
1763  else if (phir0v4)
1764  ifi_ch = 1;
1765  else if (iphi % 2 == 1)
1766  ifi_ch = 0;
1767  } else {
1768  if (phir0v3)
1769  ifi_ch = 0;
1770  else if (phir0v2)
1771  ifi_ch = 1;
1772  else if (iphi % 2 == 0)
1773  ifi_ch = 0;
1774  }
1775  }
1776  }
1777  }
1778 
1779  //Intentional integer truncation; iqie and iadc are the same across all subdetectors
1780  //(Although irm_fi for HF starts at 1 and for HO it starts at 2, so one can't just copy and paste)
1781  iqie = (irm_fi - 2) / 2 + 1;
1782 
1783  if (irm_fi % 2 == 0)
1784  iadc = ifi_ch;
1785  else
1786  iadc = NFCH + (ifi_ch + 1) % 3;
1787 
1788  //Pixel and Letter Code (Ring 0 is separate)
1789  if (ieta <= 4) {
1790  ipixel = ipixelHO[irm_fi - 2][ifi_ch][0];
1791  letter = letterHO[irm_fi - 2][ifi_ch][0];
1792  } else {
1793  ipixel = ipixelHO[irm_fi - 2][ifi_ch][1];
1794  letter = letterHO[irm_fi - 2][ifi_ch][1];
1795  }
1796 
1797  //special treatment for new ring-0 SiPMs fpga
1798  int mytype = -1; //variable that allows grouping of channels
1799  if (ieta <= 4 && mapIOV_ >= 5) {
1800  if (ipixel == 3 || ipixel == 7 || ipixel == 12 || ipixel == 14 || ipixel == 17 || ipixel == 18) {
1801  mytype = 1;
1802  if (phmod6 == 1 || phmod6 == 3)
1803  fpga = "top";
1804  else
1805  fpga = "bot";
1806  } else if (ipixel == 1 || ipixel == 4 || ipixel == 8 || ipixel == 15 || ipixel == 16 || ipixel == 19) {
1807  mytype = 2;
1808  if (phmod6 == 0 || phmod6 == 2)
1809  fpga = "top";
1810  else
1811  fpga = "bot";
1812  } else if (ipixel == 2 || ipixel == 5 || ipixel == 6 || ipixel == 9 || ipixel == 11 || ipixel == 13) {
1813  mytype = 3;
1814  fpga = "top";
1815  }
1816  }
1817 
1818  if (fpga == "bot")
1819  itb = 1; //convention different than for the
1820  else
1821  itb = 0; //electronics id, modified in the
1822  //MapEntry code
1823 
1824  //Determine which of HTR in the set belongs here. It depends only on eta and side.
1825  // the new stuff for HX
1826  if (ieta <= 3 || (ieta >= 14 && iside == 1))
1827  ih = 0;
1828  else if (ieta <= 13 && ieta >= 6 && iside == 1)
1829  ih = 1;
1830  else if (ieta <= 13 && ieta >= 6 && iside == -1)
1831  ih = 3;
1832  else
1833  ih = 2;
1834 
1836  // the htrs are grouped in chunks of ((ph+2) mod 18)/6
1837  //71,72,1,2,3,4
1838  // and indexed by the mytype variable previously defined
1839  int php2mod18 = (iph + 2) % 18;
1840  int php2mod18ov6 = php2mod18 / 6;
1841 
1842  //Each value of "is" covers 30 degrees (that is, 6 values of phi). To calculate which ones,
1843  //I use phi % 18. Crates start at phi = 71, 17, 35, 53
1844 
1845  if (iphi % 18 == 17 || iphi % 18 <= 4)
1846  is = 0;
1847  else if (iphi % 18 >= 5 && iphi % 18 <= 10)
1848  is = 1;
1849  else
1850  is = 2;
1851 
1852  if (ieta == 16 && iside > 0)
1853  ihtr = 21;
1854  else if (ieta > 4)
1855  ihtr = ihslotho[is][ih];
1856  else {
1857  //special treatment only for ring-0
1858  if (mapIOV_ < 5)
1859  ihtr = ihslotho[is][ih];
1860  else {
1861  if (mytype == 1 || mytype == 2)
1862  ih = 0;
1863  else
1864  ih = 2;
1865  ihtr = ihslotho[php2mod18ov6][ih];
1866  }
1867  }
1868 
1869  if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 6))
1870  ispigot = 12;
1871  else if ((ieta > 15 && iside > 0) && (icrate == 7 || icrate == 13))
1872  ispigot = 13;
1873  else
1874  ispigot = ihtr < 9 ? (ihtr - 2) * 2 + itb : (ihtr - 13) * 2 + itb;
1875  idcc = ihtr < 9 ? 1 : 2;
1876  idcc_sl = idcc == 1 ? 10 : 20;
1877 
1878  ifed = fedhonum[ic][idcc - 1];
1879 
1880  //RBX and sector
1881 
1882  if (iside == -1)
1883  sidesign = 'M';
1884  else
1885  sidesign = 'P';
1886 
1887  if (ieta <= 4)
1888  ring = 0;
1889  else if (ieta >= 5 && ieta <= 10)
1890  ring = 1;
1891  else
1892  ring = 2;
1893 
1894  //Sector ranges from 1 to 12 depending on phi. Sector 1 goes 71,72,1,2,3,4 so I start at -2
1895  sector = 0;
1896  for (i = -2; i < iphi; i += 6) {
1897  sector++;
1898  }
1899  if (sector > 12)
1900  sector = 1; //It rolls over for phi = 71,72
1901 
1902  isector = sector;
1903 
1904  //For rings 1 and 2, we only want even sectors for the rbx
1905  if (ring != 0 && sector % 2 != 0)
1906  sector++;
1907 
1908  if (ring == 0)
1909  snprintf(tempbuff, sizeof tempbuff, "%s%i%2.2d", det.c_str(), ring, sector);
1910  else
1911  snprintf(tempbuff, sizeof tempbuff, "%s%i%c%2.2d", det.c_str(), ring, sidesign, sector);
1912  mystream << tempbuff;
1913  rbx = mystream.str();
1914  mystream.str("");
1915  if (ieta == 16) {
1916  det = "HOX";
1917  letter = "X";
1918  } else
1919  det = "HO";
1920 
1921  // the new htr_fi stuff for HX
1922  if (ieta == 16 && isid < 0)
1923  ihtr_fi = HO_htr_fi_450eta16M[irm - 1];
1924  else if (ieta == 16 && isid > 0)
1925  ihtr_fi = HO_htr_fi_450eta16P[irm - 1][sector / 2 - 1];
1926 
1927  if ((ieta > 15 && iside > 0) && (icrate == 3 || icrate == 7)) {
1928  icrate = 6;
1929  ifed = 729;
1930  } else if ((ieta > 15 && iside > 0) && (icrate == 6 || icrate == 13)) {
1931  icrate = 7;
1932  ifed = 727;
1933  }
1934 
1935  if (ieta == 16)
1936  ieta = 15;
1937  // fixing the switched RM's
1938  if (iside == 1 && ring == 2) {
1939  if (iphi == 5) {
1940  ieta = rmspecialeta[0][iet - 10];
1941  letter = rmspeciallet_code[0][iet - 10];
1942  det = rmspecialdet[0][iet - 10];
1943  } else if (iphi == 67) {
1944  ieta = rmspecialeta[1][iet - 10];
1945  letter = rmspeciallet_code[1][iet - 10];
1946  det = rmspecialdet[1][iet - 10];
1947  }
1948  } else if (iside == -1) {
1949  if (ring == 1) {
1950  if (iphi == 57) {
1951  ieta = rmspecialeta[2][iet - 4];
1952  letter = rmspeciallet_code[2][iet - 4];
1953  det = rmspecialdet[2][iet - 4];
1954  } else if (iphi == 65) {
1955  ieta = rmspecialeta[3][iet - 4];
1956  letter = rmspeciallet_code[3][iet - 4];
1957  det = rmspecialdet[3][iet - 4];
1958  }
1959  } else if (ring == 2) {
1960  if (iphi == 16) {
1961  ieta = rmspecialeta[4][iet - 10];
1962  letter = rmspeciallet_code[4][iet - 10];
1963  det = rmspecialdet[4][iet - 10];
1964  } else if (iphi == 31) {
1965  ieta = rmspecialeta[5][iet - 10];
1966  letter = rmspeciallet_code[5][iet - 10];
1967  det = rmspecialdet[5][iet - 10];
1968  }
1969  }
1970  }
1971 
1972  HOHXLogicalMapEntry hoxlmapentry(ifi_ch,
1973  ihtr_fi,
1974  ispigot,
1975  ifed,
1976  icrate,
1977  ihtr,
1978  fpga,
1979  det,
1980  iside,
1981  ieta,
1982  iphi,
1983  idepth,
1984  idphi,
1985  isector,
1986  irm,
1987  irm_fi,
1988  ipixel,
1989  iqie,
1990  iadc,
1991  rbx,
1992  letter);
1993  HOHXEntries.push_back(hoxlmapentry);
1994  LinearIndex2Entry.at(hoxlmapentry.getLinearIndex()) =
1995  HcalLogicalMap::makeEntryNumber(true, 1, HOHXEntries.size() - 1);
1996 
1997  const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
1998  unsigned int denseId;
1999  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
2000  denseId = topo->detId2denseIdHO(hgdi);
2001  HoHash2Entry.at(denseId) = HOHXEntries.size();
2002  } else if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration) {
2003  denseId = topo->detId2denseIdCALIB(hgdi);
2004  HxCalibHash2Entry.at(denseId) = HOHXEntries.size();
2005  }
2006 
2007  if (ring == 0) {
2008  if (ipixel == 1) {
2009  ipixel = 2;
2010  iadc = 4;
2011  if (mapIOV_ < 5)
2012  ifi_ch = 0;
2013  else {
2014  irm_fi = 4;
2015  ifi_ch = 2;
2016  if (irm_fi % 2 == 0)
2017  iadc = ifi_ch;
2018  else
2019  iadc = NFCH + (ifi_ch + 1) % 3;
2020  iqie = (irm_fi - 2) / 2 + 1;
2021  ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][4][(irm - 1) / 2][sidear];
2022  itb = 0;
2023  fpga = "top";
2024  // mytype = 3;
2025  ih = 2;
2026  ihtr = ihslotho[php2mod18ov6][ih];
2027  ispigot = ihtr < 9 ? (ihtr - 2) * 2 + itb : (ihtr - 13) * 2 + itb;
2028  idcc = ihtr < 9 ? 1 : 2;
2029  idcc_sl = idcc == 1 ? 10 : 20;
2030  ifed = fedhonum[ic][idcc - 1];
2031  }
2032  letter = "X";
2033  det = "HOX";
2034  HOHXLogicalMapEntry hoxlmapentry(ifi_ch,
2035  ihtr_fi,
2036  ispigot,
2037  ifed,
2038  icrate,
2039  ihtr,
2040  fpga,
2041  det,
2042  iside,
2043  ieta,
2044  iphi,
2045  idepth,
2046  idphi,
2047  isector,
2048  irm,
2049  irm_fi,
2050  ipixel,
2051  iqie,
2052  iadc,
2053  rbx,
2054  letter);
2055  HOHXEntries.push_back(hoxlmapentry);
2056  LinearIndex2Entry.at(hoxlmapentry.getLinearIndex()) =
2057  HcalLogicalMap::makeEntryNumber(true, 1, HOHXEntries.size() - 1);
2058 
2059  const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
2060  unsigned int denseId;
2061  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
2062  denseId = topo->detId2denseIdHO(hgdi);
2063  HoHash2Entry.at(denseId) = HOHXEntries.size();
2064  } else if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration) {
2065  denseId = topo->detId2denseIdCALIB(hgdi);
2066  HxCalibHash2Entry.at(denseId) = HOHXEntries.size();
2067  }
2068  } else if (ipixel == 17) {
2069  ipixel = 18;
2070  iadc = 1;
2071  if (mapIOV_ < 5)
2072  ifi_ch = 1;
2073  else {
2074  irm_fi = 6;
2075  ifi_ch = 1;
2076  if (irm_fi % 2 == 0)
2077  iadc = ifi_ch;
2078  else
2079  iadc = NFCH + (ifi_ch + 1) % 3;
2080  iqie = (irm_fi - 2) / 2 + 1;
2081  ihtr_fi = HO_htr_fi_eta1234_sipm[phmod6][4][(irm - 1) / 2][sidear];
2082  if (phmod6 == 1 || phmod6 == 3) {
2083  itb = 0;
2084  fpga = "top";
2085  } else {
2086  itb = 1;
2087  fpga = "bot";
2088  }
2089  ispigot = ihtr < 9 ? (ihtr - 2) * 2 + itb : (ihtr - 13) * 2 + itb;
2090  idcc = ihtr < 9 ? 1 : 2;
2091  idcc_sl = idcc == 1 ? 10 : 20;
2092  ifed = fedhonum[ic][idcc - 1];
2093  }
2094  letter = "X";
2095  det = "HOX";
2096  HOHXLogicalMapEntry hoxlmapentry(ifi_ch,
2097  ihtr_fi,
2098  ispigot,
2099  ifed,
2100  icrate,
2101  ihtr,
2102  fpga,
2103  det,
2104  iside,
2105  ieta,
2106  iphi,
2107  idepth,
2108  idphi,
2109  isector,
2110  irm,
2111  irm_fi,
2112  ipixel,
2113  iqie,
2114  iadc,
2115  rbx,
2116  letter);
2117  HOHXEntries.push_back(hoxlmapentry);
2118  LinearIndex2Entry.at(hoxlmapentry.getLinearIndex()) =
2119  HcalLogicalMap::makeEntryNumber(true, 1, HOHXEntries.size() - 1);
2120 
2121  const HcalGenericDetId hgdi(hoxlmapentry.getDetId());
2122  unsigned int denseId;
2123  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
2124  denseId = topo->detId2denseIdHO(hgdi);
2125  HoHash2Entry.at(denseId) = HOHXEntries.size();
2126  } else if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration) {
2127  denseId = topo->detId2denseIdCALIB(hgdi);
2128  HxCalibHash2Entry.at(denseId) = HOHXEntries.size();
2129  }
2130  }
2131  }
2132  }
2133  }
2134  }
2135 }
2136 
2138  std::vector<CALIBLogicalMapEntry>& CALIBEntries,
2139  std::vector<uint32_t>& LinearIndex2Entry,
2140  std::vector<uint32_t>& HxCalibHash2Entry) {
2141  /******************************/
2142  /* CALIB crate numbering in order of FEDID*/
2143  int calibcrate_loc[NCALIBCR] = {4, 0, 1, 5, 11, 15, 17, 14, 10, 9, 7, 6, 13}; //HBHE,HF,HO
2144  memcpy(calibcrate, calibcrate_loc, sizeof(int) * NCALIBCR);
2145  /* CALIB FED numbering of DCCs */
2146  int fedcalibnum_loc[NCALIBCR][2] = {{700, 701},
2147  {702, 703},
2148  {704, 705},
2149  {706, 707},
2150  {708, 709},
2151  {710, 711},
2152  {712, 713},
2153  {714, 715},
2154  {716, 717}, /*calib_hbhe 4,0,1,5,11,15,17,14,10*/
2155  {720, 721}, /*calib_hf 9*/
2156  {726, 727},
2157  {728, 729},
2158  {730, 731}}; //calib_ho 7,6,13
2159  memcpy(fedcalibnum, fedcalibnum_loc, sizeof(int) * NCALIBCR * 2);
2160  /* iphi (lower) starting index for each CALIB crate */
2161  int icalibphis_loc[NCALIBCR] = {3, 11, 19, 27, 35, 43, 51, 59, 67, 27, 17, 35, 53};
2162  memcpy(icalibphis, icalibphis_loc, sizeof(int) * NCALIBCR);
2163  /* icalibsector_min minimum sector on each crate {0,1,4,5,10,11,14,15,17,9,7,6,13}*/
2164  int icalibsector_min_loc[NCALIBCR] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 4, 7, 10};
2165  memcpy(icalibsector_min, icalibsector_min_loc, sizeof(int) * NCALIBCR);
2166  /* icalibsector_max maximum sector on each crate */
2167  int icalibsector_max_loc[NCALIBCR] = {3, 5, 7, 9, 11, 13, 15, 17, 1, 4, 6, 9, 12};
2168  memcpy(icalibsector_max, icalibsector_max_loc, sizeof(int) * NCALIBCR);
2169  //detectors represented on each crate (0 for top, 1 for bot)
2170  std::string detIDCALIB_loc[NCALIBCR][NTOPBOT] = {{"HB", "HE"}, /*crate 4*/
2171  {"HB", "HE"}, /*crate 0*/
2172  {"HB", "HE"}, /*crate 1*/
2173  {"HB", "HE"}, /*crate 5*/
2174  {"HB", "HE"}, /*crate 11*/
2175  {"HB", "HE"}, /*crate 15*/
2176  {"HB", "HE"}, /*crate 17*/
2177  {"HB", "HE"}, /*crate 14*/
2178  {"HB", "HE"}, /*crate 10*/
2179  {"HF", "HF"}, /*crate 9*/
2180  {"HO", "HO"}, /*crate 7*/
2181  {"HO", "HO"}, /*crate 6*/
2182  {"HO", "HO"}}; /*crate 13*/
2183  for (int jj = 0; jj < NCALIBCR; jj++) {
2184  for (int kk = 0; kk < NTOPBOT; kk++) {
2185  detIDCALIB[jj][kk] = detIDCALIB_loc[jj][kk];
2186  }
2187  }
2188 
2189  int nfbr_max_loc[NCALIBCR][NTOPBOT] = {
2190  {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 8}, {4, 4}, {8, 4}, {8, 8}, {8, 4}};
2191  memcpy(nfbr_max, nfbr_max_loc, sizeof(int) * NCALIBCR * NTOPBOT);
2192  //HB only utilizes 4 htr_fibers HE all 8
2193  int calibHOinfo_loc[NHOCR][NTOPBOT][NFBR][2] = {
2194  /*sector and ring of HO for the calib channel*/
2195  {{{4, 0}, {5, 0}, {6, 0}, {}, {6, -2}, {6, -1}, {6, 1}, {6, 2}},
2196  {{4, -2}, {4, -1}, {4, 1}, {4, 2}, {}, {}, {}, {}}}, /*crate 7*/
2197 
2198  {{{7, 0}, {8, 0}, {9, 0}, {}, {8, -2}, {8, -1}, {8, 1}, {8, 2}},
2199  {{1, 0}, {2, 0}, {3, 0}, {}, {2, -2}, {2, -1}, {2, 1}, {2, 2}}}, /*crate 6*/
2200 
2201  {{{10, 0}, {11, 0}, {12, 0}, {}, {10, -2}, {10, -1}, {10, 1}, {10, 2}},
2202  {{12, -2}, {12, -1}, {12, 1}, {12, 2}, {}, {}, {}, {}}} /*crate 13*/
2203  };
2204  memcpy(calibHOinfo, calibHOinfo_loc, sizeof(int) * NHOCR * NTOPBOT * NFBR * 2);
2205 
2206  /*********************************/
2207 
2208  char tempbuff[30]{0};
2209 
2210  //Stream variable
2211 
2212  stringstream mystream;
2213 
2214  ihtr = 8; //calibration units are housed on htr slot 8
2215  idcc = 1;
2216  idcc_sl = 10;
2217  irm_fi = 1; // everything other than HE is on A
2218  det = "";
2219 
2220  /*****************************************************/
2221  /*HBHE calibration channels*/
2222  for (ic = 0; ic < NHBHECR; ic++) {
2223  icrate = calibcrate[ic];
2224  ifed = fedcalibnum[ic][idcc - 1];
2225  /* top and bottom */
2226  for (itb = 0; itb < NTOPBOT; itb++) {
2227  /* 4 or 8 fibers used per HTR FPGA */
2228  for (ifb = 0; ifb < nfbr_max[ic][itb]; ifb++) {
2229  det = detIDCALIB[ic][itb];
2230  ihtr_fi = ifb + 1;
2231  irm_fi = 1; // everything other than he is on A
2232  idphi = 4;
2233  if (itb == 1)
2234  if (ihtr_fi % 2 == 0)
2235  irm_fi = 2; //all of the even fibers in HE are on B rather than A
2236  if (det == "HE") {
2237  ispigot = 13;
2238  fpga = "bot";
2239  if (ihtr_fi == 1 || ihtr_fi == 2 || ihtr_fi == 5 || ihtr_fi == 6) {
2240  iwedge = icalibsector_min[ic];
2241  } else if (ihtr_fi == 3 || ihtr_fi == 4 || ihtr_fi == 7 || ihtr_fi == 8) {
2242  iwedge = icalibsector_max[ic];
2243  }
2244  if (ihtr_fi < 5) {
2245  sidesign = 'M';
2246  S_side = '1';
2247  ieta = -1;
2248  iside = -1;
2249  } else {
2250  sidesign = 'P';
2251  S_side = '1';
2252  ieta = 1;
2253  iside = 1;
2254  }
2255  } else if (det == "HB") {
2256  ispigot = 12;
2257  fpga = "top";
2258  (ihtr_fi % 2 == 1) ? iwedge = icalibsector_min[ic] : iwedge = icalibsector_max[ic];
2259  if (ihtr_fi < 3) {
2260  sidesign = 'M';
2261  S_side = '1';
2262  ieta = -1;
2263  iside = -1;
2264  } else {
2265  sidesign = 'P';
2266  S_side = '1';
2267  ieta = 1;
2268  iside = 1;
2269  }
2270  }
2271  iphi = ((iwedge * idphi) + 71 - idphi) % 72;
2272  subdet = "CALIB_" + det;
2273  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
2274  mystream << tempbuff;
2275  rbx = mystream.str();
2276  mystream.str("");
2277  /* three channels per fiber */
2278  for (ifc = 0; ifc < NFCH; ifc++) {
2279  ifi_ch = ifc;
2280  if (irm_fi == 1) {
2281  if (ifc == 0)
2282  ich_type = 0;
2283  else if (ifc == 1)
2284  ich_type = 1;
2285  else if (ifc == 2) {
2286  if (det == "HB")
2287  ich_type = 2;
2288  else if (det == "HE")
2289  ich_type = 3;
2290  }
2291  } else if (irm_fi == 2) {
2292  if (ifc == 0)
2293  ich_type = 4;
2294  else if (ifc == 1)
2295  ich_type = 5;
2296  else if (ifc == 2)
2297  ich_type = 6;
2298  }
2299  CALIBLogicalMapEntry caliblmapentry(ifi_ch,
2300  ihtr_fi,
2301  ispigot,
2302  ifed,
2303  icrate,
2304  ihtr,
2305  fpga,
2306  det,
2307  ieta,
2308  iphi,
2309  ich_type,
2310  iside,
2311  idphi,
2312  rbx,
2313  iwedge,
2314  irm_fi,
2315  subdet);
2316  CALIBEntries.push_back(caliblmapentry);
2317  LinearIndex2Entry.at(caliblmapentry.getLinearIndex()) =
2318  HcalLogicalMap::makeEntryNumber(true, 2, CALIBEntries.size() - 1);
2319 
2320  const HcalGenericDetId hgdi(caliblmapentry.getDetId());
2321  const unsigned int hashedId = topo->detId2denseIdCALIB(hgdi);
2322  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration)
2323  HxCalibHash2Entry.at(hashedId) = CALIBEntries.size();
2324  }
2325  }
2326  }
2327  }
2328 
2329  /* only one CALIB HF crate */
2330  /* top and bottom */
2331  for (itb = 0; itb < NTOPBOT; itb++) {
2332  /* four CALIB HF fibers per HTR FPGA */
2333  for (ifb = 0; ifb < 4; ifb++) {
2334  /* three channels per fiber */
2335  for (ifc = 0; ifc < NFCH; ifc++) {
2336  icrate = calibcrate[ic];
2337  det = "HF";
2338  ihtr_fi = ifb + 1;
2339  ifi_ch = ifc;
2340  (ihtr_fi == 1) ? iphi = 1 : ((ihtr_fi == 2) ? iphi = 19 : ((ihtr_fi == 3) ? iphi = 37 : iphi = 55));
2341  idphi = 18;
2342  ifed = fedcalibnum[ic][idcc - 1];
2343  (ifc == 0) ? ich_type = 8 : (ifc == 1 ? ich_type = 0 : ich_type = 1);
2344  //changed ch_type of fibre channel 0 from 2 to 8, as per HcalCalibDetId specification
2345  irm_fi = 1;
2346  //Wedge has steps of 3, HF(P/M)2,5,8,11
2347  //iwedge=ihtr_fi;
2348  iwedge = 2 + (ifb * 3);
2349  if (itb == 0) {
2350  ispigot = 12;
2351  fpga = "top";
2352  sidesign = 'P';
2353  iside = 1;
2354  ieta = 1;
2355  } else {
2356  ispigot = 13;
2357  fpga = "bot";
2358  sidesign = 'M';
2359  iside = -1;
2360  ieta = -1;
2361  }
2362  subdet = "CALIB_" + det;
2363  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
2364  mystream << tempbuff;
2365  rbx = mystream.str();
2366  mystream.str("");
2367  CALIBLogicalMapEntry caliblmapentry(ifi_ch,
2368  ihtr_fi,
2369  ispigot,
2370  ifed,
2371  icrate,
2372  ihtr,
2373  fpga,
2374  det,
2375  ieta,
2376  iphi,
2377  ich_type,
2378  iside,
2379  idphi,
2380  rbx,
2381  iwedge,
2382  irm_fi,
2383  subdet);
2384  CALIBEntries.push_back(caliblmapentry);
2385  LinearIndex2Entry.at(caliblmapentry.getLinearIndex()) =
2386  HcalLogicalMap::makeEntryNumber(true, 2, CALIBEntries.size() - 1);
2387 
2388  const HcalGenericDetId hgdi(caliblmapentry.getDetId());
2389  const unsigned int hashedId = topo->detId2denseIdCALIB(hgdi);
2390  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration)
2391  HxCalibHash2Entry.at(hashedId) = CALIBEntries.size();
2392  }
2393  }
2394  }
2395 
2396  /*HO calibration channels*/
2397  for (ic = ic + 1; ic < NCALIBCR; ic++) {
2398  icrate = calibcrate[ic];
2399  irm_fi = 1; // everything other than he is on A
2400  ifed = fedcalibnum[ic][idcc - 1];
2401  /* top and bottom */
2402  for (itb = 0; itb < NTOPBOT; itb++) {
2403  det = detIDCALIB[ic][itb];
2404  /* 4 or 8 fibers used per HTR FPGA */
2405  for (ifb = 0; ifb < nfbr_max[ic][itb]; ifb++) {
2406  if (itb == 1) {
2407  ispigot = 13;
2408  fpga = "bot";
2409  } else {
2410  ispigot = 12;
2411  fpga = "top";
2412  }
2413  ihtr_fi = ifb + 1;
2414  iwedge = calibHOinfo[ic - 10][itb][ifb][0];
2415  ieta = calibHOinfo[ic - 10][itb][ifb][1];
2416  if (ieta < 0) {
2417  iside = -1;
2418  sidesign = 'M';
2419  } else if (ieta > 0) {
2420  iside = 1;
2421  sidesign = 'P';
2422  } else {
2423  iside = 0;
2424  sidesign = '0';
2425  }
2426  if (ieta == -2)
2427  S_side = '2';
2428  else if (ieta == -1)
2429  S_side = '1';
2430  else if (ieta == 1)
2431  S_side = '1';
2432  else if (ieta == 2)
2433  S_side = '2';
2434 
2435  subdet = "CALIB_" + det;
2436  if (ieta == 0)
2437  snprintf(tempbuff, sizeof tempbuff, "%s%c%2.2i", det.c_str(), sidesign, iwedge);
2438  else
2439  snprintf(tempbuff, sizeof tempbuff, "%s%c%c%2.2i", det.c_str(), S_side, sidesign, iwedge);
2440  mystream << tempbuff;
2441  rbx = mystream.str();
2442  mystream.str("");
2443  /* only two channels used in HO per fiber */
2444  //now new information suggests that the third channel is used for x-talk
2445  //but only in some of the rm's, seems to be dependent on whether nfbr_max
2446  //sector 10 on YB+2,1,0,-1, sector 12 on YB-2
2447  int NFCH_HO;
2448  //( nfbr_max[ic][itb] == 4 ) ? NFCH_HO = 2 : NFCH_HO = 3;
2449  (ieta == -2) ? (iwedge == 12 ? NFCH_HO = 3 : NFCH_HO = 2) : (iwedge == 10) ? NFCH_HO = 3 : NFCH_HO = 2;
2450  for (ifc = 0; ifc < NFCH_HO; ifc++) {
2451  ifi_ch = ifc;
2452  (ifi_ch == 2) ? ich_type = 7 : ich_type = ifi_ch;
2453  (ieta == 0) ? idphi = 6 : idphi = 12;
2454 
2455  (ieta == 0) ? iphi = ((iwedge * idphi) + 71 - idphi) % 72 : iphi = (((iwedge / 2) * idphi) + 71 - idphi) % 72;
2456  //nothing on htr_fi=4 for the top
2457  //do {
2458  if (iside == 0 && ifb == 3)
2459  continue; // adjust logic since no longer inside loop
2460  CALIBLogicalMapEntry caliblmapentry(ifi_ch,
2461  ihtr_fi,
2462  ispigot,
2463  ifed,
2464  icrate,
2465  ihtr,
2466  fpga,
2467  det,
2468  ieta,
2469  iphi,
2470  ich_type,
2471  iside,
2472  idphi,
2473  rbx,
2474  iwedge,
2475  irm_fi,
2476  subdet);
2477  CALIBEntries.push_back(caliblmapentry);
2478  LinearIndex2Entry.at(caliblmapentry.getLinearIndex()) =
2479  HcalLogicalMap::makeEntryNumber(true, 2, CALIBEntries.size() - 1);
2480 
2481  const HcalGenericDetId hgdi(caliblmapentry.getDetId());
2482  const unsigned int hashedId = topo->detId2denseIdCALIB(hgdi);
2483  if (hgdi.genericSubdet() == HcalGenericDetId::HcalGenCalibration)
2484  HxCalibHash2Entry.at(hashedId) = CALIBEntries.size();
2485  //} while (ifb!=ifb);
2486  }
2487  }
2488  }
2489  }
2490 }
2491 
2493  std::vector<ZDCLogicalMapEntry>& ZDCEntries,
2494  std::vector<uint32_t>& LinearIndex2Entry,
2495  std::vector<uint32_t>& ZdcHash2Entry) {
2496  /******************************/
2497  /*ZDC channels*/
2498  //Stream variable
2499  stringstream mystream;
2500 
2501  ifed = 722;
2502  iy = 1;
2503  ihtr = 8;
2504  icrate = 12;
2505  idcc = 1;
2506  idcc_sl = 10;
2507  ispigot = 12;
2508  /* side plus and minus */
2509  for (itb = 0; itb < NTOPBOT; itb++) {
2510  if (itb == 0) {
2511  iside = 1;
2512  irm = 1;
2513  fpga = "top";
2514  } else {
2515  iside = -1;
2516  irm = 2;
2517  if (mapIOV_ < 4) {
2518  fpga = "top";
2519  ispigot = 12;
2520  } else {
2521  fpga = "bot";
2522  ispigot = 13;
2523  }
2524  }
2525  /*loop over ZDC cables*/
2526  for (icab = 1; icab < NZDCCAB + 1; icab++) {
2527  if (icab < 4) {
2528  irm_fi = 1;
2529  iadc = icab - 1;
2530  ifi_ch = iadc;
2531  } else if (icab < 7) {
2532  irm_fi = 2;
2533  iadc = icab - 1;
2534  ifi_ch = iadc - 3;
2535  } else {
2536  irm_fi = 3;
2537  iadc = icab - 7;
2538  ifi_ch = iadc;
2539  }
2540  if (itb == 0) {
2541  ihtr_fi = irm_fi;
2542  } else {
2543  if (mapIOV_ < 4)
2544  ihtr_fi = irm_fi + 3;
2545  else
2546  ihtr_fi = irm_fi;
2547  }
2548  if (icab < 6) {
2549  ix = icab;
2550  idepth = 1;
2551  idx = 1;
2552  det = "ZDC_EM";
2553  idet_ch = ix;
2554  iqie = 1;
2555  } else {
2556  ix = 1;
2557  idepth = icab - 4;
2558  idx = 5;
2559  det = "ZDC_HAD";
2560  idet_ch = icab - 5;
2561  if (icab == 6)
2562  iqie = 1;
2563  else
2564  iqie = 2;
2565  }
2566  ZDCLogicalMapEntry zdclmapentry(ifi_ch,
2567  ihtr_fi,
2568  ispigot,
2569  ifed,
2570  icrate,
2571  ihtr,
2572  fpga,
2573  det,
2574  iside,
2575  idepth,
2576  ix,
2577  iy,
2578  idx,
2579  idet_ch,
2580  icab,
2581  irm,
2582  iqie,
2583  iadc,
2584  irm_fi);
2585  ZDCEntries.push_back(zdclmapentry);
2586  LinearIndex2Entry.at(zdclmapentry.getLinearIndex()) =
2587  HcalLogicalMap::makeEntryNumber(true, 3, ZDCEntries.size() - 1);
2588  }
2589  }
2590 }
2591 
2592 /********************************************************/
2594  std::vector<HTLogicalMapEntry>& HTEntries,
2595  int iside,
2596  int ieta,
2597  int iphi,
2598  int idphi,
2599  int idepth,
2600  std::string det,
2601  int iwedge,
2602  int irm,
2603  int ipixel,
2604  int iqie,
2605  int iadc,
2606  int irm_fi,
2607  int ifi_ch,
2608  int icrate,
2609  int ihtr,
2610  std::string fpga,
2611  int ihtr_fi,
2612  int ispigot,
2613  int islb,
2614  std::string slbin,
2615  std::string slbin2,
2616  std::string slnam,
2617  int irctcra,
2618  int irctcar,
2619  int irctcon,
2620  std::string rctnam,
2621  int ifed) {
2622  string t_chDet, t_fpga;
2623  string t_slnam, t_rctnam, t_slbin, t_slbin2;
2624 
2625  int t_nDat = -1;
2626  int t_side, t_iEta, t_iPhi, t_jPhi, t_iDep, t_topbot;
2627  int t_wedge, t_crate, t_htr;
2628  // int t_rm,t_pixel,t_qie,t_adc,t_rm_fi,t_fi_ch,t_htr_fi;
2629  int t_spigo, t_slb, t_rctcra, t_rctcar, t_rctcon, t_fedid;
2630 
2631  //making global variables local for modification
2632  (fpga == "bot") ? t_topbot = 1 : t_topbot = 0;
2633  t_side = iside;
2634  t_iEta = ieta;
2635  t_iPhi = iphi;
2636  t_jPhi = idphi;
2637  t_iDep = idepth;
2638  t_chDet = det;
2639  t_wedge = iwedge;
2640  // t_rm = irm;
2641  // t_pixel = ipixel;
2642  // t_qie = iqie;
2643  // t_adc = iadc;
2644  // t_rm_fi = irm_fi;
2645  // t_fi_ch = ifi_ch;
2646  t_crate = icrate;
2647  t_htr = ihtr;
2648  t_fpga = fpga;
2649  // t_htr_fi = ihtr_fi;
2650  t_spigo = ispigot;
2651  t_slb = islb;
2652  t_slbin = slbin;
2653  t_slbin2 = slbin2;
2654  t_slnam = slnam;
2655  t_rctcra = irctcra;
2656  t_rctcar = irctcar;
2657  t_rctcon = irctcon;
2658  t_rctnam = rctnam;
2659  t_fedid = ifed;
2660 
2661  do {
2662  if (t_iDep != 1)
2663  break;
2664  if (t_chDet == "HE" && t_iEta == 29)
2665  break;
2666 
2667  if (t_chDet == "HF") {
2668  t_jPhi = 4; //20 degree slices in HF
2669  if (t_iEta == 30 || t_iEta == 31 || t_iEta == 33 || t_iEta == 34 || t_iEta == 36 || t_iEta == 37 ||
2670  t_iEta == 39 || t_iEta == 40 || t_iEta == 41)
2671  break;
2672 
2673  else if (t_iEta == 32)
2674  t_iEta = 30;
2675  else if (t_iEta == 35)
2676  t_iEta = 31;
2677  else if (t_iEta == 38)
2678  t_iEta = 32;
2679 
2680  if (t_iPhi == 3 || t_iPhi == 7 || t_iPhi == 11 || t_iPhi == 15 || t_iPhi == 19 || t_iPhi == 23 || t_iPhi == 27 ||
2681  t_iPhi == 31 || t_iPhi == 35 || t_iPhi == 39 || t_iPhi == 43 || t_iPhi == 47 || t_iPhi == 51 ||
2682  t_iPhi == 55 || t_iPhi == 59 || t_iPhi == 63 || t_iPhi == 67 || t_iPhi == 71)
2683  break;
2684  }
2685 
2686  if (t_side < 0)
2687  t_iEta = -t_iEta;
2688  t_chDet = "HT";
2689 
2690  if (t_slbin != "NA") {
2691  if (t_slbin2 != "NA")
2692  t_jPhi = 1;
2693  if (t_slbin == "A0" || t_slbin == "B0")
2694  t_nDat = 0;
2695  else if (t_slbin == "A1" || t_slbin == "B1")
2696  t_nDat = 1;
2697  else if (t_slbin == "C0" || t_slbin == "D0")
2698  t_nDat = 2;
2699  else if (t_slbin == "C1" || t_slbin == "D1")
2700  t_nDat = 3;
2701 
2702  HTLogicalMapEntry htlmapentry(t_iEta,
2703  t_iPhi,
2704  t_side,
2705  t_jPhi,
2706  t_iDep,
2707  t_chDet,
2708  t_wedge,
2709  t_crate,
2710  t_htr,
2711  t_topbot,
2712  t_spigo,
2713  t_slb,
2714  t_slbin,
2715  t_slbin2,
2716  t_nDat,
2717  t_slnam,
2718  t_rctcra,
2719  t_rctcar,
2720  t_rctcon,
2721  t_rctnam,
2722  t_fedid);
2723  HTEntries.push_back(htlmapentry);
2724  }
2725  if (t_slbin2 != "NA") {
2726  if (t_slbin2 == "A0" || t_slbin2 == "B0")
2727  t_nDat = 0;
2728  else if (t_slbin2 == "A1" || t_slbin2 == "B1")
2729  t_nDat = 1;
2730  else if (t_slbin2 == "C0" || t_slbin2 == "D0")
2731  t_nDat = 2;
2732  else if (t_slbin2 == "C1" || t_slbin2 == "D1")
2733  t_nDat = 3;
2734  t_jPhi = 1; //after splitting up these towers, each half should have dphi of 1
2735  t_iPhi += 1;
2736 
2737  HTLogicalMapEntry htlmapentry(t_iEta,
2738  t_iPhi, //changed from t_iPhi + 1 here to the spot above
2739  t_side,
2740  t_jPhi,
2741  t_iDep,
2742  t_chDet,
2743  t_wedge,
2744  t_crate,
2745  t_htr,
2746  t_topbot,
2747  t_spigo,
2748  t_slb,
2749  t_slbin,
2750  t_slbin2,
2751  t_nDat,
2752  t_slnam,
2753  t_rctcra,
2754  t_rctcar,
2755  t_rctcon,
2756  t_rctnam,
2757  t_fedid);
2758  HTEntries.push_back(htlmapentry);
2759  }
2760  } while (1 != 1);
2761 }
const DetId getDetId() const
uint32_t getLinearIndex() const
const uint32_t getLinearIndex() const
static uint32_t makeEntryNumber(bool, int, int)
const DetId getDetId() const
unsigned int detId2denseIdHF(const DetId &id) const
return a linear packed id from HF
unsigned int detId2denseIdHO(const DetId &id) const
return a linear packed id from HO
void buildZDCMap(const HcalTopology *topo, std::vector< ZDCLogicalMapEntry > &, std::vector< uint32_t > &, std::vector< uint32_t > &)
unsigned int detId2denseIdHE(const DetId &id) const
return a linear packed id from HE
unsigned int detId2denseIdCALIB(const DetId &id) const
return a linear packed id from CALIB
unsigned int detId2denseIdHB(const DetId &id) const
return a linear packed id from HB
const uint32_t getLinearIndex() const
HcalLogicalMap createMap(const HcalTopology *topo, unsigned int mapIOV=4)
Log< level::Info, false > LogInfo
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
void buildCALIBMap(const HcalTopology *topo, std::vector< CALIBLogicalMapEntry > &, std::vector< uint32_t > &, std::vector< uint32_t > &)
static const int maxLinearIndex
void buildHOXMap(const HcalTopology *topo, std::vector< HOHXLogicalMapEntry > &, std::vector< uint32_t > &, std::vector< uint32_t > &, std::vector< uint32_t > &)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
const DetId getDetId() const
void ConstructTriggerTower(const HcalTopology *topo, std::vector< HTLogicalMapEntry > &, int i_side, int i_eta, int i_phi, int i_dphi, int i_depth, std::string i_det, int i_wedge, int i_rm, int i_pixel, int i_qie, int i_adc, int i_rm_fi, int i_fi_ch, int i_crate, int i_htr, std::string i_fpga, int i_htr_fi, int i_spigot, int i_slb, std::string i_slbin, std::string i_slbin2, std::string i_slnam, int i_rctcra, int i_rctcar, int i_rctcon, std::string i_rctnam, int i_fed)
void buildHBEFTMap(const HcalTopology *topo, std::vector< HBHEHFLogicalMapEntry > &, std::vector< HTLogicalMapEntry > &, std::vector< uint32_t > &, std::vector< uint32_t > &, std::vector< uint32_t > &, std::vector< uint32_t > &, std::vector< uint32_t > &)
const uint32_t getLinearIndex() const