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::TypeExternal", l1t::TypeExternal},
71  {nullptr, (l1t::GtConditionType)-1},
72  {"l1t::Type2corWithOverlapRemoval", l1t::Type2corWithOverlapRemoval},
73  {"l1t::TypeCent0", l1t::TypeCent0},
74  {"l1t::TypeCent1", l1t::TypeCent1},
75  {"l1t::TypeCent2", l1t::TypeCent2},
76  {"l1t::TypeCent3", l1t::TypeCent3},
77  {"l1t::TypeCent4", l1t::TypeCent4},
78  {"l1t::TypeCent5", l1t::TypeCent5},
79  {"l1t::TypeCent6", l1t::TypeCent6},
80  {"l1t::TypeCent7", l1t::TypeCent7},
81  {"l1t::TypeAsymEt", l1t::TypeAsymEt},
82  {"l1t::TypeAsymHt", l1t::TypeAsymHt},
83  {"l1t::TypeAsymEtHF", l1t::TypeAsymEtHF},
84  {"l1t::TypeAsymHtHF", l1t::TypeAsymHtHF}};
85 
86  // l1t::GtConditionCategory
87  constexpr entry<l1t::GtConditionCategory> l1GtConditionCategoryStringToEnumMap[] = {
88  {"l1t::CondNull", l1t::CondNull},
89  {"l1t::CondMuon", l1t::CondMuon},
90  {"l1t::CondCalo", l1t::CondCalo},
91  {"l1t::CondEnergySum", l1t::CondEnergySum},
92  {"l1t::CondCorrelation", l1t::CondCorrelation},
93  {"l1t::CondCorrelationThreeBody", l1t::CondCorrelationThreeBody},
94  {"l1t::CondCorrelationWithOverlapRemoval", l1t::CondCorrelationWithOverlapRemoval},
95  {"l1t::CondExternal", l1t::CondExternal},
96  {nullptr, (l1t::GtConditionCategory)-1}};
97 
98 } // namespace
99 // l1t::L1GtBoardType
101  l1t::L1GtBoardType value = keyToValue(label.c_str(), l1GtBoardTypeStringToEnumMap);
102  if (value == (l1t::L1GtBoardType)-1) {
103  edm::LogInfo("L1TGlobal") << "\n '" << label
104  << "' is not a recognized l1t::L1GtBoardType. \n Return l1t::BoardNull.";
106  }
107 
108  if (value == l1t::BoardNull) {
109  edm::LogInfo("L1TGlobal") << "\n l1t::BoardNull means no valid board type defined!";
110  }
111 
112  return value;
113 }
114 
116  char const *result = valueToKey(boardType, l1GtBoardTypeStringToEnumMap);
117  if (boardType == l1t::BoardNull) {
118  edm::LogInfo("L1TGlobal") << "\n l1t::BoardNull means no valid board type defined!";
119  }
120  if (!result) {
121  edm::LogInfo("L1TGlobal") << "\n '" << boardType << "' is not a recognized l1t::L1GtBoardType. "
122  << "\n Return l1t::BoardNull, which means no valid board type defined!";
123  return "l1t::BoardNull";
124  }
125  return result;
126 }
127 
129  l1t::GtConditionType value = keyToValue(label.c_str(), l1GtConditionTypeStringToEnumMap);
130 
131  // in case of unrecognized l1t::GtConditionType, return l1t::TypeNull
132  // to be dealt by the corresponding module
133  if (value == (l1t::GtConditionType)-1) {
134  edm::LogInfo("L1TGlobal") << "\n '" << label
135  << "' is not a recognized l1t::GtConditionType. \n Return l1t::TypeNull.";
136 
138  }
139 
140  if (value == l1t::TypeNull) {
141  edm::LogInfo("L1TGlobal") << "\n l1t::TypeNull means no valid condition type defined!";
142  }
143 
144  return value;
145 }
146 
148  const char *result = valueToKey(conditionType, l1GtConditionTypeStringToEnumMap);
150  edm::LogInfo("L1TGlobal") << "\n Return l1t::TypeNull, which means no valid condition type defined!";
151  if (!result) {
152  result = "l1t::TypeNull";
153  edm::LogInfo("L1TGlobal") << "\n '" << conditionType << "' is not a recognized l1t::GtConditionType. "
154  << "\n Return l1t::TypeNull, which means no valid condition type defined!";
155  }
156  return result;
157 }
158 
160  l1t::GtConditionCategory value = keyToValue(label.c_str(), l1GtConditionCategoryStringToEnumMap);
161  // in case of unrecognized l1t::GtConditionCategory, return l1t::CondNull
162  // to be dealt by the corresponding module
163  if (value == (l1t::GtConditionCategory)-1) {
164  edm::LogInfo("L1TGlobal") << "\n '" << label
165  << "' is not a recognized l1t::GtConditionCategory. \n Return l1t::CondNull.";
166 
168  }
169 
170  if (value == l1t::CondNull) {
171  edm::LogInfo("L1TGlobal") << "\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") << "\n Return l1t::CondNull, which means no valid condition category defined!";
181 
182  if (!result) {
183  result = "l1t::CondNull";
184  edm::LogInfo("L1TGlobal") << "\n '" << conditionCategory << "' is not a recognized l1t::GtConditionCategory. "
185  << "\n Return l1t::CondNull, which means no valid condition category defined!";
186  }
187 
188  return result;
189 }
l1t::l1GtConditionCategoryEnumToString
std::string l1GtConditionCategoryEnumToString(const GtConditionCategory &)
Definition: GlobalDefinitions.cc:177
l1t::Type2cor
Definition: GlobalDefinitions.h:54
l1t::TypeCent5
Definition: GlobalDefinitions.h:75
MessageLogger.h
l1t::l1GtConditionCategoryStringToEnum
GtConditionCategory l1GtConditionCategoryStringToEnum(const std::string &)
Definition: GlobalDefinitions.cc:159
l1t::TypeNull
Definition: GlobalDefinitions.h:50
mps_splice.entry
entry
Definition: mps_splice.py:68
l1t::TypeETM
Definition: GlobalDefinitions.h:57
l1t::Type3s
Definition: GlobalDefinitions.h:55
l1t::CondCorrelationWithOverlapRemoval
Definition: GlobalDefinitions.h:100
l1t::TypeAsymEtHF
Definition: GlobalDefinitions.h:80
l1t::TypeMinBiasHFP0
Definition: GlobalDefinitions.h:63
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
l1t::TypeCent2
Definition: GlobalDefinitions.h:72
l1t::TypeCent3
Definition: GlobalDefinitions.h:73
l1t::TypeCent7
Definition: GlobalDefinitions.h:77
writeEcalDQMStatus.conditionType
conditionType
Definition: writeEcalDQMStatus.py:52
l1t::TypeMinBiasHFM1
Definition: GlobalDefinitions.h:66
l1t::Type2corWithOverlapRemoval
Definition: GlobalDefinitions.h:69
l1t::TypeCent1
Definition: GlobalDefinitions.h:71
l1t::CondCalo
Definition: GlobalDefinitions.h:96
l1t::BoardNull
Definition: GlobalDefinitions.h:29
l1t::CondNull
Definition: GlobalDefinitions.h:94
l1t::L1GtBoardType
L1GtBoardType
board types in GT
Definition: GlobalDefinitions.h:29
l1t::GtConditionType
GtConditionType
Definition: GlobalDefinitions.h:49
l1t::l1GtBoardTypeStringToEnum
L1GtBoardType l1GtBoardTypeStringToEnum(const std::string &)
Definition: GlobalDefinitions.cc:100
l1t::TypeAsymEt
Definition: GlobalDefinitions.h:78
l1t::TypeHTT
Definition: GlobalDefinitions.h:59
l1t::l1GtConditionTypeStringToEnum
GtConditionType l1GtConditionTypeStringToEnum(const std::string &)
Definition: GlobalDefinitions.cc:128
l1t::TypeCent4
Definition: GlobalDefinitions.h:74
funct::true
true
Definition: Factorize.h:173
l1t::MP7
Definition: Block.h:11
l1t::CondCorrelationThreeBody
Definition: GlobalDefinitions.h:101
l1t::Type1s
Definition: GlobalDefinitions.h:51
l1t::l1GtConditionTypeEnumToString
std::string l1GtConditionTypeEnumToString(const GtConditionType &)
Definition: GlobalDefinitions.cc:147
l1t::TypeMinBiasHFP1
Definition: GlobalDefinitions.h:65
l1t::TypeTowerCount
Definition: GlobalDefinitions.h:62
value
Definition: value.py:1
l1t::l1GtBoardTypeEnumToString
std::string l1GtBoardTypeEnumToString(const L1GtBoardType &)
Definition: GlobalDefinitions.cc:115
l1t::CondEnergySum
Definition: GlobalDefinitions.h:97
l1t::Type2wsc
Definition: GlobalDefinitions.h:53
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
l1t::TypeETMHF
Definition: GlobalDefinitions.h:61
l1t::TypeAsymHt
Definition: GlobalDefinitions.h:79
l1t::Type2s
Definition: GlobalDefinitions.h:52
l1t::TypeETT
Definition: GlobalDefinitions.h:58
l1t::TypeHTM
Definition: GlobalDefinitions.h:60
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.value
value
Definition: relativeConstraints.py:53
GlobalDefinitions.h
l1t::CondCorrelation
Definition: GlobalDefinitions.h:98
genVertex_cff.x
x
Definition: genVertex_cff.py:13
l1t::TypeExternal
Definition: GlobalDefinitions.h:68
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
l1t::CondExternal
Definition: GlobalDefinitions.h:99
l1t::TypeCent6
Definition: GlobalDefinitions.h:76
l1t::CondMuon
Definition: GlobalDefinitions.h:95
l1t::TypeAsymHtHF
Definition: GlobalDefinitions.h:81
l1t::Type4s
Definition: GlobalDefinitions.h:56
l1t::GtConditionCategory
GtConditionCategory
condition categories
Definition: GlobalDefinitions.h:93
l1t::TypeMinBiasHFM0
Definition: GlobalDefinitions.h:64
mps_fire.result
result
Definition: mps_fire.py:311
l1t::TypeCent0
Definition: GlobalDefinitions.h:70
label
const char * label
Definition: PFTauDecayModeTools.cc:11