Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-16 03:19:40

0001 /**
0002  *
0003  *
0004  * Description: see header file.
0005  *
0006  *
0007  * \author: Vasile Mihai Ghete - HEPHY Vienna
0008  *
0009  * $Date$
0010  * $Revision$
0011  *
0012  */
0013 
0014 // this class header
0015 #include "CondFormats/L1TObjects/interface/L1GtDefinitions.h"
0016 
0017 // system include files
0018 #include <cstring>
0019 
0020 // user include files
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 namespace {
0023   template <class T>
0024   struct entry {
0025     char const* label;
0026     T value;
0027   };
0028 
0029   constexpr bool same(char const* x, char const* y) {
0030     return !*x && !*y ? true : /* default */ (*x == *y && same(x + 1, y + 1));
0031   }
0032 
0033   template <class T>
0034   constexpr T keyToValue(char const* label, entry<T> const* entries) {
0035     return !entries->label               ? entries->value
0036            : same(entries->label, label) ? entries->value
0037                                          : /*default*/ keyToValue(label, entries + 1);
0038   }
0039 
0040   template <class T>
0041   constexpr char const* valueToKey(T value, entry<T> const* entries) {
0042     return !entries->label           ? entries->label
0043            : entries->value == value ? entries->label
0044                                      : /*default*/ valueToKey(value, entries + 1);
0045   }
0046   constexpr entry<L1GtBoardType> l1GtBoardTypeStringToEnumMap[] = {{"GTFE", GTFE},
0047                                                                    {"FDL", FDL},
0048                                                                    {"PSB", PSB},
0049                                                                    {"GMT", GMT},
0050                                                                    {"TCS", TCS},
0051                                                                    {"TIM", TIM},
0052                                                                    {"BoardNull", BoardNull},
0053                                                                    {nullptr, (L1GtBoardType)-1}};
0054 
0055   constexpr entry<L1GtPsbQuad> l1GtPsbQuadStringToEnumMap[] = {{"Free", Free},
0056                                                                {"TechTr", TechTr},
0057                                                                {"IsoEGQ", IsoEGQ},
0058                                                                {"NoIsoEGQ", NoIsoEGQ},
0059                                                                {"CenJetQ", CenJetQ},
0060                                                                {"ForJetQ", ForJetQ},
0061                                                                {"TauJetQ", TauJetQ},
0062                                                                {"ESumsQ", ESumsQ},
0063                                                                {"JetCountsQ", JetCountsQ},
0064                                                                {"MQB1", MQB1},
0065                                                                {"MQB2", MQB2},
0066                                                                {"MQF3", MQF3},
0067                                                                {"MQF4", MQF4},
0068                                                                {"MQB5", MQB5},
0069                                                                {"MQB6", MQB6},
0070                                                                {"MQF7", MQF7},
0071                                                                {"MQF8", MQF8},
0072                                                                {"MQB9", MQB9},
0073                                                                {"MQB10", MQB10},
0074                                                                {"MQF11", MQF11},
0075                                                                {"MQF12", MQF12},
0076                                                                {"CastorQ", CastorQ},
0077                                                                {"HfQ", HfQ},
0078                                                                {"BptxQ", BptxQ},
0079                                                                {"GtExternalQ", GtExternalQ},
0080                                                                {"PsbQuadNull", PsbQuadNull},
0081                                                                {nullptr, (L1GtPsbQuad)-1}};
0082 
0083   // L1GtConditionType
0084   constexpr entry<L1GtConditionType> l1GtConditionTypeStringToEnumMap[] = {{"TypeNull", TypeNull},
0085                                                                            {"Type1s", Type1s},
0086                                                                            {"Type2s", Type2s},
0087                                                                            {"Type2wsc", Type2wsc},
0088                                                                            {"Type2cor", Type2cor},
0089                                                                            {"Type3s", Type3s},
0090                                                                            {"Type4s", Type4s},
0091                                                                            {"TypeETM", TypeETM},
0092                                                                            {"TypeETT", TypeETT},
0093                                                                            {"TypeHTT", TypeHTT},
0094                                                                            {"TypeHTM", TypeHTM},
0095                                                                            {"TypeJetCounts", TypeJetCounts},
0096                                                                            {"TypeCastor", TypeCastor},
0097                                                                            {"TypeHfBitCounts", TypeHfBitCounts},
0098                                                                            {"TypeHfRingEtSums", TypeHfRingEtSums},
0099                                                                            {"TypeBptx", TypeBptx},
0100                                                                            {"TypeExternal", TypeExternal},
0101                                                                            {nullptr, (L1GtConditionType)-1}};
0102 
0103   // L1GtConditionCategory
0104   constexpr entry<L1GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
0105       {"CondNull", CondNull},
0106       {"CondMuon", CondMuon},
0107       {"CondCalo", CondCalo},
0108       {"CondEnergySum", CondEnergySum},
0109       {"CondJetCounts", CondJetCounts},
0110       {"CondCorrelation", CondCorrelation},
0111       {"CondCastor", CondCastor},
0112       {"CondHfBitCounts", CondHfBitCounts},
0113       {"CondHfRingEtSums", CondHfRingEtSums},
0114       {"CondBptx", CondBptx},
0115       {"CondExternal", CondExternal},
0116       {nullptr, (L1GtConditionCategory)-1}};
0117 
0118 }  // namespace
0119 // L1GtBoardType
0120 L1GtBoardType l1GtBoardTypeStringToEnum(const std::string& label) {
0121   L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
0122   if (value == (L1GtBoardType)-1) {
0123     edm::LogInfo("L1GtDefinitions") << "\n  '" << label << "' is not a recognized L1GtBoardType. \n  Return BoardNull.";
0124     value = BoardNull;
0125   }
0126 
0127   if (value == BoardNull) {
0128     edm::LogInfo("L1GtDefinitions") << "\n  BoardNull means no valid board type defined!";
0129   }
0130 
0131   return value;
0132 }
0133 
0134 std::string l1GtBoardTypeEnumToString(const L1GtBoardType& boardType) {
0135   char const* result = valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
0136   if (boardType == BoardNull) {
0137     edm::LogInfo("L1GtDefinitions") << "\n  BoardNull means no valid board type defined!";
0138   }
0139   if (!result) {
0140     edm::LogInfo("L1GtDefinitions") << "\n  '" << boardType << "' is not a recognized L1GtBoardType. "
0141                                     << "\n  Return BoardNull, which means no valid board type defined!";
0142     return "BoardNull";
0143   }
0144   return result;
0145 }
0146 
0147 // L1GtPsbQuad
0148 
0149 L1GtPsbQuad l1GtPsbQuadStringToEnum(const std::string& label) {
0150   L1GtPsbQuad value = keyToValue(label.c_str(), l1GtPsbQuadStringToEnumMap);
0151   // in case of unrecognized L1GtPsbQuad, return PsbQuadNull
0152   // to be dealt by the corresponding module
0153   if (value == (L1GtPsbQuad)-1) {
0154     edm::LogInfo("L1GtDefinitions") << "\n  '" << label << "' is not a recognized L1GtPsbQuad. \n  Return PsbQuadNull.";
0155     value = PsbQuadNull;
0156   }
0157 
0158   if (value == PsbQuadNull) {
0159     edm::LogInfo("L1GtDefinitions") << "\n  PsbQuadNull means no valid PSB quadruplet defined!";
0160   }
0161 
0162   return value;
0163 }
0164 
0165 std::string l1GtPsbQuadEnumToString(const L1GtPsbQuad& psbQuad) {
0166   char const* result = valueToKey(psbQuad, l1GtPsbQuadStringToEnumMap);
0167   if (psbQuad == PsbQuadNull)
0168     edm::LogInfo("L1GtDefinitions") << "\n  PsbQuadNull means no valid PSB quadruplet defined!";
0169   if (!result) {
0170     result = "PsbQuadNull";
0171     edm::LogInfo("L1GtDefinitions") << "\n  '" << psbQuad << "' is not a recognized L1GtPsbQuad. "
0172                                     << "\n  Return PsbQuadNull, which means no valid PSB quadruplet defined!";
0173   }
0174 
0175   return result;
0176 }
0177 
0178 L1GtConditionType l1GtConditionTypeStringToEnum(const std::string& label) {
0179   L1GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
0180 
0181   // in case of unrecognized L1GtConditionType, return TypeNull
0182   // to be dealt by the corresponding module
0183   if (value == (L1GtConditionType)-1) {
0184     edm::LogInfo("L1GtDefinitions") << "\n  '" << label
0185                                     << "' is not a recognized L1GtConditionType. \n  Return TypeNull.";
0186 
0187     value = TypeNull;
0188   }
0189 
0190   if (value == TypeNull) {
0191     edm::LogInfo("L1GtDefinitions") << "\n  TypeNull means no valid condition type defined!";
0192   }
0193 
0194   return value;
0195 }
0196 
0197 std::string l1GtConditionTypeEnumToString(const L1GtConditionType& conditionType) {
0198   const char* result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
0199   if (conditionType == TypeNull)
0200     edm::LogInfo("L1GtDefinitions") << "\n  Return TypeNull, which means no valid condition type defined!";
0201   if (!result) {
0202     result = "TypeNull";
0203     edm::LogInfo("L1GtDefinitions") << "\n  '" << conditionType << "' is not a recognized L1GtConditionType. "
0204                                     << "\n  Return TypeNull, which means no valid condition type defined!";
0205   }
0206   return result;
0207 }
0208 
0209 L1GtConditionCategory l1GtConditionCategoryStringToEnum(const std::string& label) {
0210   L1GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
0211   // in case of unrecognized L1GtConditionCategory, return CondNull
0212   // to be dealt by the corresponding module
0213   if (value == (L1GtConditionCategory)-1) {
0214     edm::LogInfo("L1GtDefinitions") << "\n  '" << label
0215                                     << "' is not a recognized L1GtConditionCategory. \n  Return CondNull.";
0216 
0217     value = CondNull;
0218   }
0219 
0220   if (value == CondNull) {
0221     edm::LogInfo("L1GtDefinitions") << "\n  CondNull means no valid condition category defined!";
0222   }
0223 
0224   return value;
0225 }
0226 
0227 std::string l1GtConditionCategoryEnumToString(const L1GtConditionCategory& conditionCategory) {
0228   char const* result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
0229   if (conditionCategory == CondNull)
0230     edm::LogInfo("L1GtDefinitions") << "\n  Return CondNull, which means no valid condition category defined!";
0231 
0232   if (!result) {
0233     result = "CondNull";
0234     edm::LogInfo("L1GtDefinitions") << "\n  '" << conditionCategory << "' is not a recognized L1GtConditionCategory. "
0235                                     << "\n  Return CondNull, which means no valid condition category defined!";
0236   }
0237 
0238   return result;
0239 }