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  {0, (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  {0, (l1t::GtConditionType) - 1},
76  {"l1t::Type2corWithOverlapRemoval", l1t::Type2corWithOverlapRemoval}
77 
78 };
79 
80 // l1t::GtConditionCategory
81 constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
82  {"l1t::CondNull", l1t::CondNull},
83  {"l1t::CondMuon", l1t::CondMuon},
84  {"l1t::CondCalo", l1t::CondCalo},
85  {"l1t::CondEnergySum", l1t::CondEnergySum},
86  {"l1t::CondCorrelation", l1t::CondCorrelation},
87  {"l1t::CondExternal", l1t::CondExternal},
88  {0, (l1t::GtConditionCategory) - 1},
89  {"l1t::CondCorrelationWithOverlapRemoval", l1t::CondCorrelationWithOverlapRemoval}
90 };
91 
92 }
93 // l1t::L1GtBoardType
95  l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
96  if (value == (l1t::L1GtBoardType) - 1) {
97  edm::LogInfo("L1TGlobal") << "\n '" << label
98  << "' is not a recognized l1t::L1GtBoardType. \n Return l1t::BoardNull.";
99  value = l1t::BoardNull;
100  }
101 
102  if (value == l1t::BoardNull) {
103  edm::LogInfo("L1TGlobal")
104  << "\n l1t::BoardNull means no valid board type defined!";
105  }
106 
107  return value;
108 }
109 
111  char const *result= valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
112  if (boardType == l1t::BoardNull) {
113  edm::LogInfo("L1TGlobal")
114  << "\n l1t::BoardNull means no valid board type defined!";
115  }
116  if (!result) {
117  edm::LogInfo("L1TGlobal") << "\n '" << boardType
118  << "' is not a recognized l1t::L1GtBoardType. "
119  << "\n Return l1t::BoardNull, which means no valid board type defined!";
120  return "l1t::BoardNull";
121  }
122  return result;
123 }
124 
125 
126 
127 
128 
130  l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
131 
132  // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
133  // to be dealt by the corresponding module
134  if (value == (l1t::GtConditionType) -1) {
135  edm::LogInfo("L1TGlobal") << "\n '" << label
136  << "' is not a recognized l1t::GtConditionType. \n Return l1t::TypeNull.";
137 
138  value = l1t::TypeNull;
139  }
140 
141  if (value == l1t::TypeNull) {
142  edm::LogInfo("L1TGlobal")
143  << "\n l1t::TypeNull means no valid condition type defined!";
144  }
145 
146  return value;
147 }
148 
150  const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
151  if (conditionType == l1t::TypeNull)
152  edm::LogInfo("L1TGlobal")
153  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
154  if (!result) {
155  result = "l1t::TypeNull";
156  edm::LogInfo("L1TGlobal") << "\n '" << conditionType
157  << "' is not a recognized l1t::GtConditionType. "
158  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
159  }
160  return result;
161 }
162 
164  l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
165  // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
166  // to be dealt by the corresponding module
167  if (value == (l1t::GtConditionCategory) -1) {
168  edm::LogInfo("L1TGlobal") << "\n '" << label
169  << "' is not a recognized l1t::GtConditionCategory. \n Return l1t::CondNull.";
170 
171  value = l1t::CondNull;
172  }
173 
174  if (value == l1t::CondNull) {
175  edm::LogInfo("L1TGlobal")
176  << "\n l1t::CondNull means no valid condition category defined!";
177  }
178 
179  return value;
180 }
181 
183  char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
184  if (conditionCategory == l1t::CondNull)
185  edm::LogInfo("L1TGlobal")
186  << "\n Return l1t::CondNull, which means no valid condition category defined!";
187 
188  if (!result) {
189  result = "l1t::CondNull";
190  edm::LogInfo("L1TGlobal") << "\n '" << conditionCategory
191  << "' is not a recognized l1t::GtConditionCategory. "
192  << "\n Return l1t::CondNull, which means no valid condition category defined!";
193  }
194 
195  return result;
196 }
L1GtBoardType
board types in GT
std::string l1GtConditionTypeEnumToString(const GtConditionType &)
Definition: Block.h:11
std::string l1GtBoardTypeEnumToString(const L1GtBoardType &)
#define constexpr
GtConditionCategory
condition categories
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