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::TypeTowerCount", l1t::TypeTowerCount},
66  {"l1t::TypeMinBiasHFP0", l1t::TypeMinBiasHFP0},
67  {"l1t::TypeMinBiasHFM0", l1t::TypeMinBiasHFM0},
68  {"l1t::TypeMinBiasHFP1", l1t::TypeMinBiasHFP1},
69  {"l1t::TypeMinBiasHFM1", l1t::TypeMinBiasHFM1},
70  {"l1t::TypeZDCP", l1t::TypeZDCP},
71  {"l1t::TypeZDCM", l1t::TypeZDCM},
72  {"l1t::TypeAXOL1TL", l1t::TypeAXOL1TL},
73  {"l1t::TypeExternal", l1t::TypeExternal},
74  {nullptr, (l1t::GtConditionType)-1},
75  {"l1t::Type2corWithOverlapRemoval", l1t::Type2corWithOverlapRemoval},
76  {"l1t::TypeCent0", l1t::TypeCent0},
77  {"l1t::TypeCent1", l1t::TypeCent1},
78  {"l1t::TypeCent2", l1t::TypeCent2},
79  {"l1t::TypeCent3", l1t::TypeCent3},
80  {"l1t::TypeCent4", l1t::TypeCent4},
81  {"l1t::TypeCent5", l1t::TypeCent5},
82  {"l1t::TypeCent6", l1t::TypeCent6},
83  {"l1t::TypeCent7", l1t::TypeCent7},
84  {"l1t::TypeAsymEt", l1t::TypeAsymEt},
85  {"l1t::TypeAsymHt", l1t::TypeAsymHt},
86  {"l1t::TypeAsymEtHF", l1t::TypeAsymEtHF},
87  {"l1t::TypeAsymHtHF", l1t::TypeAsymHtHF}};
88 
89  // l1t::GtConditionCategory
90  constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
91  {"l1t::CondNull", l1t::CondNull},
92  {"l1t::CondMuon", l1t::CondMuon},
93  {"l1t::CondCalo", l1t::CondCalo},
94  {"l1t::CondEnergySum", l1t::CondEnergySum},
95  {"l1t::CondEnergySumZdc", l1t::CondEnergySumZdc},
96  {"l1t::CondAXOL1TL", l1t::CondAXOL1TL},
97  {"l1t::CondCorrelation", l1t::CondCorrelation},
98  {"l1t::CondCorrelationThreeBody", l1t::CondCorrelationThreeBody},
99  {"l1t::CondCorrelationWithOverlapRemoval", l1t::CondCorrelationWithOverlapRemoval},
100  {"l1t::CondExternal", l1t::CondExternal},
101  {nullptr, (l1t::GtConditionCategory)-1}};
102 
103 } // namespace
104 // l1t::L1GtBoardType
106  l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
107  if (value == (l1t::L1GtBoardType)-1) {
108  edm::LogInfo("L1TGlobal") << "\n '" << label
109  << "' is not a recognized l1t::L1GtBoardType. \n Return l1t::BoardNull.";
111  }
112 
113  if (value == l1t::BoardNull) {
114  edm::LogInfo("L1TGlobal") << "\n l1t::BoardNull means no valid board type defined!";
115  }
116 
117  return value;
118 }
119 
121  char const *result = valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
122  if (boardType == l1t::BoardNull) {
123  edm::LogInfo("L1TGlobal") << "\n l1t::BoardNull means no valid board type defined!";
124  }
125  if (!result) {
126  edm::LogInfo("L1TGlobal") << "\n '" << boardType << "' is not a recognized l1t::L1GtBoardType. "
127  << "\n Return l1t::BoardNull, which means no valid board type defined!";
128  return "l1t::BoardNull";
129  }
130  return result;
131 }
132 
134  l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
135 
136  // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
137  // to be dealt by the corresponding module
138  if (value == (l1t::GtConditionType)-1) {
139  edm::LogInfo("L1TGlobal") << "\n '" << label
140  << "' is not a recognized l1t::GtConditionType. \n Return l1t::TypeNull.";
141 
143  }
144 
145  if (value == l1t::TypeNull) {
146  edm::LogInfo("L1TGlobal") << "\n l1t::TypeNull means no valid condition type defined!";
147  }
148 
149  return value;
150 }
151 
153  const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
154  if (conditionType == l1t::TypeNull)
155  edm::LogInfo("L1TGlobal") << "\n Return l1t::TypeNull, which means no valid condition type defined!";
156  if (!result) {
157  result = "l1t::TypeNull";
158  edm::LogInfo("L1TGlobal") << "\n '" << conditionType << "' is not a recognized l1t::GtConditionType. "
159  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
160  }
161  return result;
162 }
163 
165  l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
166  // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
167  // to be dealt by the corresponding module
168  if (value == (l1t::GtConditionCategory)-1) {
169  edm::LogInfo("L1TGlobal") << "\n '" << label
170  << "' is not a recognized l1t::GtConditionCategory. \n Return l1t::CondNull.";
171 
173  }
174 
175  if (value == l1t::CondNull) {
176  edm::LogInfo("L1TGlobal") << "\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") << "\n Return l1t::CondNull, which means no valid condition category defined!";
186 
187  if (!result) {
188  result = "l1t::CondNull";
189  edm::LogInfo("L1TGlobal") << "\n '" << conditionCategory << "' is not a recognized l1t::GtConditionCategory. "
190  << "\n Return l1t::CondNull, which means no valid condition category defined!";
191  }
192 
193  return result;
194 }
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