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::TypeETM2", l1t::TypeETM2},
68  {"l1t::TypeMinBias", l1t::TypeMinBias},
69  {"l1t::TypeExternal", l1t::TypeExternal},
70  {0, (l1t::GtConditionType) - 1}
71 };
72 
73 // l1t::GtConditionCategory
74 constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
75  {"l1t::CondNull", l1t::CondNull},
76  {"l1t::CondMuon", l1t::CondMuon},
77  {"l1t::CondCalo", l1t::CondCalo},
78  {"l1t::CondEnergySum", l1t::CondEnergySum},
79  {"l1t::CondCorrelation", l1t::CondCorrelation},
80  {"l1t::CondExternal", l1t::CondExternal},
81  {0, (l1t::GtConditionCategory) - 1}
82 };
83 
84 }
85 // l1t::L1GtBoardType
87  l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
88  if (value == (l1t::L1GtBoardType) - 1) {
89  edm::LogInfo("L1TGlobal") << "\n '" << label
90  << "' is not a recognized l1t::L1GtBoardType. \n Return l1t::BoardNull.";
91  value = l1t::BoardNull;
92  }
93 
94  if (value == l1t::BoardNull) {
95  edm::LogInfo("L1TGlobal")
96  << "\n l1t::BoardNull means no valid board type defined!";
97  }
98 
99  return value;
100 }
101 
103  char const *result= valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
104  if (boardType == l1t::BoardNull) {
105  edm::LogInfo("L1TGlobal")
106  << "\n l1t::BoardNull means no valid board type defined!";
107  }
108  if (!result) {
109  edm::LogInfo("L1TGlobal") << "\n '" << boardType
110  << "' is not a recognized l1t::L1GtBoardType. "
111  << "\n Return l1t::BoardNull, which means no valid board type defined!";
112  return "l1t::BoardNull";
113  }
114  return result;
115 }
116 
117 
118 
119 
120 
122  l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
123 
124  // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
125  // to be dealt by the corresponding module
126  if (value == (l1t::GtConditionType) -1) {
127  edm::LogInfo("L1TGlobal") << "\n '" << label
128  << "' is not a recognized l1t::GtConditionType. \n Return l1t::TypeNull.";
129 
130  value = l1t::TypeNull;
131  }
132 
133  if (value == l1t::TypeNull) {
134  edm::LogInfo("L1TGlobal")
135  << "\n l1t::TypeNull means no valid condition type defined!";
136  }
137 
138  return value;
139 }
140 
142  const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
143  if (conditionType == l1t::TypeNull)
144  edm::LogInfo("L1TGlobal")
145  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
146  if (!result) {
147  result = "l1t::TypeNull";
148  edm::LogInfo("L1TGlobal") << "\n '" << conditionType
149  << "' is not a recognized l1t::GtConditionType. "
150  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
151  }
152  return result;
153 }
154 
156  l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
157  // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
158  // to be dealt by the corresponding module
159  if (value == (l1t::GtConditionCategory) -1) {
160  edm::LogInfo("L1TGlobal") << "\n '" << label
161  << "' is not a recognized l1t::GtConditionCategory. \n Return l1t::CondNull.";
162 
163  value = l1t::CondNull;
164  }
165 
166  if (value == l1t::CondNull) {
167  edm::LogInfo("L1TGlobal")
168  << "\n l1t::CondNull means no valid condition category defined!";
169  }
170 
171  return value;
172 }
173 
175  char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
176  if (conditionCategory == l1t::CondNull)
177  edm::LogInfo("L1TGlobal")
178  << "\n Return l1t::CondNull, which means no valid condition category defined!";
179 
180  if (!result) {
181  result = "l1t::CondNull";
182  edm::LogInfo("L1TGlobal") << "\n '" << conditionCategory
183  << "' is not a recognized l1t::GtConditionCategory. "
184  << "\n Return l1t::CondNull, which means no valid condition category defined!";
185  }
186 
187  return result;
188 }
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:95
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