00001 #include "FWCore/Utilities/interface/Exception.h"
00002
00003 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
00004 #include <algorithm>
00005
00006 using namespace align;
00007
00008 namespace {
00009 struct entry {
00010 StructureType type;
00011 const char* name;
00012 };
00013
00014 constexpr entry entries[]{
00015 { invalid , "invalid"},
00016 { AlignableDetUnit, "DetUnit"},
00017 { AlignableDet , "Det"},
00018
00019 {TPBModule , "TPBModule"},
00020 {TPBLadder , "TPBLadder"},
00021 {TPBLayer , "TPBLayer"},
00022 {TPBHalfBarrel , "TPBHalfBarrel"},
00023 {TPBBarrel , "TPBBarrel"},
00024
00025 {TPEModule , "TPEModule"},
00026 {TPEPanel , "TPEPanel"},
00027 {TPEBlade , "TPEBlade"},
00028 {TPEHalfDisk , "TPEHalfDisk"},
00029 {TPEHalfCylinder, "TPEHalfCylinder"},
00030 {TPEEndcap , "TPEEndcap"},
00031
00032 {TIBModule , "TIBModule"},
00033 {TIBString , "TIBString"},
00034 {TIBSurface , "TIBSurface"},
00035 {TIBHalfShell , "TIBHalfShell"},
00036 {TIBLayer , "TIBLayer"},
00037 {TIBHalfBarrel , "TIBHalfBarrel"},
00038 {TIBBarrel , "TIBBarrel"},
00039
00040 {TIDModule , "TIDModule"},
00041 {TIDSide , "TIDSide"},
00042 {TIDRing , "TIDRing"},
00043 {TIDDisk , "TIDDisk"},
00044 {TIDEndcap , "TIDEndcap"},
00045
00046 {TOBModule , "TOBModule"},
00047 {TOBRod , "TOBRod"},
00048 {TOBLayer , "TOBLayer"},
00049 {TOBHalfBarrel , "TOBHalfBarrel"},
00050 {TOBBarrel , "TOBBarrel"},
00051
00052 {TECModule , "TECModule"},
00053 {TECRing , "TECRing"},
00054 {TECPetal , "TECPetal"},
00055 {TECSide , "TECSide"},
00056 {TECDisk , "TECDisk"},
00057 {TECEndcap , "TECEndcap"},
00058
00059 {Pixel , "Pixel"},
00060 {Strip , "Strip"},
00061 {Tracker , "Tracker"},
00062
00063 { AlignableDTBarrel , "DTBarrel"},
00064 { AlignableDTWheel , "DTWheel"},
00065 { AlignableDTStation , "DTStation"},
00066 { AlignableDTChamber , "DTChamber"},
00067 { AlignableDTSuperLayer, "DTSuperLayer"},
00068 { AlignableDTLayer , "DTLayer"},
00069 { AlignableCSCEndcap , "CSCEndcap"},
00070 { AlignableCSCStation , "CSCStation"},
00071 { AlignableCSCRing , "CSCRing"},
00072 { AlignableCSCChamber , "CSCChamber"},
00073 { AlignableCSCLayer , "CSCLayer"},
00074 { AlignableMuon , "Muon"},
00075
00076 { BeamSpot, "BeamSpot"},
00077 {notfound, 0}
00078 };
00079
00080 constexpr bool same(char const *x, char const *y) {
00081 return !*x && !*y ? true : (*x == *y && same(x+1, y+1));
00082 }
00083
00084 constexpr char const *objectIdToString(StructureType type, entry const *entries) {
00085 return !entries->name ? 0 :
00086 entries->type == type ? entries->name :
00087 objectIdToString(type, entries+1);
00088 }
00089
00090 constexpr enum StructureType stringToObjectId(char const *name, entry const *entries) {
00091 return !entries->name ? invalid :
00092 same(entries->name, name) ? entries->type :
00093 stringToObjectId(name, entries+1);
00094 }
00095 }
00096
00097
00098 StructureType
00099 AlignableObjectId::nameToType( const std::string &name) const
00100 {
00101 return stringToId(name.c_str());
00102 }
00103
00104
00105
00106 std::string AlignableObjectId::typeToName( StructureType type ) const
00107 {
00108 return idToString(type);
00109 }
00110
00111 const char *AlignableObjectId::idToString(align::StructureType type)
00112 {
00113 const char *result = objectIdToString(type, entries);
00114
00115 if (result == 0)
00116 {
00117 throw cms::Exception("AlignableObjectIdError")
00118 << "Unknown alignableObjectId " << type;
00119 }
00120
00121 return result;
00122 }
00123
00124 align::StructureType AlignableObjectId::stringToId(const char *name)
00125 {
00126 StructureType result = stringToObjectId(name, entries);
00127 if (result == -1)
00128 {
00129 throw cms::Exception("AlignableObjectIdError")
00130 << "Unknown alignableObjectId " << name;
00131 }
00132
00133 return result;
00134 }