CMS 3D CMS Logo

GlobalDefinitions.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <cstring>
20 
21 // user include files
23 namespace {
24 template <class T>
25 struct entry {
26  char const* label;
27  T value;
28 };
29 
30 constexpr bool same(char const *x, char const *y) {
31  return !*x && !*y ? true
32  : /* 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},
50  {"l1t::BoardNull", l1t::BoardNull},
51  {nullptr, (l1t::L1GtBoardType)-1}
52 };
53 
54 
55 // l1t::GtConditionType
56 constexpr entry<l1t::GtConditionType> l1GtConditionTypeStringToEnumMap[] = {
57  {"l1t::TypeNull", l1t::TypeNull},
58  {"l1t::Type1s", l1t::Type1s},
59  {"l1t::Type2s", l1t::Type2s},
60  {"l1t::Type2wsc", l1t::Type2wsc},
61  {"l1t::Type2cor", l1t::Type2cor},
62  {"l1t::Type3s", l1t::Type3s},
63  {"l1t::Type4s", l1t::Type4s},
64  {"l1t::TypeETM", l1t::TypeETM},
65  {"l1t::TypeETT", l1t::TypeETT},
66  {"l1t::TypeHTT", l1t::TypeHTT},
67  {"l1t::TypeHTM", l1t::TypeHTM},
68  {"l1t::TypeETMHF", l1t::TypeETMHF},
69  {"l1t::TypeTowerCount", l1t::TypeTowerCount},
70  {"l1t::TypeMinBiasHFP0", l1t::TypeMinBiasHFP0},
71  {"l1t::TypeMinBiasHFM0", l1t::TypeMinBiasHFM0},
72  {"l1t::TypeMinBiasHFP1", l1t::TypeMinBiasHFP1},
73  {"l1t::TypeMinBiasHFM1", l1t::TypeMinBiasHFM1},
74  {"l1t::TypeExternal", l1t::TypeExternal},
75  {nullptr, (l1t::GtConditionType) - 1},
76  {"l1t::Type2corWithOverlapRemoval", l1t::Type2corWithOverlapRemoval},
77  {"l1t::TypeCent0", l1t::TypeCent0},
78  {"l1t::TypeCent1", l1t::TypeCent1},
79  {"l1t::TypeCent2", l1t::TypeCent2},
80  {"l1t::TypeCent3", l1t::TypeCent3},
81  {"l1t::TypeCent4", l1t::TypeCent4},
82  {"l1t::TypeCent5", l1t::TypeCent5},
83  {"l1t::TypeCent6", l1t::TypeCent6},
84  {"l1t::TypeCent7", l1t::TypeCent7},
85  {"l1t::TypeAsymEt", l1t::TypeAsymEt},
86  {"l1t::TypeAsymHt", l1t::TypeAsymHt},
87  {"l1t::TypeAsymEtHF", l1t::TypeAsymEtHF},
88  {"l1t::TypeAsymHtHF", l1t::TypeAsymHtHF}
89 };
90 
91 // l1t::GtConditionCategory
92 constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
93  {"l1t::CondNull", l1t::CondNull},
94  {"l1t::CondMuon", l1t::CondMuon},
95  {"l1t::CondCalo", l1t::CondCalo},
96  {"l1t::CondEnergySum", l1t::CondEnergySum},
97  {"l1t::CondCorrelation", l1t::CondCorrelation},
98  {"l1t::CondExternal", l1t::CondExternal},
99  {nullptr, (l1t::GtConditionCategory) - 1},
100  {"l1t::CondCorrelationWithOverlapRemoval", l1t::CondCorrelationWithOverlapRemoval}
101 };
102 
103 }
104 // l1t::L1GtBoardType
106  l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
107  if (value == (l1t::L1GtBoardType) - 1) {
108  edm::LogInfo("L1TGlobal") << "\n '" << label
109  << "' is not a recognized l1t::L1GtBoardType. \n Return l1t::BoardNull.";
110  value = l1t::BoardNull;
111  }
112 
113  if (value == l1t::BoardNull) {
114  edm::LogInfo("L1TGlobal")
115  << "\n l1t::BoardNull means no valid board type defined!";
116  }
117 
118  return value;
119 }
120 
122  char const *result= valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
123  if (boardType == l1t::BoardNull) {
124  edm::LogInfo("L1TGlobal")
125  << "\n l1t::BoardNull means no valid board type defined!";
126  }
127  if (!result) {
128  edm::LogInfo("L1TGlobal") << "\n '" << boardType
129  << "' is not a recognized l1t::L1GtBoardType. "
130  << "\n Return l1t::BoardNull, which means no valid board type defined!";
131  return "l1t::BoardNull";
132  }
133  return result;
134 }
135 
136 
137 
138 
139 
141  l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
142 
143  // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
144  // to be dealt by the corresponding module
145  if (value == (l1t::GtConditionType) -1) {
146  edm::LogInfo("L1TGlobal") << "\n '" << label
147  << "' is not a recognized l1t::GtConditionType. \n Return l1t::TypeNull.";
148 
149  value = l1t::TypeNull;
150  }
151 
152  if (value == l1t::TypeNull) {
153  edm::LogInfo("L1TGlobal")
154  << "\n l1t::TypeNull means no valid condition type defined!";
155  }
156 
157  return value;
158 }
159 
161  const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
162  if (conditionType == l1t::TypeNull)
163  edm::LogInfo("L1TGlobal")
164  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
165  if (!result) {
166  result = "l1t::TypeNull";
167  edm::LogInfo("L1TGlobal") << "\n '" << conditionType
168  << "' is not a recognized l1t::GtConditionType. "
169  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
170  }
171  return result;
172 }
173 
175  l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
176  // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
177  // to be dealt by the corresponding module
178  if (value == (l1t::GtConditionCategory) -1) {
179  edm::LogInfo("L1TGlobal") << "\n '" << label
180  << "' is not a recognized l1t::GtConditionCategory. \n Return l1t::CondNull.";
181 
182  value = l1t::CondNull;
183  }
184 
185  if (value == l1t::CondNull) {
186  edm::LogInfo("L1TGlobal")
187  << "\n l1t::CondNull means no valid condition category defined!";
188  }
189 
190  return value;
191 }
192 
194  char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
195  if (conditionCategory == l1t::CondNull)
196  edm::LogInfo("L1TGlobal")
197  << "\n Return l1t::CondNull, which means no valid condition category defined!";
198 
199  if (!result) {
200  result = "l1t::CondNull";
201  edm::LogInfo("L1TGlobal") << "\n '" << conditionCategory
202  << "' is not a recognized l1t::GtConditionCategory. "
203  << "\n Return l1t::CondNull, which means no valid condition category defined!";
204  }
205 
206  return result;
207 }
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 &)
std::string l1GtConditionCategoryEnumToString(const GtConditionCategory &)
L1GtBoardType l1GtBoardTypeStringToEnum(const std::string &)
GtConditionType l1GtConditionTypeStringToEnum(const std::string &)
long double T
#define constexpr