CMS 3D CMS Logo

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