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