Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:09

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::TypeZDCP", l1t::TypeZDCP},
0071       {"l1t::TypeZDCM", l1t::TypeZDCM},
0072       {"l1t::TypeAXOL1TL", l1t::TypeAXOL1TL},
0073       {"l1t::TypeExternal", l1t::TypeExternal},
0074       {nullptr, (l1t::GtConditionType)-1},
0075       {"l1t::Type2corWithOverlapRemoval", l1t::Type2corWithOverlapRemoval},
0076       {"l1t::TypeCent0", l1t::TypeCent0},
0077       {"l1t::TypeCent1", l1t::TypeCent1},
0078       {"l1t::TypeCent2", l1t::TypeCent2},
0079       {"l1t::TypeCent3", l1t::TypeCent3},
0080       {"l1t::TypeCent4", l1t::TypeCent4},
0081       {"l1t::TypeCent5", l1t::TypeCent5},
0082       {"l1t::TypeCent6", l1t::TypeCent6},
0083       {"l1t::TypeCent7", l1t::TypeCent7},
0084       {"l1t::TypeAsymEt", l1t::TypeAsymEt},
0085       {"l1t::TypeAsymHt", l1t::TypeAsymHt},
0086       {"l1t::TypeAsymEtHF", l1t::TypeAsymEtHF},
0087       {"l1t::TypeAsymHtHF", l1t::TypeAsymHtHF}};
0088 
0089   // l1t::GtConditionCategory
0090   constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
0091       {"l1t::CondNull", l1t::CondNull},
0092       {"l1t::CondMuon", l1t::CondMuon},
0093       {"l1t::CondCalo", l1t::CondCalo},
0094       {"l1t::CondEnergySum", l1t::CondEnergySum},
0095       {"l1t::CondEnergySumZdc", l1t::CondEnergySumZdc},
0096       {"l1t::CondAXOL1TL", l1t::CondAXOL1TL},
0097       {"l1t::CondCorrelation", l1t::CondCorrelation},
0098       {"l1t::CondCorrelationThreeBody", l1t::CondCorrelationThreeBody},
0099       {"l1t::CondCorrelationWithOverlapRemoval", l1t::CondCorrelationWithOverlapRemoval},
0100       {"l1t::CondExternal", l1t::CondExternal},
0101       {nullptr, (l1t::GtConditionCategory)-1}};
0102 
0103 }  // namespace
0104 // l1t::L1GtBoardType
0105 l1t::L1GtBoardType l1t::l1GtBoardTypeStringToEnum(const std::string &label) {
0106   l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
0107   if (value == (l1t::L1GtBoardType)-1) {
0108     edm::LogInfo("L1TGlobal") << "\n  '" << label
0109                               << "' is not a recognized l1t::L1GtBoardType. \n  Return l1t::BoardNull.";
0110     value = l1t::BoardNull;
0111   }
0112 
0113   if (value == l1t::BoardNull) {
0114     edm::LogInfo("L1TGlobal") << "\n  l1t::BoardNull means no valid board type defined!";
0115   }
0116 
0117   return value;
0118 }
0119 
0120 std::string l1t::l1GtBoardTypeEnumToString(const l1t::L1GtBoardType &boardType) {
0121   char const *result = valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
0122   if (boardType == l1t::BoardNull) {
0123     edm::LogInfo("L1TGlobal") << "\n  l1t::BoardNull means no valid board type defined!";
0124   }
0125   if (!result) {
0126     edm::LogInfo("L1TGlobal") << "\n  '" << boardType << "' is not a recognized l1t::L1GtBoardType. "
0127                               << "\n  Return l1t::BoardNull, which means no valid board type defined!";
0128     return "l1t::BoardNull";
0129   }
0130   return result;
0131 }
0132 
0133 l1t::GtConditionType l1t::l1GtConditionTypeStringToEnum(const std::string &label) {
0134   l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
0135 
0136   // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
0137   // to be dealt by the corresponding module
0138   if (value == (l1t::GtConditionType)-1) {
0139     edm::LogInfo("L1TGlobal") << "\n  '" << label
0140                               << "' is not a recognized l1t::GtConditionType. \n  Return l1t::TypeNull.";
0141 
0142     value = l1t::TypeNull;
0143   }
0144 
0145   if (value == l1t::TypeNull) {
0146     edm::LogInfo("L1TGlobal") << "\n  l1t::TypeNull means no valid condition type defined!";
0147   }
0148 
0149   return value;
0150 }
0151 
0152 std::string l1t::l1GtConditionTypeEnumToString(const l1t::GtConditionType &conditionType) {
0153   const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
0154   if (conditionType == l1t::TypeNull)
0155     edm::LogInfo("L1TGlobal") << "\n  Return l1t::TypeNull, which means no valid condition type defined!";
0156   if (!result) {
0157     result = "l1t::TypeNull";
0158     edm::LogInfo("L1TGlobal") << "\n  '" << conditionType << "' is not a recognized l1t::GtConditionType. "
0159                               << "\n  Return l1t::TypeNull, which means no valid condition type defined!";
0160   }
0161   return result;
0162 }
0163 
0164 l1t::GtConditionCategory l1t::l1GtConditionCategoryStringToEnum(const std::string &label) {
0165   l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
0166   // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
0167   // to be dealt by the corresponding module
0168   if (value == (l1t::GtConditionCategory)-1) {
0169     edm::LogInfo("L1TGlobal") << "\n  '" << label
0170                               << "' is not a recognized l1t::GtConditionCategory. \n  Return l1t::CondNull.";
0171 
0172     value = l1t::CondNull;
0173   }
0174 
0175   if (value == l1t::CondNull) {
0176     edm::LogInfo("L1TGlobal") << "\n  l1t::CondNull means no valid condition category defined!";
0177   }
0178 
0179   return value;
0180 }
0181 
0182 std::string l1t::l1GtConditionCategoryEnumToString(const l1t::GtConditionCategory &conditionCategory) {
0183   char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
0184   if (conditionCategory == l1t::CondNull)
0185     edm::LogInfo("L1TGlobal") << "\n  Return l1t::CondNull, which means no valid condition category defined!";
0186 
0187   if (!result) {
0188     result = "l1t::CondNull";
0189     edm::LogInfo("L1TGlobal") << "\n  '" << conditionCategory << "' is not a recognized l1t::GtConditionCategory. "
0190                               << "\n  Return l1t::CondNull, which means no valid condition category defined!";
0191   }
0192 
0193   return result;
0194 }