CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GlobalDefinitions.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::MP7", l1t::MP7},
49  {"l1t::BoardNull", l1t::BoardNull},
50  {0, (l1t::L1GtBoardType)-1}
51 };
52 
53 
54 // l1t::GtConditionType
55 constexpr entry<l1t::GtConditionType> l1GtConditionTypeStringToEnumMap[] = {
56  {"l1t::TypeNull", l1t::TypeNull},
57  {"l1t::Type1s", l1t::Type1s},
58  {"l1t::Type2s", l1t::Type2s},
59  {"l1t::Type2wsc", l1t::Type2wsc},
60  {"l1t::Type2cor", l1t::Type2cor},
61  {"l1t::Type3s", l1t::Type3s},
62  {"l1t::Type4s", l1t::Type4s},
63  {"l1t::TypeETM", l1t::TypeETM},
64  {"l1t::TypeETT", l1t::TypeETT},
65  {"l1t::TypeHTT", l1t::TypeHTT},
66  {"l1t::TypeHTM", l1t::TypeHTM},
67  {"l1t::TypeETMHF", l1t::TypeETMHF},
68  {"l1t::TypeTowerCount", l1t::TypeTowerCount},
69  {"l1t::TypeMinBiasHFP0", l1t::TypeMinBiasHFP0},
70  {"l1t::TypeMinBiasHFM0", l1t::TypeMinBiasHFM0},
71  {"l1t::TypeMinBiasHFP1", l1t::TypeMinBiasHFP1},
72  {"l1t::TypeMinBiasHFM1", l1t::TypeMinBiasHFM1},
73  {"l1t::TypeExternal", l1t::TypeExternal},
74  {0, (l1t::GtConditionType) - 1}
75 };
76 
77 // l1t::GtConditionCategory
78 constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
79  {"l1t::CondNull", l1t::CondNull},
80  {"l1t::CondMuon", l1t::CondMuon},
81  {"l1t::CondCalo", l1t::CondCalo},
82  {"l1t::CondEnergySum", l1t::CondEnergySum},
83  {"l1t::CondCorrelation", l1t::CondCorrelation},
84  {"l1t::CondExternal", l1t::CondExternal},
85  {0, (l1t::GtConditionCategory) - 1}
86 };
87 
88 }
89 // l1t::L1GtBoardType
91  l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
92  if (value == (l1t::L1GtBoardType) - 1) {
93  edm::LogInfo("L1TGlobal") << "\n '" << label
94  << "' is not a recognized l1t::L1GtBoardType. \n Return l1t::BoardNull.";
95  value = l1t::BoardNull;
96  }
97 
98  if (value == l1t::BoardNull) {
99  edm::LogInfo("L1TGlobal")
100  << "\n l1t::BoardNull means no valid board type defined!";
101  }
102 
103  return value;
104 }
105 
107  char const *result= valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
108  if (boardType == l1t::BoardNull) {
109  edm::LogInfo("L1TGlobal")
110  << "\n l1t::BoardNull means no valid board type defined!";
111  }
112  if (!result) {
113  edm::LogInfo("L1TGlobal") << "\n '" << boardType
114  << "' is not a recognized l1t::L1GtBoardType. "
115  << "\n Return l1t::BoardNull, which means no valid board type defined!";
116  return "l1t::BoardNull";
117  }
118  return result;
119 }
120 
121 
122 
123 
124 
126  l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
127 
128  // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
129  // to be dealt by the corresponding module
130  if (value == (l1t::GtConditionType) -1) {
131  edm::LogInfo("L1TGlobal") << "\n '" << label
132  << "' is not a recognized l1t::GtConditionType. \n Return l1t::TypeNull.";
133 
134  value = l1t::TypeNull;
135  }
136 
137  if (value == l1t::TypeNull) {
138  edm::LogInfo("L1TGlobal")
139  << "\n l1t::TypeNull means no valid condition type defined!";
140  }
141 
142  return value;
143 }
144 
146  const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
147  if (conditionType == l1t::TypeNull)
148  edm::LogInfo("L1TGlobal")
149  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
150  if (!result) {
151  result = "l1t::TypeNull";
152  edm::LogInfo("L1TGlobal") << "\n '" << conditionType
153  << "' 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 
167  value = l1t::CondNull;
168  }
169 
170  if (value == l1t::CondNull) {
171  edm::LogInfo("L1TGlobal")
172  << "\n l1t::CondNull means no valid condition category defined!";
173  }
174 
175  return value;
176 }
177 
179  char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
180  if (conditionCategory == l1t::CondNull)
181  edm::LogInfo("L1TGlobal")
182  << "\n Return l1t::CondNull, which means no valid condition category defined!";
183 
184  if (!result) {
185  result = "l1t::CondNull";
186  edm::LogInfo("L1TGlobal") << "\n '" << conditionCategory
187  << "' is not a recognized l1t::GtConditionCategory. "
188  << "\n Return l1t::CondNull, which means no valid condition category defined!";
189  }
190 
191  return result;
192 }
L1GtBoardType
board types in GT
std::string l1GtConditionTypeEnumToString(const GtConditionType &)
Definition: Block.h:10
std::string l1GtBoardTypeEnumToString(const L1GtBoardType &)
#define constexpr
tuple result
Definition: mps_fire.py:84
GtConditionCategory
condition categories
T x() const
Cartesian x coordinate.
GtConditionCategory l1GtConditionCategoryStringToEnum(const std::string &)
std::string l1GtConditionCategoryEnumToString(const GtConditionCategory &)
L1GtBoardType l1GtBoardTypeStringToEnum(const std::string &)
GtConditionType l1GtConditionTypeStringToEnum(const std::string &)
list entry
Definition: mps_splice.py:62
long double T