CMS 3D CMS Logo

GlobalDefinitions.cc
Go to the documentation of this file.
1 
16 // this class header
18 
19 // system include files
20 #include <cstring>
21 
22 // user include files
24 namespace {
25  template <class T>
26  struct entry {
27  char const *label;
28  T value;
29  };
30 
31  constexpr bool same(char const *x, char const *y) {
32  return !*x && !*y ? true : /* 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}, {"l1t::BoardNull", l1t::BoardNull}, {nullptr, (l1t::L1GtBoardType)-1}};
50 
51  // l1t::GtConditionType
52  constexpr entry<l1t::GtConditionType> l1GtConditionTypeStringToEnumMap[] = {
53  {"l1t::TypeNull", l1t::TypeNull},
54  {"l1t::Type1s", l1t::Type1s},
55  {"l1t::Type2s", l1t::Type2s},
56  {"l1t::Type2wsc", l1t::Type2wsc},
57  {"l1t::Type2cor", l1t::Type2cor},
58  {"l1t::Type3s", l1t::Type3s},
59  {"l1t::Type4s", l1t::Type4s},
60  {"l1t::TypeETM", l1t::TypeETM},
61  {"l1t::TypeETT", l1t::TypeETT},
62  {"l1t::TypeHTT", l1t::TypeHTT},
63  {"l1t::TypeHTM", l1t::TypeHTM},
64  {"l1t::TypeETMHF", l1t::TypeETMHF},
65  {"l1t::TypeHTMHF", l1t::TypeHTMHF},
66  {"l1t::TypeTowerCount", l1t::TypeTowerCount},
67  {"l1t::TypeMinBiasHFP0", l1t::TypeMinBiasHFP0},
68  {"l1t::TypeMinBiasHFM0", l1t::TypeMinBiasHFM0},
69  {"l1t::TypeMinBiasHFP1", l1t::TypeMinBiasHFP1},
70  {"l1t::TypeMinBiasHFM1", l1t::TypeMinBiasHFM1},
71  {"l1t::TypeZDCP", l1t::TypeZDCP},
72  {"l1t::TypeZDCM", l1t::TypeZDCM},
73  {"l1t::TypeAXOL1TL", l1t::TypeAXOL1TL},
74  {"l1t::TypeCICADA", l1t::TypeCICADA},
75  {"l1t::TypeExternal", l1t::TypeExternal},
76  {nullptr, (l1t::GtConditionType)-1},
77  {"l1t::Type2corWithOverlapRemoval", l1t::Type2corWithOverlapRemoval},
78  {"l1t::TypeCent0", l1t::TypeCent0},
79  {"l1t::TypeCent1", l1t::TypeCent1},
80  {"l1t::TypeCent2", l1t::TypeCent2},
81  {"l1t::TypeCent3", l1t::TypeCent3},
82  {"l1t::TypeCent4", l1t::TypeCent4},
83  {"l1t::TypeCent5", l1t::TypeCent5},
84  {"l1t::TypeCent6", l1t::TypeCent6},
85  {"l1t::TypeCent7", l1t::TypeCent7},
86  {"l1t::TypeAsymEt", l1t::TypeAsymEt},
87  {"l1t::TypeAsymHt", l1t::TypeAsymHt},
88  {"l1t::TypeAsymEtHF", l1t::TypeAsymEtHF},
89  {"l1t::TypeAsymHtHF", l1t::TypeAsymHtHF}};
90 
91  // l1t::GtConditionCategory
92  constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
93  {"l1t::CondNull", l1t::CondNull},
94  {"l1t::CondMuon", l1t::CondMuon},
95  {"l1t::CondCalo", l1t::CondCalo},
96  {"l1t::CondEnergySum", l1t::CondEnergySum},
97  {"l1t::CondEnergySumZdc", l1t::CondEnergySumZdc},
98  {"l1t::CondAXOL1TL", l1t::CondAXOL1TL},
99  {"l1t::CondCICADA", l1t::CondCICADA},
100  {"l1t::CondCorrelation", l1t::CondCorrelation},
101  {"l1t::CondCorrelationThreeBody", l1t::CondCorrelationThreeBody},
102  {"l1t::CondCorrelationWithOverlapRemoval", l1t::CondCorrelationWithOverlapRemoval},
103  {"l1t::CondExternal", l1t::CondExternal},
104  {nullptr, (l1t::GtConditionCategory)-1}};
105 
106 } // namespace
107 // l1t::L1GtBoardType
109  l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
110  if (value == (l1t::L1GtBoardType)-1) {
111  edm::LogInfo("L1TGlobal") << "\n '" << label
112  << "' is not a recognized l1t::L1GtBoardType. \n Return l1t::BoardNull.";
114  }
115 
116  if (value == l1t::BoardNull) {
117  edm::LogInfo("L1TGlobal") << "\n l1t::BoardNull means no valid board type defined!";
118  }
119 
120  return value;
121 }
122 
124  char const *result = valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
125  if (boardType == l1t::BoardNull) {
126  edm::LogInfo("L1TGlobal") << "\n l1t::BoardNull means no valid board type defined!";
127  }
128  if (!result) {
129  edm::LogInfo("L1TGlobal") << "\n '" << boardType << "' is not a recognized l1t::L1GtBoardType. "
130  << "\n Return l1t::BoardNull, which means no valid board type defined!";
131  return "l1t::BoardNull";
132  }
133  return result;
134 }
135 
137  l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
138 
139  // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
140  // to be dealt by the corresponding module
141  if (value == (l1t::GtConditionType)-1) {
142  edm::LogInfo("L1TGlobal") << "\n '" << label
143  << "' is not a recognized l1t::GtConditionType. \n Return l1t::TypeNull.";
144 
146  }
147 
148  if (value == l1t::TypeNull) {
149  edm::LogInfo("L1TGlobal") << "\n l1t::TypeNull means no valid condition type defined!";
150  }
151 
152  return value;
153 }
154 
156  const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
157  if (conditionType == l1t::TypeNull)
158  edm::LogInfo("L1TGlobal") << "\n Return l1t::TypeNull, which means no valid condition type defined!";
159  if (!result) {
160  result = "l1t::TypeNull";
161  edm::LogInfo("L1TGlobal") << "\n '" << conditionType << "' is not a recognized l1t::GtConditionType. "
162  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
163  }
164  return result;
165 }
166 
168  l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
169  // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
170  // to be dealt by the corresponding module
171  if (value == (l1t::GtConditionCategory)-1) {
172  edm::LogInfo("L1TGlobal") << "\n '" << label
173  << "' is not a recognized l1t::GtConditionCategory. \n Return l1t::CondNull.";
174 
176  }
177 
178  if (value == l1t::CondNull) {
179  edm::LogInfo("L1TGlobal") << "\n l1t::CondNull means no valid condition category defined!";
180  }
181 
182  return value;
183 }
184 
186  char const *result = valueToKey(conditionCategory, l1GtConditionCategoryStringToEnumMap);
187  if (conditionCategory == l1t::CondNull)
188  edm::LogInfo("L1TGlobal") << "\n Return l1t::CondNull, which means no valid condition category defined!";
189 
190  if (!result) {
191  result = "l1t::CondNull";
192  edm::LogInfo("L1TGlobal") << "\n '" << conditionCategory << "' is not a recognized l1t::GtConditionCategory. "
193  << "\n Return l1t::CondNull, which means no valid condition category defined!";
194  }
195 
196  return result;
197 }
L1GtBoardType
board types in GT
std::string l1GtConditionTypeEnumToString(const GtConditionType &)
Definition: Block.h:11
std::string l1GtBoardTypeEnumToString(const L1GtBoardType &)
GtConditionCategory
condition categories
char const * label
Definition: value.py:1
GtConditionCategory l1GtConditionCategoryStringToEnum(const std::string &)
Log< level::Info, false > LogInfo
std::string l1GtConditionCategoryEnumToString(const GtConditionCategory &)
L1GtBoardType l1GtBoardTypeStringToEnum(const std::string &)
GtConditionType l1GtConditionTypeStringToEnum(const std::string &)
float x
long double T