Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-11 04:40:26

0001 /**
0002  *
0003  *
0004  * Description: see header file.
0005  *
0006  *
0007  * \author: Vasile Mihai Ghete - HEPHY Vienna
0008  *          Vladimir Rekovic - extend for overlap removal
0009  *          Elisa Fontanesi - extended for three-body correlation conditions
0010  *
0011  * $Date$
0012  * $Revision$
0013  *
0014  */
0015 
0016 // this class header
0017 #include "L1Trigger/L1TGlobal/interface/GlobalDefinitions.h"
0018 
0019 // system include files
0020 #include <cstring>
0021 
0022 // user include files
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 namespace {
0025   template <class T>
0026   struct entry {
0027     char const *label;
0028     T value;
0029   };
0030 
0031   constexpr bool same(char const *x, char const *y) {
0032     return !*x && !*y ? true : /* default */ (*x == *y && same(x + 1, y + 1));
0033   }
0034 
0035   template <class T>
0036   constexpr T keyToValue(char const *label, entry<T> const *entries) {
0037     return !entries->label               ? entries->value
0038            : same(entries->label, label) ? entries->value
0039                                          : /*default*/ keyToValue(label, entries + 1);
0040   }
0041 
0042   template <class T>
0043   constexpr char const *valueToKey(T value, entry<T> const *entries) {
0044     return !entries->label           ? entries->label
0045            : entries->value == value ? entries->label
0046                                      : /*default*/ valueToKey(value, entries + 1);
0047   }
0048   constexpr entry<l1t::L1GtBoardType> l1GtBoardTypeStringToEnumMap[] = {
0049       {"l1t::MP7", l1t::MP7}, {"l1t::BoardNull", l1t::BoardNull}, {nullptr, (l1t::L1GtBoardType)-1}};
0050 
0051   // l1t::GtConditionType
0052   constexpr entry<l1t::GtConditionType> l1GtConditionTypeStringToEnumMap[] = {
0053       {"l1t::TypeNull", l1t::TypeNull},
0054       {"l1t::Type1s", l1t::Type1s},
0055       {"l1t::Type2s", l1t::Type2s},
0056       {"l1t::Type2wsc", l1t::Type2wsc},
0057       {"l1t::Type2cor", l1t::Type2cor},
0058       {"l1t::Type3s", l1t::Type3s},
0059       {"l1t::Type4s", l1t::Type4s},
0060       {"l1t::TypeETM", l1t::TypeETM},
0061       {"l1t::TypeETT", l1t::TypeETT},
0062       {"l1t::TypeHTT", l1t::TypeHTT},
0063       {"l1t::TypeHTM", l1t::TypeHTM},
0064       {"l1t::TypeETMHF", l1t::TypeETMHF},
0065       {"l1t::TypeTowerCount", l1t::TypeTowerCount},
0066       {"l1t::TypeMinBiasHFP0", l1t::TypeMinBiasHFP0},
0067       {"l1t::TypeMinBiasHFM0", l1t::TypeMinBiasHFM0},
0068       {"l1t::TypeMinBiasHFP1", l1t::TypeMinBiasHFP1},
0069       {"l1t::TypeMinBiasHFM1", l1t::TypeMinBiasHFM1},
0070       {"l1t::TypeExternal", l1t::TypeExternal},
0071       {nullptr, (l1t::GtConditionType)-1},
0072       {"l1t::Type2corWithOverlapRemoval", l1t::Type2corWithOverlapRemoval},
0073       {"l1t::TypeCent0", l1t::TypeCent0},
0074       {"l1t::TypeCent1", l1t::TypeCent1},
0075       {"l1t::TypeCent2", l1t::TypeCent2},
0076       {"l1t::TypeCent3", l1t::TypeCent3},
0077       {"l1t::TypeCent4", l1t::TypeCent4},
0078       {"l1t::TypeCent5", l1t::TypeCent5},
0079       {"l1t::TypeCent6", l1t::TypeCent6},
0080       {"l1t::TypeCent7", l1t::TypeCent7},
0081       {"l1t::TypeAsymEt", l1t::TypeAsymEt},
0082       {"l1t::TypeAsymHt", l1t::TypeAsymHt},
0083       {"l1t::TypeAsymEtHF", l1t::TypeAsymEtHF},
0084       {"l1t::TypeAsymHtHF", l1t::TypeAsymHtHF}};
0085 
0086   // l1t::GtConditionCategory
0087   constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
0088       {"l1t::CondNull", l1t::CondNull},
0089       {"l1t::CondMuon", l1t::CondMuon},
0090       {"l1t::CondCalo", l1t::CondCalo},
0091       {"l1t::CondEnergySum", l1t::CondEnergySum},
0092       {"l1t::CondCorrelation", l1t::CondCorrelation},
0093       {"l1t::CondCorrelationThreeBody", l1t::CondCorrelationThreeBody},
0094       {"l1t::CondCorrelationWithOverlapRemoval", l1t::CondCorrelationWithOverlapRemoval},
0095       {"l1t::CondExternal", l1t::CondExternal},
0096       {nullptr, (l1t::GtConditionCategory)-1}};
0097 
0098 }  // namespace
0099 // l1t::L1GtBoardType
0100 l1t::L1GtBoardType l1t::l1GtBoardTypeStringToEnum(const std::string &label) {
0101   l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
0102   if (value == (l1t::L1GtBoardType)-1) {
0103     edm::LogInfo("L1TGlobal") << "\n  '" << label
0104                               << "' is not a recognized l1t::L1GtBoardType. \n  Return l1t::BoardNull.";
0105     value = l1t::BoardNull;
0106   }
0107 
0108   if (value == l1t::BoardNull) {
0109     edm::LogInfo("L1TGlobal") << "\n  l1t::BoardNull means no valid board type defined!";
0110   }
0111 
0112   return value;
0113 }
0114 
0115 std::string l1t::l1GtBoardTypeEnumToString(const l1t::L1GtBoardType &boardType) {
0116   char const *result = valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
0117   if (boardType == l1t::BoardNull) {
0118     edm::LogInfo("L1TGlobal") << "\n  l1t::BoardNull means no valid board type defined!";
0119   }
0120   if (!result) {
0121     edm::LogInfo("L1TGlobal") << "\n  '" << boardType << "' is not a recognized l1t::L1GtBoardType. "
0122                               << "\n  Return l1t::BoardNull, which means no valid board type defined!";
0123     return "l1t::BoardNull";
0124   }
0125   return result;
0126 }
0127 
0128 l1t::GtConditionType l1t::l1GtConditionTypeStringToEnum(const std::string &label) {
0129   l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
0130 
0131   // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
0132   // to be dealt by the corresponding module
0133   if (value == (l1t::GtConditionType)-1) {
0134     edm::LogInfo("L1TGlobal") << "\n  '" << label
0135                               << "' is not a recognized l1t::GtConditionType. \n  Return l1t::TypeNull.";
0136 
0137     value = l1t::TypeNull;
0138   }
0139 
0140   if (value == l1t::TypeNull) {
0141     edm::LogInfo("L1TGlobal") << "\n  l1t::TypeNull means no valid condition type defined!";
0142   }
0143 
0144   return value;
0145 }
0146 
0147 std::string l1t::l1GtConditionTypeEnumToString(const l1t::GtConditionType &conditionType) {
0148   const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
0149   if (conditionType == l1t::TypeNull)
0150     edm::LogInfo("L1TGlobal") << "\n  Return l1t::TypeNull, which means no valid condition type defined!";
0151   if (!result) {
0152     result = "l1t::TypeNull";
0153     edm::LogInfo("L1TGlobal") << "\n  '" << conditionType << "' is not a recognized l1t::GtConditionType. "
0154                               << "\n  Return l1t::TypeNull, which means no valid condition type defined!";
0155   }
0156   return result;
0157 }
0158 
0159 l1t::GtConditionCategory l1t::l1GtConditionCategoryStringToEnum(const std::string &label) {
0160   l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
0161   // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
0162   // to be dealt by the corresponding module
0163   if (value == (l1t::GtConditionCategory)-1) {
0164     edm::LogInfo("L1TGlobal") << "\n  '" << label
0165                               << "' is not a recognized l1t::GtConditionCategory. \n  Return l1t::CondNull.";
0166 
0167     value = l1t::CondNull;
0168   }
0169 
0170   if (value == l1t::CondNull) {
0171     edm::LogInfo("L1TGlobal") << "\n  l1t::CondNull means no valid condition category defined!";
0172   }
0173 
0174   return value;
0175 }
0176 
0177 std::string l1t::l1GtConditionCategoryEnumToString(const l1t::GtConditionCategory &conditionCategory) {
0178   char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
0179   if (conditionCategory == l1t::CondNull)
0180     edm::LogInfo("L1TGlobal") << "\n  Return l1t::CondNull, which means no valid condition category defined!";
0181 
0182   if (!result) {
0183     result = "l1t::CondNull";
0184     edm::LogInfo("L1TGlobal") << "\n  '" << conditionCategory << "' is not a recognized l1t::GtConditionCategory. "
0185                               << "\n  Return l1t::CondNull, which means no valid condition category defined!";
0186   }
0187 
0188   return result;
0189 }