CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Mapper.h
Go to the documentation of this file.
1 #ifndef Mapper_h
2 #define Mapper_h
3 
4 /*
5  * file: Mapper.h
6  * Author: Viktor Khristenko
7  *
8  * Description:
9  * Internal Mapper of vector<ME*> indices. All the possibilities should
10  * be predefined
11  */
12 
16 
17 #include <string>
18 #include <vector>
19 #include <sstream>
20 
21 namespace hcaldqm
22 {
23  namespace mapper
24  {
25  /*
26  * Mapper Type enum:
27  *
28  */
29  using namespace hcaldqm::constants;
31  {
32  // By HCAL subdetector
33  fSubDet = 0,
34 
35  // By Detector Coordinate
36  fiphi = 1,
37  fieta = 2,
38  fdepth = 3,
39 
40  // Detector Combinations
43 
44  // By Electronics Coordinate
45  fFED = 6,
46  fCrate = 7,
47 
48  // Double Electronics Combinations
49  fFED_Slot = 8,
51 
52  // TP Mappers
53  fTPSubDet = 10,
56 
57  // Separating Plus Minus
58  fSubDetPM = 13,
62  fHFPM_iphi = 17,
63 
65 
67  };
68 
69  /*
70  * Index Generation Functions - generate index based on input
71  */
72  struct Input
73  {
74  int i1;
75  int i2;
76  int i3;
77  int i4;
78  };
79  typedef unsigned int(*index_generator)(Input const&);
80  unsigned int generate_fSubDet(Input const&);
81  unsigned int generate_fiphi(Input const&);
82  unsigned int generate_fieta(Input const&);
83  unsigned int generate_fdepth(Input const&);
84  unsigned int generate_fSubDet_iphi(Input const&);
85  unsigned int generate_fSubDet_ieta(Input const&);
86  unsigned int generate_fFED(Input const&);
87  unsigned int generate_fCrate(Input const&);
88  unsigned int generate_fFED_Slot(Input const&);
89  unsigned int generate_fCrate_Slot(Input const&);
90  unsigned int generate_fTPSubDet(Input const&);
91  unsigned int generate_fTPSubDet_iphi(Input const&);
92  unsigned int generate_fTPSubDet_ieta(Input const&);
93  unsigned int generate_fSubDetPM(Input const&);
94  unsigned int generate_fSubDetPM_iphi(Input const&);
95  unsigned int generate_fTPSubDetPM(Input const&);
96  unsigned int generate_fTPSubDetPM_iphi(Input const&);
97  unsigned int generate_fHFPM_iphi(Input const&);
98  unsigned int generate_fHBHEPartition(Input const&);
108 
109  /*
110  * Mapper Class
111  */
112  class Mapper
113  {
114  public:
115  Mapper(): _type(fSubDet) {}
116  Mapper(MapperType type) : _type(type)
117  {
118  this->setSize();
119  }
120  virtual ~Mapper() {}
121 
122  virtual void initialize(MapperType type, int debug=0)
123  {
124  _type = type;
125  this->setSize();
126  _logger.set("Mapper", debug);
127  }
128  virtual unsigned int index() {return 0;}
129  virtual unsigned int index(double) { return 0;}
130  virtual unsigned int index(int x)
131  {
132  Input i; i.i1=x;
133  if (_type==fFED)
134  return vindex[_type](i);
135 
136  return 0;
137  }
138 
139  virtual unsigned int index(HcalDetId const& did)
140  {
141  Input i;
142  if (_type==fSubDet)
143  i.i1 = did.subdet();
144  else if (_type==fiphi)
145  i.i1 = did.iphi();
146  else if (_type==fieta)
147  i.i1 = did.ieta();
148  else if (_type==fdepth)
149  i.i1 = did.depth();
150  else if (_type==fSubDet_iphi)
151  {
152  i.i1 = did.subdet();
153  i.i2 = did.iphi();
154  }
155  else if (_type==fSubDet_ieta)
156  {
157  i.i1 = did.subdet();
158  i.i2 = did.ieta();
159  }
160  else if (_type==fSubDetPM)
161  {
162  i.i1 = did.subdet();
163  i.i2 = did.ieta()>0 ? 1 : 0;
164  }
165  else if (_type==fSubDetPM_iphi)
166  {
167  i.i1 = did.subdet();
168  i.i2 = did.iphi();
169  i.i3 = did.ieta()>0 ? 1 : 0;
170  }
171  else if (_type==fHFPM_iphi)
172  {
173  i.i1 = did.iphi();
174  i.i2 = did.ieta()>0 ? 1 : 0;
175  }
176  else if (_type==fHBHEPartition)
177  {
178  i.i1 = did.iphi();
179  }
180 
181  return vindex[_type](i);
182  }
183  virtual unsigned int index(HcalElectronicsId const& eid)
184  {
185  Input i;
186  if (_type==fCrate)
187  i.i1 = eid.crateId();
188  else if (_type==fCrate_Slot)
189  {
190  i.i1 = eid.crateId();
191  i.i2 = eid.slot();
192  }
193  return vindex[_type](i);
194  }
195 
196  virtual unsigned index(HcalTrigTowerDetId const& tid)
197  {
198  Input i;
199  switch(_type)
200  {
201  case fTPSubDet:
202  i.i1 = tid.ietaAbs();
203  break;
204  case fTPSubDet_iphi:
205  i.i1 = tid.ietaAbs();
206  i.i2 = tid.iphi();
207  break;
208  case fTPSubDet_ieta:
209  i.i1 = tid.ieta();
210  break;
211  case fTPSubDetPM:
212  i.i1 = tid.ieta();
213  break;
214  case fTPSubDetPM_iphi:
215  i.i1 = tid.ieta();
216  i.i2 = tid.iphi();
217  break;
218  default:
219  return 0;
220  break;
221  }
222 
223  return vindex[_type](i);
224  }
225 
226  virtual std::string buildName(unsigned id)
227  {
228  _logger.debug(id);
229  _logger.debug(_type);
230  std::string builtname;
231  switch(_type)
232  {
233  case fSubDet:
234  builtname = constants::SUBDET_NAME[id];
235  break;
236  case fiphi :
237  {
238  char name[10];
239  sprintf(name, "iphi%d",
241  builtname = name;
242  break;
243  }
244  case fHFPM_iphi:
245  {
246  char name[20];
247  if (id>=IPHI_NUM_HF)
248  sprintf(name, "HFPiphi%d",
249  (id-IPHI_NUM_HF)*IPHI_DELTA_HF +
250  IPHI_MIN);
251  else
252  sprintf(name, "HFMiphi%d",
253  id*IPHI_DELTA_HF + IPHI_MIN);
254 
255  builtname = name;
256  break;
257  }
258  case fieta :
259  {
260  char name[10];
261  int ieta = id<(constants::IETA_NUM/2) ?
263  (id-constants::IETA_NUM/2)*constants::IETA_DELTA
265  sprintf(name, "ieta%d", ieta);
266  builtname = name;
267  break;
268  }
269  case fdepth:
270  {
271  char name[10];
272  sprintf(name, "Depth%d", id+1);
273  builtname = name;
274  break;
275  }
276  case fSubDet_iphi:
277  {
278  char name[20];
279  if (id>=IPHI_NUM*3) // HF
280  sprintf(name, "HFiphi%d",
281  (id-3*constants::IPHI_NUM)*
283  else if (id>=2*constants::IPHI_NUM) // HO
284  sprintf(name, "HOiphi%d",
285  (id-2*constants::IPHI_NUM)*
287  else if (id>=constants::IPHI_NUM) // HE
288  sprintf(name, "HEiphi%d",
289  (id-constants::IPHI_NUM)*
291  else
292  sprintf(name, "HBiphi%d",
294 
295  builtname = name;
296  break;
297  }
298  case fSubDet_ieta:
299  {
300  char name[20];
301  unsigned int totalHB = IETA_MAX_HB-IETA_MIN_HB+1;
302  unsigned int totalHE = IETA_MAX_HE-IETA_MIN_HE+1;
303  unsigned int totalHO = IETA_MAX_HO-IETA_MIN_HO+1;
304  unsigned int totalHF = IETA_MAX_HF-IETA_MIN_HF+1;
305  if (id>=(2*(totalHB+totalHE+totalHO)+totalHF))
306  sprintf(name, "HFPieta%d",
307  (id-2*totalHB-2*totalHE-2*totalHO-totalHF) +
308  IETA_MIN_HF);
309  else if (id>=(2*totalHB + 2*totalHE + 2*totalHO))
310  sprintf(name, "HFMieta%d",
311  -((id-2*totalHB-2*totalHE-2*totalHO) +
312  IETA_MIN_HF));
313  else if (id>=(2*totalHB+2*totalHE+totalHO))
314  sprintf(name, "HOPieta%d",
315  (id-2*totalHB-2*totalHE-totalHO +
316  IETA_MIN_HO));
317  else if (id>=(2*totalHB+2*totalHE))
318  sprintf(name, "HOMieta%d",
319  -(id-2*totalHB-2*totalHE + IETA_MIN_HO));
320  else if (id>=(2*totalHB+totalHE))
321  sprintf(name, "HEPieta%d",
322  (id-2*totalHB-totalHE + IETA_MIN_HE));
323  else if (id>=(2*totalHB))
324  sprintf(name, "HEMieta%d",
325  -(id-2*totalHB+IETA_MIN_HE));
326  else if (id>=totalHB)
327  sprintf(name, "HBPieta%d",
328  id-totalHB+IETA_MIN_HB);
329  else
330  sprintf(name, "HBMieta%d",
331  -(id+IETA_MIN_HB));
332 
333  builtname = name;
334  break;
335  }
336  case fCrate:
337  {
338  char name[20];
339  if (id>=CRATE_VME_NUM)
340  sprintf(name, "CRATE%d",
343  else
344  sprintf(name, "CRATE%d",
346 
347  builtname = name;
348  break;
349  }
350  case fFED:
351  {
352  char name[20];
353  if (id>=FED_VME_NUM)
354  sprintf(name, "FED%d",
356  else
357  sprintf(name, "FED%d",
359  builtname = name;
360  break;
361  }
362  case fCrate_Slot:
363  {
364  char name[20];
365  if (id>=CRATE_VME_NUM*SLOT_VME_NUM)
366  {
367  int newid = id - CRATE_VME_NUM*SLOT_VME_NUM;
368  int icrate = newid/SLOT_uTCA_NUM;
369  int islot = newid%SLOT_uTCA_NUM;
370  sprintf(name, "CRATE%dSLOT%d",
371  icrate+CRATE_uTCA_MIN, islot+SLOT_uTCA_MIN);
372  }
373  else
374  {
375  int icrate = id/SLOT_VME_NUM;
376  int islot = id%SLOT_VME_NUM;
377  if (islot>=SLOT_VME_NUM1)
378  sprintf(name, "CRATE%dSLOT%d",
379  icrate+CRATE_VME_MIN,
381  else
382  sprintf(name, "CRATE%dSLOT%d",
383  icrate+CRATE_VME_MIN,
384  islot+SLOT_VME_MIN);
385  }
386  builtname = name;
387  break;
388  }
389  case fTPSubDet:
390  {
391  builtname = constants::TPSUBDET_NAME[id];
392  break;
393  }
394  case fTPSubDet_iphi:
395  {
396  char name[20];
397  if (id>=IPHI_NUM)
398  sprintf(name, "HFiphi%d",
400  IPHI_MIN);
401  else
402  sprintf(name, "HBHEiphi%d",
403  id+IPHI_MIN);
404  builtname = name;
405 
406  break;
407  }
408  case fTPSubDet_ieta:
409  {
410  char name[20];
411  unsigned int totalHBHE = IETA_MAX_TPHBHE - IETA_MIN+1;
412  unsigned int totalHF = IETA_MAX_TPHF - IETA_MIN_HF+1;
413  if (id>=(2*totalHBHE+totalHF))
414  sprintf(name, "HFPieta%d",
415  id - 2*totalHBHE-totalHF+IETA_MIN_HF);
416  else if (id>=2*totalHBHE)
417  sprintf(name, "HFMieta%d",
418  -(id - 2*totalHBHE + IETA_MIN_HF));
419  else if (id>=totalHBHE)
420  sprintf(name, "HBHEPieta%d",
421  id-totalHBHE+IETA_MIN);
422  else
423  sprintf(name, "HBHEMieta%d",
424  -(id+IETA_MIN));
425 
426  builtname = name;
427  break;
428  }
429  case fSubDetPM:
430  {
431  builtname = constants::SUBDETPM_NAME[id];
432  break;
433  }
434  case fSubDetPM_iphi:
435  {
436  char name[20];
437  if (id>=(IPHI_NUM*6)+IPHI_NUM_HF) // HFP
438  sprintf(name, "HFPiphi%d",
439  (id-6*IPHI_NUM-IPHI_NUM_HF)*
442  else if (id>=6*IPHI_NUM) // HFM
443  sprintf(name, "HFMiphi%d",
444  (id-6*IPHI_NUM)*
447  else if (id>=5*IPHI_NUM) // HOP
448  sprintf(name, "HOPiphi%d",
449  (id-5*IPHI_NUM)*
451  else if (id>=4*IPHI_NUM) // HOM
452  sprintf(name, "HOMiphi%d",
453  (id-4*IPHI_NUM)*
455  else if (id>=3*IPHI_NUM) // HEP
456  sprintf(name, "HEPiphi%d",
457  (id-3*IPHI_NUM)*
459  else if (id>=2*IPHI_NUM) // HEM
460  sprintf(name, "HEMiphi%d",
461  (id-2*IPHI_NUM)*
463  else if (id>=IPHI_NUM) // HBP
464  sprintf(name, "HBPiphi%d",
466  else // HBM
467  sprintf(name, "HBMiphi%d",
468  id*IPHI_DELTA+IPHI_MIN);
469 
470  builtname = name;
471  break;
472  }
473  case fTPSubDetPM:
474  {
475  builtname = constants::TPSUBDETPM_NAME[id];
476  break;
477  }
478  case fTPSubDetPM_iphi:
479  {
480  char name[20];
481  if (id>=(2*IPHI_NUM+IPHI_NUM_TPHF))
482  sprintf(name, "HFPiphi%d",
483  (id-2*IPHI_NUM-IPHI_NUM_TPHF)*
485  else if (id>=2*IPHI_NUM)
486  sprintf(name, "HFMiphi%d",
487  (id-2*IPHI_NUM)*
489  else if (id>=IPHI_NUM)
490  sprintf(name, "HBHEPiphi%d",
492  else
493  sprintf(name, "HBHEMiphi%d",
494  id*IPHI_DELTA+IPHI_MIN);
495  builtname = name;
496  break;
497  }
498  case fHBHEPartition:
499  {
500  if (id==0)
501  builtname = "HBHEa";
502  else if (id==1)
503  builtname = "HBHEb";
504  else if (id==2)
505  builtname = "HBHEc";
506  break;
507  }
508  default:
509  {
510  return std::string("UNKNOWN");
511  break;
512  }
513  }
514  return builtname;
515  }
516 
517  inline unsigned int getSize() {return _size;}
518 
519  protected:
521  unsigned int _size;
523  void setSize()
524  {
525  switch (_type)
526  {
527  case fSubDet :
528  _size = SUBDET_NUM;
529  break;
530  case fiphi:
531  _size = IPHI_NUM;
532  break;
533  case fieta:
534  _size = IETA_NUM;
535  break;
536  case fdepth:
537  _size = DEPTH_NUM;
538  break;
539  case fSubDet_iphi:
540  _size = (SUBDET_NUM-1)*IPHI_NUM +
542  break;
543  case fSubDet_ieta:
544  _size = 2*(IETA_MAX_HB-IETA_MIN_HB+1) +
545  2*(IETA_MAX_HE-IETA_MIN_HE+1) +
546  2*(IETA_MAX_HO-IETA_MIN_HO+1)+
547  2*(IETA_MAX_HF-IETA_MIN_HF+1);
548  break;
549  case fFED:
550  _size = FED_VME_NUM+FED_uTCA_NUM;
551  break;
552  case fCrate:
553  _size = CRATE_VME_NUM+CRATE_uTCA_NUM;
554  break;
555  case fCrate_Slot:
556  _size = CRATE_VME_NUM*SLOT_VME_NUM +
557  CRATE_uTCA_NUM*SLOT_uTCA_NUM;
558  break;
559  case fTPSubDet:
560  _size = 2;
561  break;
562  case fTPSubDet_iphi:
564  break;
565  case fTPSubDet_ieta:
566  _size = 2*(IETA_MAX_TPHBHE-IETA_MIN+1)+
568  break;
569  case fSubDetPM:
570  _size = 8;
571  break;
572  case fSubDetPM_iphi:
573  // 6 * 72 + 2*72/2 for the current detecto
574  _size = 6*IPHI_NUM+2*IPHI_NUM/IPHI_DELTA_HF;
575  break;
576  case fTPSubDetPM:
577  _size = 4;
578  break;
579  case fTPSubDetPM_iphi:
580  _size = 2*IPHI_NUM + 2*IPHI_NUM/IPHI_DELTA_TPHF;
581  break;
582  case fHFPM_iphi:
583  _size = 72;
584  break;
585  case fHBHEPartition:
586  _size = 3;
587  break;
588  default:
589  _size = 0;
590  }
591  }
592  };
593  }
594 }
595 
596 #endif
597 
598 
599 
600 
601 
602 
603 
604 
Definition: Logger.h:6
type
Definition: HCALResponse.h:21
int const IETA_MAX_HF
Definition: Constants.h:119
int const IETA_MIN_HO
Definition: Constants.h:116
int i
Definition: DBlmapReader.cc:9
int const IPHI_NUM
Definition: Constants.h:100
int const CRATE_VME_MIN
Definition: Constants.h:38
index_generator const vindex[nMapperType]
Definition: Mapper.h:99
int const SUBDET_NUM
Definition: Constants.h:87
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
std::string const TPSUBDETPM_NAME[2 *TPSUBDET_NUM]
Definition: Constants.h:94
int const IETA_MAX_HB
Definition: Constants.h:113
unsigned int generate_fCrate(Input const &)
Definition: Mapper.cc:119
int const IETA_NUM
Definition: Constants.h:111
virtual unsigned int index()
Definition: Mapper.h:128
int const IETA_MIN_HE
Definition: Constants.h:114
unsigned int generate_fieta(Input const &)
Definition: Mapper.cc:26
int const IETA_MIN
Definition: Constants.h:108
unsigned int generate_fCrate_Slot(Input const &)
Definition: Mapper.cc:140
int const CRATE_uTCA_NUM
Definition: Constants.h:46
virtual std::string buildName(unsigned id)
Definition: Mapper.h:226
int const IPHI_MIN
Definition: Constants.h:98
unsigned int _size
Definition: Mapper.h:521
int ieta() const
get the tower ieta
virtual unsigned int index(HcalDetId const &did)
Definition: Mapper.h:139
int const SLOT_VME_NUM
Definition: Constants.h:60
int crateId() const
get the readout VME crate number
int const FED_uTCA_MIN
Definition: Constants.h:31
int const SLOT_VME_MIN2
Definition: Constants.h:56
int const IETA_MIN_HB
Definition: Constants.h:112
unsigned int(* index_generator)(Input const &)
Definition: Mapper.h:79
unsigned int generate_fTPSubDet(Input const &)
Definition: Mapper.cc:161
int depth() const
get the tower depth
Definition: HcalDetId.cc:106
std::string const SUBDET_NAME[SUBDET_NUM]
Definition: Constants.h:89
unsigned int generate_fSubDetPM_iphi(Input const &)
Definition: Mapper.cc:198
unsigned int generate_fiphi(Input const &)
Definition: Mapper.cc:18
unsigned int generate_fdepth(Input const &)
Definition: Mapper.cc:38
int const FED_VME_MIN
Definition: Constants.h:26
int const FED_uTCA_DELTA
Definition: Constants.h:34
unsigned int generate_fSubDet(Input const &)
Definition: Mapper.cc:9
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
std::string const SUBDETPM_NAME[2 *SUBDET_NUM]
Definition: Constants.h:90
int const IPHI_NUM_HF
Definition: Constants.h:101
virtual unsigned index(HcalTrigTowerDetId const &tid)
Definition: Mapper.h:196
unsigned int generate_fTPSubDet_ieta(Input const &)
Definition: Mapper.cc:177
int const IETA_MAX_TPHF
Definition: Constants.h:122
int const IPHI_DELTA_HF
Definition: Constants.h:104
int const SLOT_VME_MIN
Definition: Constants.h:54
int const IETA_MAX_HO
Definition: Constants.h:117
MapperType _type
Definition: Mapper.h:520
int const IETA_MAX_TPHBHE
Definition: Constants.h:121
int const CRATE_uTCA_MIN
Definition: Constants.h:43
int const SLOT_VME_NUM1
Definition: Constants.h:58
int const FED_VME_DELTA
Definition: Constants.h:28
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:101
virtual unsigned int index(HcalElectronicsId const &eid)
Definition: Mapper.h:183
int const CRATE_VME_DELTA
Definition: Constants.h:40
unsigned int generate_fFED_Slot(Input const &)
Definition: Mapper.cc:135
#define debug
Definition: HDRShower.cc:19
unsigned int generate_fHBHEPartition(Input const &)
Definition: Mapper.cc:263
std::string const TPSUBDET_NAME[TPSUBDET_NUM]
Definition: Constants.h:93
int const FED_uTCA_NUM
Definition: Constants.h:33
int const DEPTH_NUM
Definition: Constants.h:128
Mapper(MapperType type)
Definition: Mapper.h:116
int slot() const
get the htr or uHTR slot
int const FED_VME_NUM
Definition: Constants.h:29
int const IPHI_NUM_TPHF
Definition: Constants.h:102
int const CRATE_VME_NUM
Definition: Constants.h:41
unsigned int generate_fTPSubDet_iphi(Input const &)
Definition: Mapper.cc:166
int const IETA_MIN_HF
Definition: Constants.h:118
unsigned int generate_fSubDet_ieta(Input const &)
Definition: Mapper.cc:70
int const SLOT_uTCA_NUM
Definition: Constants.h:52
int const IETA_MAX_HE
Definition: Constants.h:115
virtual unsigned int index(int x)
Definition: Mapper.h:130
unsigned int getSize()
Definition: Mapper.h:517
unsigned int generate_fSubDetPM(Input const &)
Definition: Mapper.cc:193
unsigned int generate_fSubDet_iphi(Input const &)
Definition: Mapper.cc:47
unsigned int generate_fFED(Input const &)
Definition: Mapper.cc:107
int const CRATE_uTCA_DELTA
Definition: Constants.h:45
virtual unsigned int index(double)
Definition: Mapper.h:129
int const IPHI_DELTA_TPHF
Definition: Constants.h:105
Readout chain identification for Hcal.
unsigned int generate_fHFPM_iphi(Input const &)
Definition: Mapper.cc:257
int ietaAbs() const
get the absolute value of the tower ieta
int iphi() const
get the tower iphi
int const IETA_DELTA
Definition: Constants.h:109
int const SLOT_uTCA_MIN
Definition: Constants.h:49
unsigned int generate_fTPSubDetPM(Input const &)
Definition: Mapper.cc:225
int const IPHI_DELTA
Definition: Constants.h:103
unsigned int generate_fTPSubDetPM_iphi(Input const &)
Definition: Mapper.cc:239
virtual void initialize(MapperType type, int debug=0)
Definition: Mapper.h:122