00001
00014
00015 #include "CondFormats/L1TObjects/interface/L1GtDefinitions.h"
00016
00017
00018 #include <cstring>
00019
00020
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 namespace {
00023 template <class T>
00024 struct entry {
00025 char const* label;
00026 T value;
00027 };
00028
00029 constexpr bool same(char const *x, char const *y) {
00030 return !*x && !*y ? true
00031 : (*x == *y && same(x+1, y+1));
00032 }
00033
00034 template <class T>
00035 constexpr T keyToValue(char const *label, entry<T> const *entries) {
00036 return !entries->label ? entries->value
00037 : same(entries->label, label) ? entries->value
00038 : keyToValue(label, entries+1);
00039 }
00040
00041 template <class T>
00042 constexpr char const*valueToKey(T value, entry<T> const *entries) {
00043 return !entries->label ? entries->label
00044 : entries->value == value ? entries->label
00045 : valueToKey(value, entries+1);
00046 }
00047 constexpr entry<L1GtBoardType> l1GtBoardTypeStringToEnumMap[] = {
00048 {"GTFE", GTFE},
00049 {"FDL", FDL},
00050 {"PSB", PSB},
00051 {"GMT", GMT},
00052 {"TCS", TCS},
00053 {"TIM", TIM},
00054 {"BoardNull", BoardNull},
00055 {0, (L1GtBoardType)-1}
00056 };
00057
00058 constexpr entry<L1GtPsbQuad> l1GtPsbQuadStringToEnumMap[] = {
00059 {"Free", Free},
00060 {"TechTr", TechTr},
00061 {"IsoEGQ", IsoEGQ},
00062 {"NoIsoEGQ", NoIsoEGQ},
00063 {"CenJetQ", CenJetQ},
00064 {"ForJetQ", ForJetQ},
00065 {"TauJetQ", TauJetQ},
00066 {"ESumsQ", ESumsQ},
00067 {"JetCountsQ", JetCountsQ},
00068 {"MQB1", MQB1},
00069 {"MQB2", MQB2},
00070 {"MQF3", MQF3},
00071 {"MQF4", MQF4},
00072 {"MQB5", MQB5},
00073 {"MQB6", MQB6},
00074 {"MQF7", MQF7},
00075 {"MQF8", MQF8},
00076 {"MQB9", MQB9},
00077 {"MQB10", MQB10},
00078 {"MQF11", MQF11},
00079 {"MQF12", MQF12},
00080 {"CastorQ", CastorQ},
00081 {"HfQ", HfQ},
00082 {"BptxQ", BptxQ},
00083 {"GtExternalQ", GtExternalQ},
00084 {"PsbQuadNull", PsbQuadNull},
00085 {0, (L1GtPsbQuad) - 1}
00086 };
00087
00088
00089 constexpr entry<L1GtConditionType> l1GtConditionTypeStringToEnumMap[] = {
00090 {"TypeNull", TypeNull},
00091 {"Type1s", Type1s},
00092 {"Type2s", Type2s},
00093 {"Type2wsc", Type2wsc},
00094 {"Type2cor", Type2cor},
00095 {"Type3s", Type3s},
00096 {"Type4s", Type4s},
00097 {"TypeETM", TypeETM},
00098 {"TypeETT", TypeETT},
00099 {"TypeHTT", TypeHTT},
00100 {"TypeHTM", TypeHTM},
00101 {"TypeJetCounts", TypeJetCounts},
00102 {"TypeCastor", TypeCastor},
00103 {"TypeHfBitCounts", TypeHfBitCounts},
00104 {"TypeHfRingEtSums", TypeHfRingEtSums},
00105 {"TypeBptx", TypeBptx},
00106 {"TypeExternal", TypeExternal},
00107 {0, (L1GtConditionType) - 1}
00108 };
00109
00110
00111 constexpr entry<L1GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
00112 {"CondNull", CondNull},
00113 {"CondMuon", CondMuon},
00114 {"CondCalo", CondCalo},
00115 {"CondEnergySum", CondEnergySum},
00116 {"CondJetCounts", CondJetCounts},
00117 {"CondCorrelation", CondCorrelation},
00118 {"CondCastor", CondCastor},
00119 {"CondHfBitCounts", CondHfBitCounts},
00120 {"CondHfRingEtSums", CondHfRingEtSums},
00121 {"CondBptx", CondBptx},
00122 {"CondExternal", CondExternal},
00123 {0, (L1GtConditionCategory) - 1}
00124 };
00125
00126 }
00127
00128 L1GtBoardType l1GtBoardTypeStringToEnum(const std::string& label) {
00129 L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
00130 if (value == (L1GtBoardType) - 1) {
00131 edm::LogInfo("L1GtDefinitions") << "\n '" << label
00132 << "' is not a recognized L1GtBoardType. \n Return BoardNull.";
00133 value = BoardNull;
00134 }
00135
00136 if (value == BoardNull) {
00137 edm::LogInfo("L1GtDefinitions")
00138 << "\n BoardNull means no valid board type defined!";
00139 }
00140
00141 return value;
00142 }
00143
00144 std::string l1GtBoardTypeEnumToString(const L1GtBoardType& boardType) {
00145 char const *result= valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
00146 if (boardType == BoardNull) {
00147 edm::LogInfo("L1GtDefinitions")
00148 << "\n BoardNull means no valid board type defined!";
00149 }
00150 if (!result) {
00151 edm::LogInfo("L1GtDefinitions") << "\n '" << boardType
00152 << "' is not a recognized L1GtBoardType. "
00153 << "\n Return BoardNull, which means no valid board type defined!";
00154 return "BoardNull";
00155 }
00156 return result;
00157 }
00158
00159
00160
00161
00162 L1GtPsbQuad l1GtPsbQuadStringToEnum(const std::string& label) {
00163 L1GtPsbQuad value = keyToValue(label.c_str(), l1GtPsbQuadStringToEnumMap);
00164
00165
00166 if (value == -1) {
00167 edm::LogInfo("L1GtDefinitions") << "\n '" << label
00168 << "' is not a recognized L1GtPsbQuad. \n Return PsbQuadNull.";
00169 value = PsbQuadNull;
00170 }
00171
00172 if (value == PsbQuadNull) {
00173 edm::LogInfo("L1GtDefinitions")
00174 << "\n PsbQuadNull means no valid PSB quadruplet defined!";
00175 }
00176
00177 return value;
00178 }
00179
00180 std::string l1GtPsbQuadEnumToString(const L1GtPsbQuad& psbQuad) {
00181 char const*result = valueToKey(psbQuad, l1GtPsbQuadStringToEnumMap);
00182 if (psbQuad == PsbQuadNull)
00183 edm::LogInfo("L1GtDefinitions") << "\n PsbQuadNull means no valid PSB quadruplet defined!";
00184 if (!result) {
00185 result = "PsbQuadNull";
00186 edm::LogInfo("L1GtDefinitions") << "\n '" << psbQuad
00187 << "' is not a recognized L1GtPsbQuad. "
00188 << "\n Return PsbQuadNull, which means no valid PSB quadruplet defined!";
00189 }
00190
00191 return result;
00192 }
00193
00194
00195 L1GtConditionType l1GtConditionTypeStringToEnum(const std::string& label) {
00196 L1GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
00197
00198
00199
00200 if (value == (L1GtConditionType) -1) {
00201 edm::LogInfo("L1GtDefinitions") << "\n '" << label
00202 << "' is not a recognized L1GtConditionType. \n Return TypeNull.";
00203
00204 value = TypeNull;
00205 }
00206
00207 if (value == TypeNull) {
00208 edm::LogInfo("L1GtDefinitions")
00209 << "\n TypeNull means no valid condition type defined!";
00210 }
00211
00212 return value;
00213 }
00214
00215 std::string l1GtConditionTypeEnumToString(const L1GtConditionType& conditionType) {
00216 const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
00217 if (conditionType == TypeNull)
00218 edm::LogInfo("L1GtDefinitions")
00219 << "\n Return TypeNull, which means no valid condition type defined!";
00220 if (!result) {
00221 result = "TypeNull";
00222 edm::LogInfo("L1GtDefinitions") << "\n '" << conditionType
00223 << "' is not a recognized L1GtConditionType. "
00224 << "\n Return TypeNull, which means no valid condition type defined!";
00225 }
00226 return result;
00227 }
00228
00229 L1GtConditionCategory l1GtConditionCategoryStringToEnum(const std::string& label) {
00230 L1GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
00231
00232
00233 if (value == (L1GtConditionCategory) -1) {
00234 edm::LogInfo("L1GtDefinitions") << "\n '" << label
00235 << "' is not a recognized L1GtConditionCategory. \n Return CondNull.";
00236
00237 value = CondNull;
00238 }
00239
00240 if (value == CondNull) {
00241 edm::LogInfo("L1GtDefinitions")
00242 << "\n CondNull means no valid condition category defined!";
00243 }
00244
00245 return value;
00246 }
00247
00248 std::string l1GtConditionCategoryEnumToString(const L1GtConditionCategory& conditionCategory) {
00249 char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
00250 if (conditionCategory == CondNull)
00251 edm::LogInfo("L1GtDefinitions")
00252 << "\n Return CondNull, which means no valid condition category defined!";
00253
00254 if (!result) {
00255 result = "CondNull";
00256 edm::LogInfo("L1GtDefinitions") << "\n '" << conditionCategory
00257 << "' is not a recognized L1GtConditionCategory. "
00258 << "\n Return CondNull, which means no valid condition category defined!";
00259 }
00260
00261 return result;
00262 }