CMS 3D CMS Logo

AlignableObjectId.cc
Go to the documentation of this file.
2 
3 #include <algorithm>
4 
7 
10  const char *name;
11 };
12 
13 namespace {
14 
15  constexpr AlignableObjectId::entry entries_RunI[]{{align::invalid, "invalid"},
16  {align::AlignableDetUnit, "DetUnit"},
17  {align::AlignableDet, "Det"},
18 
19  {align::TPBModule, "TPBModule"},
20  {align::TPBLadder, "TPBLadder"},
21  {align::TPBLayer, "TPBLayer"},
22  {align::TPBHalfBarrel, "TPBHalfBarrel"},
23  {align::TPBBarrel, "TPBBarrel"},
24 
25  {align::TPEModule, "TPEModule"},
26  {align::TPEPanel, "TPEPanel"},
27  {align::TPEBlade, "TPEBlade"},
28  {align::TPEHalfDisk, "TPEHalfDisk"},
29  {align::TPEHalfCylinder, "TPEHalfCylinder"},
30  {align::TPEEndcap, "TPEEndcap"},
31 
32  {align::TIBModule, "TIBModule"},
33  {align::TIBString, "TIBString"},
34  {align::TIBSurface, "TIBSurface"},
35  {align::TIBHalfShell, "TIBHalfShell"},
36  {align::TIBLayer, "TIBLayer"},
37  {align::TIBHalfBarrel, "TIBHalfBarrel"},
38  {align::TIBBarrel, "TIBBarrel"},
39 
40  {align::TIDModule, "TIDModule"},
41  {align::TIDSide, "TIDSide"},
42  {align::TIDRing, "TIDRing"},
43  {align::TIDDisk, "TIDDisk"},
44  {align::TIDEndcap, "TIDEndcap"},
45 
46  {align::TOBModule, "TOBModule"},
47  {align::TOBRod, "TOBRod"},
48  {align::TOBLayer, "TOBLayer"},
49  {align::TOBHalfBarrel, "TOBHalfBarrel"},
50  {align::TOBBarrel, "TOBBarrel"},
51 
52  {align::TECModule, "TECModule"},
53  {align::TECRing, "TECRing"},
54  {align::TECPetal, "TECPetal"},
55  {align::TECSide, "TECSide"},
56  {align::TECDisk, "TECDisk"},
57  {align::TECEndcap, "TECEndcap"},
58 
59  {align::Pixel, "Pixel"},
60  {align::Strip, "Strip"},
61  {align::Tracker, "Tracker"},
62 
63  {align::AlignableDTBarrel, "DTBarrel"},
64  {align::AlignableDTWheel, "DTWheel"},
65  {align::AlignableDTStation, "DTStation"},
66  {align::AlignableDTChamber, "DTChamber"},
67  {align::AlignableDTSuperLayer, "DTSuperLayer"},
68  {align::AlignableDTLayer, "DTLayer"},
69  {align::AlignableCSCEndcap, "CSCEndcap"},
70  {align::AlignableCSCStation, "CSCStation"},
71  {align::AlignableCSCRing, "CSCRing"},
72  {align::AlignableCSCChamber, "CSCChamber"},
73  {align::AlignableCSCLayer, "CSCLayer"},
74  {align::AlignableMuon, "Muon"},
75 
76  {align::BeamSpot, "BeamSpot"},
77  {align::notfound, nullptr}};
78 
79  constexpr AlignableObjectId::entry entries_PhaseI[]{{align::invalid, "invalid"},
80  {align::AlignableDetUnit, "DetUnit"},
81  {align::AlignableDet, "Det"},
82 
83  {align::TPBModule, "P1PXBModule"},
84  {align::TPBLadder, "P1PXBLadder"},
85  {align::TPBLayer, "P1PXBLayer"},
86  {align::TPBHalfBarrel, "P1PXBHalfBarrel"},
87  {align::TPBBarrel, "P1PXBBarrel"},
88 
89  {align::TPEModule, "P1PXECModule"},
90  {align::TPEPanel, "P1PXECPanel"},
91  {align::TPEBlade, "P1PXECBlade"},
92  {align::TPEHalfDisk, "P1PXECHalfDisk"},
93  {align::TPEHalfCylinder, "P1PXECHalfCylinder"},
94  {align::TPEEndcap, "P1PXECEndcap"},
95 
96  {align::TIBModule, "TIBModule"},
97  {align::TIBString, "TIBString"},
98  {align::TIBSurface, "TIBSurface"},
99  {align::TIBHalfShell, "TIBHalfShell"},
100  {align::TIBLayer, "TIBLayer"},
101  {align::TIBHalfBarrel, "TIBHalfBarrel"},
102  {align::TIBBarrel, "TIBBarrel"},
103 
104  {align::TIDModule, "TIDModule"},
105  {align::TIDSide, "TIDSide"},
106  {align::TIDRing, "TIDRing"},
107  {align::TIDDisk, "TIDDisk"},
108  {align::TIDEndcap, "TIDEndcap"},
109 
110  {align::TOBModule, "TOBModule"},
111  {align::TOBRod, "TOBRod"},
112  {align::TOBLayer, "TOBLayer"},
113  {align::TOBHalfBarrel, "TOBHalfBarrel"},
114  {align::TOBBarrel, "TOBBarrel"},
115 
116  {align::TECModule, "TECModule"},
117  {align::TECRing, "TECRing"},
118  {align::TECPetal, "TECPetal"},
119  {align::TECSide, "TECSide"},
120  {align::TECDisk, "TECDisk"},
121  {align::TECEndcap, "TECEndcap"},
122 
123  {align::Pixel, "Pixel"},
124  {align::Strip, "Strip"},
125  {align::Tracker, "Tracker"},
126 
127  {align::AlignableDTBarrel, "DTBarrel"},
128  {align::AlignableDTWheel, "DTWheel"},
129  {align::AlignableDTStation, "DTStation"},
130  {align::AlignableDTChamber, "DTChamber"},
131  {align::AlignableDTSuperLayer, "DTSuperLayer"},
132  {align::AlignableDTLayer, "DTLayer"},
133  {align::AlignableCSCEndcap, "CSCEndcap"},
134  {align::AlignableCSCStation, "CSCStation"},
135  {align::AlignableCSCRing, "CSCRing"},
136  {align::AlignableCSCChamber, "CSCChamber"},
137  {align::AlignableCSCLayer, "CSCLayer"},
138  {align::AlignableGEMEndcap, "GEMEndcap"},
139  {align::AlignableGEMStation, "GEMStation"},
140  {align::AlignableGEMRing, "GEMRing"},
141  {align::AlignableGEMSuperChamber, "GEMSuperChamber"},
142  {align::AlignableGEMChamber, "GEMChamber"},
143  {align::AlignableGEMEtaPartition, "GEMEtaPartition"},
144  {align::AlignableMuon, "Muon"},
145 
146  {align::BeamSpot, "BeamSpot"},
147  {align::notfound, nullptr}};
148 
149  constexpr AlignableObjectId::entry entries_PhaseII[]{{align::invalid, "invalid"},
150  {align::AlignableDetUnit, "DetUnit"},
151  {align::AlignableDet, "Det"},
152 
153  {align::TPBModule, "P2PXBModule"},
154  {align::TPBLadder, "P2PXBLadder"},
155  {align::TPBLayer, "P2PXBLayer"},
156  {align::TPBHalfBarrel, "P2PXBHalfBarrel"},
157  {align::TPBBarrel, "P2PXBBarrel"},
158 
159  {align::TPEModule, "P2PXECModule"},
160  {align::TPEPanel, "P2PXECPanel"},
161  {align::TPEBlade, "P2PXECBlade"},
162  {align::TPEHalfDisk, "P2PXECHalfDisk"},
163  {align::TPEHalfCylinder, "P2PXECHalfCylinder"},
164  {align::TPEEndcap, "P2PXECEndcap"},
165 
166  // TIB doesn't exit in PhaseII
167  {align::TIBModule, "TIBModule-INVALID"},
168  {align::TIBString, "TIBString-INVALID"},
169  {align::TIBSurface, "TIBSurface-INVALID"},
170  {align::TIBHalfShell, "TIBHalfShell-INVALID"},
171  {align::TIBLayer, "TIBLayer-INVALID"},
172  {align::TIBHalfBarrel, "TIBHalfBarrel-INVALID"},
173  {align::TIBBarrel, "TIBBarrel-INVALID"},
174 
175  {align::TIDModule, "P2OTECModule"},
176  {align::TIDSide, "P2OTECSide"},
177  {align::TIDRing, "P2OTECRing"},
178  {align::TIDDisk, "P2OTECDisk"},
179  {align::TIDEndcap, "P2OTECEndcap"},
180 
181  {align::TOBModule, "P2OTBModule"},
182  {align::TOBRod, "P2OTBRod"},
183  {align::TOBLayer, "P2OTBLayer"},
184  {align::TOBHalfBarrel, "P2OTBHalfBarrel"},
185  {align::TOBBarrel, "P2OTBBarrel"},
186 
187  // TEC doesn't exit in PhaseII
188  {align::TECModule, "TECModule-INVALID"},
189  {align::TECRing, "TECRing-INVALID"},
190  {align::TECPetal, "TECPetal-INVALID"},
191  {align::TECSide, "TECSide-INVALID"},
192  {align::TECDisk, "TECDisk-INVALID"},
193  {align::TECEndcap, "TECEndcap-INVALID"},
194 
195  {align::Pixel, "Pixel"},
196  {align::Strip, "Strip"},
197  {align::Tracker, "Tracker"},
198 
199  {align::AlignableDTBarrel, "DTBarrel"},
200  {align::AlignableDTWheel, "DTWheel"},
201  {align::AlignableDTStation, "DTStation"},
202  {align::AlignableDTChamber, "DTChamber"},
203  {align::AlignableDTSuperLayer, "DTSuperLayer"},
204  {align::AlignableDTLayer, "DTLayer"},
205  {align::AlignableCSCEndcap, "CSCEndcap"},
206  {align::AlignableCSCStation, "CSCStation"},
207  {align::AlignableCSCRing, "CSCRing"},
208  {align::AlignableCSCChamber, "CSCChamber"},
209  {align::AlignableCSCLayer, "CSCLayer"},
210  {align::AlignableGEMEndcap, "GEMEndcap"},
211  {align::AlignableGEMStation, "GEMStation"},
212  {align::AlignableGEMRing, "GEMRing"},
213  {align::AlignableGEMSuperChamber, "GEMSuperChamber"},
214  {align::AlignableGEMChamber, "GEMChamber"},
215  {align::AlignableGEMEtaPartition, "GEMEtaPartition"},
216  {align::AlignableMuon, "Muon"},
217 
218  {align::BeamSpot, "BeamSpot"},
219  {align::notfound, nullptr}};
220 
221  constexpr bool same(char const *x, char const *y) { return !*x && !*y ? true : (*x == *y && same(x + 1, y + 1)); }
222 
223  constexpr char const *objectIdToString(align::StructureType type, AlignableObjectId::entry const *entries) {
224  return !entries->name ? nullptr : entries->type == type ? entries->name : objectIdToString(type, entries + 1);
225  }
226 
227  constexpr enum align::StructureType stringToObjectId(char const *name, AlignableObjectId::entry const *entries) {
228  return !entries->name ? align::invalid
229  : same(entries->name, name) ? entries->type
230  : stringToObjectId(name, entries + 1);
231  }
232 } // namespace
233 
234 //_____________________________________________________________________________
236  switch (geometry) {
238  entries_ = entries_RunI;
239  break;
241  entries_ = entries_PhaseI;
242  break;
244  entries_ = entries_PhaseII;
245  break;
247  entries_ = entries_RunI;
248  break;
250  entries_ = nullptr;
251  break;
252  }
253  if (!entries_) {
254  throw cms::Exception("LogicError") << "@SUB=AlignableObjectId::ctor\n"
255  << "trying to create AlignableObjectId with unspecified geometry";
256  }
257 }
258 
259 //_____________________________________________________________________________
261  const DTGeometry *muonDt,
262  const CSCGeometry *muonCsc,
263  const GEMGeometry *muonGem)
264  : AlignableObjectId(commonGeometry(trackerGeometry(tracker), muonGeometry(muonDt, muonCsc, muonGem))) {}
265 
266 //_____________________________________________________________________________
268 
269 //_____________________________________________________________________________
271 
272 //_____________________________________________________________________________
274  const char *result = objectIdToString(type, entries_);
275 
276  if (result == nullptr) {
277  throw cms::Exception("AlignableObjectIdError") << "Unknown alignableObjectId " << type;
278  }
279 
280  return result;
281 }
282 
283 //_____________________________________________________________________________
285  auto result = stringToObjectId(name, entries_);
286  if (result == -1) {
287  throw cms::Exception("AlignableObjectIdError") << "Unknown alignableObjectId " << name;
288  }
289 
290  return result;
291 }
292 
293 //______________________________________________________________________________
295  if (!geometry)
296  return Geometry::General;
297 
298  if (geometry->isThere(GeomDetEnumerators::P2PXEC)) {
299  // use structure-type <-> name translation for PhaseII geometry
300  return Geometry::PhaseII;
301 
302  } else if (geometry->isThere(GeomDetEnumerators::P1PXEC)) {
303  // use structure-type <-> name translation for PhaseI geometry
304  return Geometry::PhaseI;
305 
306  } else if (geometry->isThere(GeomDetEnumerators::PixelEndcap)) {
307  // use structure-type <-> name translation for RunI geometry
308  return Geometry::RunI;
309 
310  } else {
311  throw cms::Exception("AlignableObjectIdError") << "@SUB=AlignableObjectId::trackerGeometry\n"
312  << "unknown version of TrackerGeometry";
313  }
314 }
315 
317  const CSCGeometry *,
318  const GEMGeometry *) {
319  // muon alignment structure types are identical for all kinds of geometries
320  return Geometry::General;
321 }
322 
324  if (first == Geometry::General)
325  return second;
326  if (second == Geometry::General)
327  return first;
328  if (first == second)
329  return first;
330 
331  throw cms::Exception("AlignableObjectIdError") << "@SUB=AlignableObjectId::commonGeometry\n"
332  << "impossible to find common geometry because the two geometries are "
333  << "different and none of them is 'General'";
334 }
335 
337  const AlignableObjectId &second) {
338  return AlignableObjectId{commonGeometry(first.geometry(), second.geometry())};
339 }
static Geometry trackerGeometry(const TrackerGeometry *)
static Geometry commonGeometry(Geometry, Geometry)
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
align::StructureType nameToType(const std::string &name) const
Convert name to type.
std::string typeToName(align::StructureType type) const
Convert type to name.
static Geometry muonGeometry(const DTGeometry *, const CSCGeometry *, const GEMGeometry *)
U second(std::pair< T, U > const &p)
Class Geometry Contains vector for fit parameters (mean, sigma, etc.) obtained from multiple IOVs See...
Definition: DMRtrends.cc:183
AlignableObjectId(Geometry)
Allows conversion between type and name, and vice-versa.
const entry * entries_
align::StructureType type
const char * idToString(align::StructureType type) const
align::StructureType stringToId(const char *) const
float x