CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GtDefinitions.cc
Go to the documentation of this file.
1 
14 // this class header
16 
17 // system include files
18 #include <cstring>
19 
20 // user include files
22 namespace {
23 template <class T>
24 struct entry {
25  char const* label;
26  T value;
27 };
28 
29 constexpr bool same(char const *x, char const *y) {
30  return !*x && !*y ? true
31  : /* default */ (*x == *y && same(x+1, y+1));
32 }
33 
34 template <class T>
35 constexpr T keyToValue(char const *label, entry<T> const *entries) {
36  return !entries->label ? entries->value
37  : same(entries->label, label) ? entries->value
38  : /*default*/ keyToValue(label, entries+1);
39 }
40 
41 template <class T>
42 constexpr char const*valueToKey(T value, entry<T> const *entries) {
43  return !entries->label ? entries->label
44  : entries->value == value ? entries->label
45  : /*default*/ valueToKey(value, entries+1);
46 }
47 constexpr entry<l1t::L1GtBoardType> l1GtBoardTypeStringToEnumMap[] = {
48  {"l1t::GTFE", l1t::GTFE},
49  {"l1t::FDL", l1t::FDL},
50  {"l1t::PSB", l1t::PSB},
51  {"l1t::GMT", l1t::GMT},
52  {"l1t::TCS", l1t::TCS},
53  {"l1t::TIM", l1t::TIM},
54  {"l1t::BoardNull", l1t::BoardNull},
55  {0, (l1t::L1GtBoardType)-1}
56 };
57 
58 constexpr entry<l1t::L1GtPsbQuad> l1GtPsbQuadStringToEnumMap[] = {
59  {"l1t::Free", l1t::Free},
60  {"l1t::TechTr", l1t::TechTr},
61  {"l1t::IsoEGQ", l1t::IsoEGQ},
62  {"l1t::NoIsoEGQ", l1t::NoIsoEGQ},
63  {"l1t::CenJetQ", l1t::CenJetQ},
64  {"l1t::ForJetQ", l1t::ForJetQ},
65  {"l1t::TauJetQ", l1t::TauJetQ},
66  {"l1t::ESumsQ", l1t::ESumsQ},
67  {"l1t::JetCountsQ", l1t::JetCountsQ},
68  {"l1t::MQB1", l1t::MQB1},
69  {"l1t::MQB2", l1t::MQB2},
70  {"l1t::MQF3", l1t::MQF3},
71  {"l1t::MQF4", l1t::MQF4},
72  {"l1t::MQB5", l1t::MQB5},
73  {"l1t::MQB6", l1t::MQB6},
74  {"l1t::MQF7", l1t::MQF7},
75  {"l1t::MQF8", l1t::MQF8},
76  {"l1t::MQB9", l1t::MQB9},
77  {"l1t::MQB10", l1t::MQB10},
78  {"l1t::MQF11", l1t::MQF11},
79  {"l1t::MQF12", l1t::MQF12},
80  {"l1t::CastorQ", l1t::CastorQ},
81  {"l1t::HfQ", l1t::HfQ},
82  {"l1t::BptxQ", l1t::BptxQ},
83  {"l1t::GtExternalQ", l1t::GtExternalQ},
84  {"l1t::PsbQuadNull", l1t::PsbQuadNull},
85  {0, (l1t::L1GtPsbQuad) - 1}
86 };
87 
88 // l1t::GtConditionType
89 constexpr entry<l1t::GtConditionType> l1GtConditionTypeStringToEnumMap[] = {
90  {"l1t::TypeNull", l1t::TypeNull},
91  {"l1t::Type1s", l1t::Type1s},
92  {"l1t::Type2s", l1t::Type2s},
93  {"l1t::Type2wsc", l1t::Type2wsc},
94  {"l1t::Type2cor", l1t::Type2cor},
95  {"l1t::Type3s", l1t::Type3s},
96  {"l1t::Type4s", l1t::Type4s},
97  {"l1t::TypeETM", l1t::TypeETM},
98  {"l1t::TypeETT", l1t::TypeETT},
99  {"l1t::TypeHTT", l1t::TypeHTT},
100  {"l1t::TypeHTM", l1t::TypeHTM},
101  {"l1t::TypeJetCounts", l1t::TypeJetCounts},
102  {"l1t::TypeCastor", l1t::TypeCastor},
103  {"l1t::TypeHfBitCounts", l1t::TypeHfBitCounts},
104  {"l1t::TypeHfRingEtSums", l1t::TypeHfRingEtSums},
105  {"l1t::TypeBptx", l1t::TypeBptx},
106  {"l1t::TypeExternal", l1t::TypeExternal},
107  {0, (l1t::GtConditionType) - 1}
108 };
109 
110 // l1t::GtConditionCategory
111 constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
112  {"l1t::CondNull", l1t::CondNull},
113  {"l1t::CondMuon", l1t::CondMuon},
114  {"l1t::CondCalo", l1t::CondCalo},
115  {"l1t::CondEnergySum", l1t::CondEnergySum},
116  {"l1t::CondJetCounts", l1t::CondJetCounts},
117  {"l1t::CondCorrelation", l1t::CondCorrelation},
118  {"l1t::CondCastor", l1t::CondCastor},
119  {"l1t::CondHfBitCounts", l1t::CondHfBitCounts},
120  {"l1t::CondHfRingEtSums", l1t::CondHfRingEtSums},
121  {"l1t::CondBptx", l1t::CondBptx},
122  {"l1t::CondExternal", l1t::CondExternal},
123  {0, (l1t::GtConditionCategory) - 1}
124 };
125 
126 }
127 // l1t::L1GtBoardType
129  l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
130  if (value == (l1t::L1GtBoardType) - 1) {
131  edm::LogInfo("GtDefinitions") << "\n '" << label
132  << "' is not a recognized l1t::L1GtBoardType. \n Return l1t::BoardNull.";
133  value = l1t::BoardNull;
134  }
135 
136  if (value == l1t::BoardNull) {
137  edm::LogInfo("GtDefinitions")
138  << "\n l1t::BoardNull means no valid board type defined!";
139  }
140 
141  return value;
142 }
143 
145  char const *result= valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
146  if (boardType == l1t::BoardNull) {
147  edm::LogInfo("GtDefinitions")
148  << "\n l1t::BoardNull means no valid board type defined!";
149  }
150  if (!result) {
151  edm::LogInfo("GtDefinitions") << "\n '" << boardType
152  << "' is not a recognized l1t::L1GtBoardType. "
153  << "\n Return l1t::BoardNull, which means no valid board type defined!";
154  return "l1t::BoardNull";
155  }
156  return result;
157 }
158 
159 
160 // l1t::L1GtPsbQuad
161 
163  l1t::L1GtPsbQuad value = keyToValue(label.c_str(), l1GtPsbQuadStringToEnumMap);
164  // in case of unrecognized l1t::L1GtPsbQuad, return l1t::PsbQuadNull
165  // to be dealt by the corresponding module
166  if (value == -1) {
167  edm::LogInfo("GtDefinitions") << "\n '" << label
168  << "' is not a recognized l1t::L1GtPsbQuad. \n Return l1t::PsbQuadNull.";
169  value = l1t::PsbQuadNull;
170  }
171 
172  if (value == l1t::PsbQuadNull) {
173  edm::LogInfo("GtDefinitions")
174  << "\n l1t::PsbQuadNull means no valid PSB quadruplet defined!";
175  }
176 
177  return value;
178 }
179 
181  char const*result = valueToKey(psbQuad, l1GtPsbQuadStringToEnumMap);
182  if (psbQuad == l1t::PsbQuadNull)
183  edm::LogInfo("GtDefinitions") << "\n l1t::PsbQuadNull means no valid PSB quadruplet defined!";
184  if (!result) {
185  result = "l1t::PsbQuadNull";
186  edm::LogInfo("GtDefinitions") << "\n '" << psbQuad
187  << "' is not a recognized l1t::L1GtPsbQuad. "
188  << "\n Return l1t::PsbQuadNull, which means no valid PSB quadruplet defined!";
189  }
190 
191  return result;
192 }
193 
194 
196  l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
197 
198  // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
199  // to be dealt by the corresponding module
200  if (value == (l1t::GtConditionType) -1) {
201  edm::LogInfo("GtDefinitions") << "\n '" << label
202  << "' is not a recognized l1t::GtConditionType. \n Return l1t::TypeNull.";
203 
204  value = l1t::TypeNull;
205  }
206 
207  if (value == l1t::TypeNull) {
208  edm::LogInfo("GtDefinitions")
209  << "\n l1t::TypeNull means no valid condition type defined!";
210  }
211 
212  return value;
213 }
214 
216  const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
217  if (conditionType == l1t::TypeNull)
218  edm::LogInfo("GtDefinitions")
219  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
220  if (!result) {
221  result = "l1t::TypeNull";
222  edm::LogInfo("GtDefinitions") << "\n '" << conditionType
223  << "' is not a recognized l1t::GtConditionType. "
224  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
225  }
226  return result;
227 }
228 
230  l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
231  // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
232  // to be dealt by the corresponding module
233  if (value == (l1t::GtConditionCategory) -1) {
234  edm::LogInfo("GtDefinitions") << "\n '" << label
235  << "' is not a recognized l1t::GtConditionCategory. \n Return l1t::CondNull.";
236 
237  value = l1t::CondNull;
238  }
239 
240  if (value == l1t::CondNull) {
241  edm::LogInfo("GtDefinitions")
242  << "\n l1t::CondNull means no valid condition category defined!";
243  }
244 
245  return value;
246 }
247 
249  char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
250  if (conditionCategory == l1t::CondNull)
251  edm::LogInfo("GtDefinitions")
252  << "\n Return l1t::CondNull, which means no valid condition category defined!";
253 
254  if (!result) {
255  result = "l1t::CondNull";
256  edm::LogInfo("GtDefinitions") << "\n '" << conditionCategory
257  << "' is not a recognized l1t::GtConditionCategory. "
258  << "\n Return l1t::CondNull, which means no valid condition category defined!";
259  }
260 
261  return result;
262 }
L1GtBoardType
board types in GT
Definition: GtDefinitions.h:28
GtConditionType
Definition: GtDefinitions.h:99
std::string l1GtConditionTypeEnumToString(const GtConditionType &)
std::string l1GtBoardTypeEnumToString(const L1GtBoardType &)
L1GtPsbQuad l1GtPsbQuadStringToEnum(const std::string &)
L1GtPsbQuad
quadruples sent to GT via PSB
Definition: GtDefinitions.h:47
#define constexpr
GtConditionCategory
condition categories
T x() const
Cartesian x coordinate.
tuple result
Definition: query.py:137
std::string l1GtPsbQuadEnumToString(const L1GtPsbQuad &)
GtConditionCategory l1GtConditionCategoryStringToEnum(const std::string &)
std::string l1GtConditionCategoryEnumToString(const GtConditionCategory &)
L1GtBoardType l1GtBoardTypeStringToEnum(const std::string &)
GtConditionType l1GtConditionTypeStringToEnum(const std::string &)
long double T