CMS 3D CMS Logo

GlobalDefinitions.cc
Go to the documentation of this file.
1 
16 // this class header
18 
19 // system include files
20 #include <cstring>
21 
22 // user include files
24 namespace {
25  template <class T>
26  struct entry {
27  char const *label;
28  T value;
29  };
30 
31  constexpr bool same(char const *x, char const *y) {
32  return !*x && !*y ? true : /* default */ (*x == *y && same(x + 1, y + 1));
33  }
34 
35  template <class T>
36  constexpr T keyToValue(char const *label, entry<T> const *entries) {
37  return !entries->label ? entries->value
38  : same(entries->label, label) ? entries->value
39  : /*default*/ keyToValue(label, entries + 1);
40  }
41 
42  template <class T>
43  constexpr char const *valueToKey(T value, entry<T> const *entries) {
44  return !entries->label ? entries->label
45  : entries->value == value ? entries->label
46  : /*default*/ valueToKey(value, entries + 1);
47  }
48  constexpr entry<l1t::L1GtBoardType> l1GtBoardTypeStringToEnumMap[] = {
49  {"l1t::MP7", l1t::MP7}, {"l1t::BoardNull", l1t::BoardNull}, {nullptr, (l1t::L1GtBoardType)-1}};
50 
51  // l1t::GtConditionType
52  constexpr entry<l1t::GtConditionType> l1GtConditionTypeStringToEnumMap[] = {
53  {"l1t::TypeNull", l1t::TypeNull},
54  {"l1t::Type1s", l1t::Type1s},
55  {"l1t::Type2s", l1t::Type2s},
56  {"l1t::Type2wsc", l1t::Type2wsc},
57  {"l1t::Type2cor", l1t::Type2cor},
58  {"l1t::Type3s", l1t::Type3s},
59  {"l1t::Type4s", l1t::Type4s},
60  {"l1t::TypeETM", l1t::TypeETM},
61  {"l1t::TypeETT", l1t::TypeETT},
62  {"l1t::TypeHTT", l1t::TypeHTT},
63  {"l1t::TypeHTM", l1t::TypeHTM},
64  {"l1t::TypeETMHF", l1t::TypeETMHF},
65  {"l1t::TypeTowerCount", l1t::TypeTowerCount},
66  {"l1t::TypeMinBiasHFP0", l1t::TypeMinBiasHFP0},
67  {"l1t::TypeMinBiasHFM0", l1t::TypeMinBiasHFM0},
68  {"l1t::TypeMinBiasHFP1", l1t::TypeMinBiasHFP1},
69  {"l1t::TypeMinBiasHFM1", l1t::TypeMinBiasHFM1},
70  {"l1t::TypeExternal", l1t::TypeExternal},
71  {nullptr, (l1t::GtConditionType)-1},
72  {"l1t::Type2corWithOverlapRemoval", l1t::Type2corWithOverlapRemoval},
73  {"l1t::TypeCent0", l1t::TypeCent0},
74  {"l1t::TypeCent1", l1t::TypeCent1},
75  {"l1t::TypeCent2", l1t::TypeCent2},
76  {"l1t::TypeCent3", l1t::TypeCent3},
77  {"l1t::TypeCent4", l1t::TypeCent4},
78  {"l1t::TypeCent5", l1t::TypeCent5},
79  {"l1t::TypeCent6", l1t::TypeCent6},
80  {"l1t::TypeCent7", l1t::TypeCent7},
81  {"l1t::TypeAsymEt", l1t::TypeAsymEt},
82  {"l1t::TypeAsymHt", l1t::TypeAsymHt},
83  {"l1t::TypeAsymEtHF", l1t::TypeAsymEtHF},
84  {"l1t::TypeAsymHtHF", l1t::TypeAsymHtHF}};
85 
86  // l1t::GtConditionCategory
87  constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
88  {"l1t::CondNull", l1t::CondNull},
89  {"l1t::CondMuon", l1t::CondMuon},
90  {"l1t::CondCalo", l1t::CondCalo},
91  {"l1t::CondEnergySum", l1t::CondEnergySum},
92  {"l1t::CondCorrelation", l1t::CondCorrelation},
93  {"l1t::CondCorrelationThreeBody", l1t::CondCorrelationThreeBody},
94  {"l1t::CondCorrelationWithOverlapRemoval", l1t::CondCorrelationWithOverlapRemoval},
95  {"l1t::CondExternal", l1t::CondExternal},
96  {nullptr, (l1t::GtConditionCategory)-1}};
97 
98 } // namespace
99 // l1t::L1GtBoardType
101  l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
102  if (value == (l1t::L1GtBoardType)-1) {
103  edm::LogInfo("L1TGlobal") << "\n '" << label
104  << "' is not a recognized l1t::L1GtBoardType. \n Return l1t::BoardNull.";
106  }
107 
108  if (value == l1t::BoardNull) {
109  edm::LogInfo("L1TGlobal") << "\n l1t::BoardNull means no valid board type defined!";
110  }
111 
112  return value;
113 }
114 
116  char const *result = valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
117  if (boardType == l1t::BoardNull) {
118  edm::LogInfo("L1TGlobal") << "\n l1t::BoardNull means no valid board type defined!";
119  }
120  if (!result) {
121  edm::LogInfo("L1TGlobal") << "\n '" << boardType << "' is not a recognized l1t::L1GtBoardType. "
122  << "\n Return l1t::BoardNull, which means no valid board type defined!";
123  return "l1t::BoardNull";
124  }
125  return result;
126 }
127 
129  l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
130 
131  // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
132  // to be dealt by the corresponding module
133  if (value == (l1t::GtConditionType)-1) {
134  edm::LogInfo("L1TGlobal") << "\n '" << label
135  << "' is not a recognized l1t::GtConditionType. \n Return l1t::TypeNull.";
136 
138  }
139 
140  if (value == l1t::TypeNull) {
141  edm::LogInfo("L1TGlobal") << "\n l1t::TypeNull means no valid condition type defined!";
142  }
143 
144  return value;
145 }
146 
148  const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
149  if (conditionType == l1t::TypeNull)
150  edm::LogInfo("L1TGlobal") << "\n Return l1t::TypeNull, which means no valid condition type defined!";
151  if (!result) {
152  result = "l1t::TypeNull";
153  edm::LogInfo("L1TGlobal") << "\n '" << conditionType << "' is not a recognized l1t::GtConditionType. "
154  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
155  }
156  return result;
157 }
158 
160  l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
161  // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
162  // to be dealt by the corresponding module
163  if (value == (l1t::GtConditionCategory)-1) {
164  edm::LogInfo("L1TGlobal") << "\n '" << label
165  << "' is not a recognized l1t::GtConditionCategory. \n Return l1t::CondNull.";
166 
168  }
169 
170  if (value == l1t::CondNull) {
171  edm::LogInfo("L1TGlobal") << "\n l1t::CondNull means no valid condition category defined!";
172  }
173 
174  return value;
175 }
176 
178  char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
179  if (conditionCategory == l1t::CondNull)
180  edm::LogInfo("L1TGlobal") << "\n Return l1t::CondNull, which means no valid condition category defined!";
181 
182  if (!result) {
183  result = "l1t::CondNull";
184  edm::LogInfo("L1TGlobal") << "\n '" << conditionCategory << "' is not a recognized l1t::GtConditionCategory. "
185  << "\n Return l1t::CondNull, which means no valid condition category defined!";
186  }
187 
188  return result;
189 }
L1GtBoardType
board types in GT
std::string l1GtConditionTypeEnumToString(const GtConditionType &)
Definition: Block.h:11
std::string l1GtBoardTypeEnumToString(const L1GtBoardType &)
GtConditionCategory
condition categories
char const * label
Definition: value.py:1
GtConditionCategory l1GtConditionCategoryStringToEnum(const std::string &)
Log< level::Info, false > LogInfo
std::string l1GtConditionCategoryEnumToString(const GtConditionCategory &)
L1GtBoardType l1GtBoardTypeStringToEnum(const std::string &)
GtConditionType l1GtConditionTypeStringToEnum(const std::string &)
float x
long double T