CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlignableObjectId.cc
Go to the documentation of this file.
2 
4 #include <algorithm>
5 
6 using namespace align;
7 
8 namespace {
9  struct entry {
11  const char* name;
12  };
13 
14  constexpr entry entries[]{
15  { invalid , "invalid"},
16  { AlignableDetUnit, "DetUnit"},
17  { AlignableDet , "Det"},
18 
19  {TPBModule , "TPBModule"},
20  {TPBLadder , "TPBLadder"},
21  {TPBLayer , "TPBLayer"},
22  {TPBHalfBarrel , "TPBHalfBarrel"},
23  {TPBBarrel , "TPBBarrel"},
24 
25  {TPEModule , "TPEModule"},
26  {TPEPanel , "TPEPanel"},
27  {TPEBlade , "TPEBlade"},
28  {TPEHalfDisk , "TPEHalfDisk"},
29  {TPEHalfCylinder, "TPEHalfCylinder"},
30  {TPEEndcap , "TPEEndcap"},
31 
32  {TIBModule , "TIBModule"},
33  {TIBString , "TIBString"},
34  {TIBSurface , "TIBSurface"},
35  {TIBHalfShell , "TIBHalfShell"},
36  {TIBLayer , "TIBLayer"},
37  {TIBHalfBarrel , "TIBHalfBarrel"},
38  {TIBBarrel , "TIBBarrel"},
39 
40  {TIDModule , "TIDModule"},
41  {TIDSide , "TIDSide"},
42  {TIDRing , "TIDRing"},
43  {TIDDisk , "TIDDisk"},
44  {TIDEndcap , "TIDEndcap"},
45 
46  {TOBModule , "TOBModule"},
47  {TOBRod , "TOBRod"},
48  {TOBLayer , "TOBLayer"},
49  {TOBHalfBarrel , "TOBHalfBarrel"},
50  {TOBBarrel , "TOBBarrel"},
51 
52  {TECModule , "TECModule"},
53  {TECRing , "TECRing"},
54  {TECPetal , "TECPetal"},
55  {TECSide , "TECSide"},
56  {TECDisk , "TECDisk"},
57  {TECEndcap , "TECEndcap"},
58 
59  {Pixel , "Pixel"},
60  {Strip , "Strip"},
61  {Tracker , "Tracker"},
62 
63  { AlignableDTBarrel , "DTBarrel"},
64  { AlignableDTWheel , "DTWheel"},
65  { AlignableDTStation , "DTStation"},
66  { AlignableDTChamber , "DTChamber"},
67  { AlignableDTSuperLayer, "DTSuperLayer"},
68  { AlignableDTLayer , "DTLayer"},
69  { AlignableCSCEndcap , "CSCEndcap"},
70  { AlignableCSCStation , "CSCStation"},
71  { AlignableCSCRing , "CSCRing"},
72  { AlignableCSCChamber , "CSCChamber"},
73  { AlignableCSCLayer , "CSCLayer"},
74  { AlignableMuon , "Muon"},
75 
76  { BeamSpot, "BeamSpot"},
77  {notfound, 0}
78  };
79 
80  constexpr bool same(char const *x, char const *y) {
81  return !*x && !*y ? true : (*x == *y && same(x+1, y+1));
82  }
83 
84  constexpr char const *objectIdToString(StructureType type, entry const *entries) {
85  return !entries->name ? 0 :
86  entries->type == type ? entries->name :
87  objectIdToString(type, entries+1);
88  }
89 
90  constexpr enum StructureType stringToObjectId(char const *name, entry const *entries) {
91  return !entries->name ? invalid :
92  same(entries->name, name) ? entries->type :
93  stringToObjectId(name, entries+1);
94  }
95 }
96 
97 //__________________________________________________________________________________________________
100 {
101  return stringToId(name.c_str());
102 }
103 
104 
105 //__________________________________________________________________________________________________
107 {
108  return idToString(type);
109 }
110 
112 {
113  const char *result = objectIdToString(type, entries);
114 
115  if (result == 0)
116  {
117  throw cms::Exception("AlignableObjectIdError")
118  << "Unknown alignableObjectId " << type;
119  }
120 
121  return result;
122 }
123 
125 {
126  StructureType result = stringToObjectId(name, entries);
127  if (result == -1)
128  {
129  throw cms::Exception("AlignableObjectIdError")
130  << "Unknown alignableObjectId " << name;
131  }
132 
133  return result;
134 }
type
Definition: HCALResponse.h:21
std::string typeToName(align::StructureType type) const
Convert type to name.
static align::StructureType stringToId(const char *)
tuple result
Definition: query.py:137
align::StructureType nameToType(const std::string &name) const
Convert name to type.
Definition: DDAxes.h:10
static const char * idToString(align::StructureType type)
#define constexpr