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