CMS 3D CMS Logo

L1GlobalTriggerObjectMaps.cc
Go to the documentation of this file.
1 
17 
18 #include <algorithm>
19 #include <limits>
20 
22 
28 }
29 
30 bool L1GlobalTriggerObjectMaps::algorithmExists(int algorithmBitNumber) const {
31  std::vector<AlgorithmResult>::const_iterator i = std::lower_bound(
32  m_algorithmResults.begin(), m_algorithmResults.end(), AlgorithmResult(0, algorithmBitNumber, false));
33  if (i == m_algorithmResults.end() || i->algorithmBitNumber() != algorithmBitNumber) {
34  return false;
35  }
36  return true;
37 }
38 
39 bool L1GlobalTriggerObjectMaps::algorithmResult(int algorithmBitNumber) const {
40  std::vector<AlgorithmResult>::const_iterator i = std::lower_bound(
41  m_algorithmResults.begin(), m_algorithmResults.end(), AlgorithmResult(0, algorithmBitNumber, false));
42  if (i == m_algorithmResults.end() || i->algorithmBitNumber() != algorithmBitNumber) {
43  cms::Exception ex("L1GlobalTrigger");
44  ex << "algorithmBitNumber not found";
45  ex.addContext("Calling L1GlobalTriggerObjectMaps::algorithmResult");
46  throw ex;
47  }
48  return i->algorithmResult();
49 }
50 
52  int algorithmBitNumber, std::vector<L1GtLogicParser::OperandToken>& operandTokenVector) const {
53  unsigned startIndex = 0;
54  unsigned endIndex = 0;
55  getStartEndIndex(algorithmBitNumber, startIndex, endIndex);
56 
57  unsigned length = endIndex - startIndex;
58  if (length != operandTokenVector.size()) {
59  cms::Exception ex("L1GlobalTrigger");
60  ex << "operand token vector size does not match number of conditions";
61  ex.addContext("Calling L1GlobalTriggerObjectMaps::updateOperandTokenVector");
62  throw ex;
63  }
64 
65  for (unsigned i = 0; i < length; ++i) {
66  operandTokenVector[i].tokenResult = m_conditionResults[startIndex + i].conditionResult();
67  }
68 }
69 
70 void L1GlobalTriggerObjectMaps::getAlgorithmBitNumbers(std::vector<int>& algorithmBitNumbers) const {
71  algorithmBitNumbers.clear();
72  for (std::vector<AlgorithmResult>::const_iterator i = m_algorithmResults.begin(), iEnd = m_algorithmResults.end();
73  i != iEnd;
74  ++i) {
75  algorithmBitNumbers.push_back(i->algorithmBitNumber());
76  }
77 }
78 
79 unsigned L1GlobalTriggerObjectMaps::getNumberOfConditions(int algorithmBitNumber) const {
80  unsigned startIndex = 0;
81  unsigned endIndex = 0;
82  getStartEndIndex(algorithmBitNumber, startIndex, endIndex);
83  return endIndex - startIndex;
84 }
85 
87  int algorithmBitNumber) const {
88  unsigned startIndex = 0;
89  unsigned endIndex = 0;
90  getStartEndIndex(algorithmBitNumber, startIndex, endIndex);
91  return ConditionsInAlgorithm(&m_conditionResults[startIndex], endIndex - startIndex);
92 }
93 
95  int algorithmBitNumber, unsigned conditionNumber) const {
96  unsigned startIndex = 0;
97  unsigned endIndex = 0;
98  getStartEndIndex(algorithmBitNumber, startIndex, endIndex);
99 
100  if (endIndex <= startIndex + conditionNumber) {
101  cms::Exception ex("L1GlobalTrigger");
102  ex << "Condition number is out of range";
103  ex.addContext("Calling L1GlobalTriggerObjectMaps::getCombinationsInCondition");
104  throw ex;
105  }
106 
107  unsigned endObjectIndex = m_combinations.size();
108  unsigned nextConditionIndex = startIndex + conditionNumber + 1U;
109  if (nextConditionIndex < m_conditionResults.size()) {
110  endObjectIndex = m_conditionResults[nextConditionIndex].startIndexOfCombinations();
111  }
112  unsigned beginObjectIndex = m_conditionResults[startIndex + conditionNumber].startIndexOfCombinations();
113  unsigned short nObjectsPerCombination = m_conditionResults[startIndex + conditionNumber].nObjectsPerCombination();
114 
115  if (endObjectIndex == beginObjectIndex) {
116  return CombinationsInCondition(nullptr, 0, 0);
117  }
118  if (endObjectIndex < beginObjectIndex || m_combinations.size() < endObjectIndex || nObjectsPerCombination == 0 ||
119  (endObjectIndex - beginObjectIndex) % nObjectsPerCombination != 0) {
120  cms::Exception ex("L1GlobalTrigger");
121  ex << "Indexes to combinations are invalid";
122  ex.addContext("Calling L1GlobalTriggerObjectMaps::getCombinationsInCondition");
123  throw ex;
124  }
125  return CombinationsInCondition(&m_combinations[beginObjectIndex],
126  (endObjectIndex - beginObjectIndex) / nObjectsPerCombination,
127  nObjectsPerCombination);
128 }
129 
131 
132 void L1GlobalTriggerObjectMaps::pushBackAlgorithm(unsigned startIndexOfConditions,
133  int algorithmBitNumber,
134  bool algorithmResult) {
135  m_algorithmResults.push_back(AlgorithmResult(startIndexOfConditions, algorithmBitNumber, algorithmResult));
136 }
137 
139  // None of these checks should ever fail unless there
140  // is a bug in the code filling this object
141  for (std::vector<AlgorithmResult>::const_iterator i = m_algorithmResults.begin(), iEnd = m_algorithmResults.end();
142  i != iEnd;
143  ++i) {
144  std::vector<AlgorithmResult>::const_iterator j = i;
145  ++j;
146  if (j != iEnd && !(*i < *j)) {
147  cms::Exception ex("L1GlobalTrigger");
148  ex << "AlgorithmResults should be sorted in increasing order of bit number with no duplicates. It is not.";
149  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
150  throw ex;
151  }
152  unsigned endIndex = (j != iEnd) ? j->startIndexOfConditions() : m_conditionResults.size();
153 
154  if (endIndex < i->startIndexOfConditions()) {
155  cms::Exception ex("L1GlobalTrigger");
156  ex << "startIndexOfConditions decreases or exceeds the size of m_conditionResults";
157  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
158  throw ex;
159  }
160  }
161  for (std::vector<ConditionResult>::const_iterator i = m_conditionResults.begin(), iEnd = m_conditionResults.end();
162  i != iEnd;
163  ++i) {
164  std::vector<ConditionResult>::const_iterator j = i;
165  ++j;
166  unsigned endIndex = (j != iEnd) ? j->startIndexOfCombinations() : m_combinations.size();
167 
168  if (endIndex < i->startIndexOfCombinations()) {
169  cms::Exception ex("L1GlobalTrigger");
170  ex << "startIndexOfCombinations decreases or exceeds the size of m_conditionResults";
171  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
172  throw ex;
173  }
174  unsigned length = endIndex - i->startIndexOfCombinations();
175  if (length == 0U) {
176  if (i->nObjectsPerCombination() != 0U) {
177  cms::Exception ex("L1GlobalTrigger");
178  ex << "Length is zero and nObjectsInCombination is not zero";
179  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
180  throw ex;
181  }
182  } else {
183  if (i->nObjectsPerCombination() == 0 || length % i->nObjectsPerCombination() != 0) {
184  cms::Exception ex("L1GlobalTrigger");
185  ex << "Size indicated by startIndexOfCombinations is not a multiple of nObjectsInCombination";
186  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
187  throw ex;
188  }
189  }
190  }
191 }
192 
194 
195 void L1GlobalTriggerObjectMaps::pushBackCondition(unsigned startIndexOfCombinations,
196  unsigned short nObjectsPerCombination,
197  bool conditionResult) {
198  m_conditionResults.push_back(ConditionResult(startIndexOfCombinations, nObjectsPerCombination, conditionResult));
199 }
200 
202 
203 void L1GlobalTriggerObjectMaps::pushBackObjectIndex(unsigned char objectIndex) {
204  m_combinations.push_back(objectIndex);
205 }
206 
208  m_namesParameterSetID = psetID;
209 }
210 
212  : m_startIndexOfConditions(0), m_algorithmBitNumber(0), m_algorithmResult(false) {}
213 
215  int algorithmBitNumber,
216  bool algorithmResult)
217  : m_startIndexOfConditions(startIndexOfConditions), m_algorithmResult(algorithmResult) {
218  // We made the decision to try to save space in the data format
219  // and fit this object into 8 bytes by making the persistent
220  // algorithmBitNumber a short. This creates something very
221  // ugly below. In practice the range should never be exceeded.
222  // In fact it is currently always supposed to be less than 128.
223  // I hope this never comes back to haunt us for some unexpected reason.
224  // I cringe when I look at it, but cannot think of any practical
225  // harm ... It is probably a real bug if anyone ever
226  // tries to shove a big int into here.
229  cms::Exception ex("L1GlobalTrigger");
230  ex << "algorithmBitNumber out of range of a short int";
231  ex.addContext("Calling L1GlobalTriggerObjectMaps::AlgorithmResult::AlgorithmResult");
232  throw ex;
233  }
234  m_algorithmBitNumber = static_cast<short>(algorithmBitNumber);
235 }
236 
238  : m_startIndexOfCombinations(0), m_nObjectsPerCombination(0), m_conditionResult(false) {}
239 
241  unsigned short nObjectsPerCombination,
242  bool conditionResult)
243  : m_startIndexOfCombinations(startIndexOfCombinations),
244  m_nObjectsPerCombination(nObjectsPerCombination),
245  m_conditionResult(conditionResult) {}
246 
248  unsigned nConditions)
249  : m_conditionResults(conditionResults), m_nConditions(nConditions) {}
250 
252  if (condition >= m_nConditions) {
253  cms::Exception ex("L1GlobalTrigger");
254  ex << "argument out of range";
255  ex.addContext("Calling L1GlobalTriggerObjectMaps::ConditionsInAlgorithm::getConditionResult");
256  throw ex;
257  }
258  return (m_conditionResults + condition)->conditionResult();
259 }
260 
262  unsigned nCombinations,
263  unsigned short nObjectsPerCombination)
264  : m_startOfObjectIndexes(startOfObjectIndexes),
265  m_nCombinations(nCombinations),
266  m_nObjectsPerCombination(nObjectsPerCombination) {}
267 
269  unsigned object) const {
270  if (combination >= m_nCombinations || object >= m_nObjectsPerCombination) {
271  cms::Exception ex("L1GlobalTrigger");
272  ex << "arguments out of range";
273  ex.addContext("Calling L1GlobalTriggerObjectMaps::CombinationsInCondition::getObjectIndex");
274  throw ex;
275  }
276  return m_startOfObjectIndexes[combination * m_nObjectsPerCombination + object];
277 }
278 
280  unsigned& startIndex,
281  unsigned& endIndex) const {
282  std::vector<AlgorithmResult>::const_iterator iAlgo = std::lower_bound(
283  m_algorithmResults.begin(), m_algorithmResults.end(), AlgorithmResult(0, algorithmBitNumber, false));
284 
285  if (iAlgo == m_algorithmResults.end() || iAlgo->algorithmBitNumber() != algorithmBitNumber) {
286  cms::Exception ex("L1GlobalTrigger");
287  ex << "algorithmBitNumber not found";
288  ex.addContext("Calling L1GlobalTriggerObjectMaps::getStartEndIndex");
289  throw ex;
290  }
291 
292  startIndex = iAlgo->startIndexOfConditions();
293  ++iAlgo;
294  endIndex = (iAlgo != m_algorithmResults.end()) ? iAlgo->startIndexOfConditions() : m_conditionResults.size();
295 
296  if (endIndex < startIndex || m_conditionResults.size() < endIndex) {
297  cms::Exception ex("L1GlobalTrigger");
298  ex << "index out of order or out of range";
299  ex.addContext("Calling L1GlobalTriggerObjectMaps::getStartEndIndex");
300  throw ex;
301  }
302 }
L1GlobalTriggerObjectMaps::setNamesParameterSetID
void setNamesParameterSetID(edm::ParameterSetID const &psetID)
Definition: L1GlobalTriggerObjectMaps.cc:207
L1GlobalTriggerObjectMaps::ConditionResult::ConditionResult
ConditionResult()
Definition: L1GlobalTriggerObjectMaps.cc:237
L1GlobalTriggerObjectMaps::reserveForObjectIndexes
void reserveForObjectIndexes(unsigned n)
Definition: L1GlobalTriggerObjectMaps.cc:201
L1GlobalTriggerObjectMaps::getCombinationsInCondition
CombinationsInCondition getCombinationsInCondition(int algorithmBitNumber, unsigned conditionNumber) const
Definition: L1GlobalTriggerObjectMaps.cc:94
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
mps_fire.i
i
Definition: mps_fire.py:355
L1GlobalTriggerObjectMaps::AlgorithmResult::algorithmBitNumber
short algorithmBitNumber() const
Definition: L1GlobalTriggerObjectMaps.h:95
funct::false
false
Definition: Factorize.h:34
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
L1GlobalTriggerObjectMaps::swap
void swap(L1GlobalTriggerObjectMaps &rh)
Definition: L1GlobalTriggerObjectMaps.cc:23
cms::Exception::addContext
void addContext(std::string const &context)
Definition: Exception.cc:165
L1GlobalTriggerObjectMaps::ConditionsInAlgorithm::getConditionResult
bool getConditionResult(unsigned condition) const
Definition: L1GlobalTriggerObjectMaps.cc:251
edm::Hash::swap
void swap(Hash< I > &other)
Definition: Hash.h:181
min
T min(T a, T b)
Definition: MathUtil.h:58
L1GlobalTriggerObjectMaps::m_namesParameterSetID
edm::ParameterSetID m_namesParameterSetID
Definition: L1GlobalTriggerObjectMaps.h:160
L1GlobalTriggerObjectMaps::AlgorithmResult::m_algorithmBitNumber
short m_algorithmBitNumber
Definition: L1GlobalTriggerObjectMaps.h:102
L1GlobalTriggerObjectMaps.h
L1GlobalTriggerObjectMaps::m_algorithmResults
std::vector< AlgorithmResult > m_algorithmResults
Definition: L1GlobalTriggerObjectMaps.h:157
L1GlobalTriggerObjectMaps::ConditionsInAlgorithm::ConditionsInAlgorithm
ConditionsInAlgorithm(ConditionResult const *conditionResults, unsigned nConditions)
Definition: L1GlobalTriggerObjectMaps.cc:247
L1GlobalTriggerObjectMaps::consistencyCheck
void consistencyCheck() const
Definition: L1GlobalTriggerObjectMaps.cc:138
L1GlobalTriggerObjectMaps::algorithmExists
bool algorithmExists(int algorithmBitNumber) const
Returns true if there is an entry for this algorithm bit number.
Definition: L1GlobalTriggerObjectMaps.cc:30
L1GlobalTriggerObjectMaps::ConditionsInAlgorithm
Definition: L1GlobalTriggerObjectMaps.h:120
L1GlobalTriggerObjectMaps::reserveForAlgorithms
void reserveForAlgorithms(unsigned n)
Definition: L1GlobalTriggerObjectMaps.cc:130
edm::Hash< ParameterSetType >
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
L1GlobalTriggerObjectMaps::pushBackAlgorithm
void pushBackAlgorithm(unsigned startIndexOfConditions, int algorithmBitNumber, bool algorithmResult)
Definition: L1GlobalTriggerObjectMaps.cc:132
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
L1GlobalTriggerObjectMaps::pushBackObjectIndex
void pushBackObjectIndex(unsigned char objectIndex)
Definition: L1GlobalTriggerObjectMaps.cc:203
L1GlobalTriggerObjectMaps::CombinationsInCondition
Definition: L1GlobalTriggerObjectMaps.h:131
L1GlobalTriggerObjectMaps::updateOperandTokenVector
void updateOperandTokenVector(int algorithmBitNumber, std::vector< L1GtLogicParser::OperandToken > &operandTokenVector) const
Update the condition result in the operandTokenVector.
Definition: L1GlobalTriggerObjectMaps.cc:51
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
L1GlobalTriggerObjectMaps::AlgorithmResult::AlgorithmResult
AlgorithmResult()
Definition: L1GlobalTriggerObjectMaps.cc:211
L1GlobalTriggerObjectMaps::m_combinations
std::vector< unsigned char > m_combinations
Definition: L1GlobalTriggerObjectMaps.h:159
L1GlobalTriggerObjectMaps::algorithmResult
bool algorithmResult(int algorithmBitNumber) const
Returns whether an algorithm trigger passed or failed.
Definition: L1GlobalTriggerObjectMaps.cc:39
L1GlobalTriggerObjectMaps::AlgorithmResult
Definition: L1GlobalTriggerObjectMaps.h:90
goodZToMuMu_cfi.condition
condition
Definition: goodZToMuMu_cfi.py:37
L1GlobalTriggerObjectMaps::getConditionsInAlgorithm
ConditionsInAlgorithm getConditionsInAlgorithm(int algorithmBitNumber) const
Definition: L1GlobalTriggerObjectMaps.cc:86
L1GlobalTriggerObjectMaps::CombinationsInCondition::getObjectIndex
unsigned char getObjectIndex(unsigned combination, unsigned object) const
Definition: L1GlobalTriggerObjectMaps.cc:268
L1GlobalTriggerObjectMaps::pushBackCondition
void pushBackCondition(unsigned startIndexOfCombinations, unsigned short nObjectsPerCombination, bool conditionResult)
Definition: L1GlobalTriggerObjectMaps.cc:195
L1GlobalTriggerObjectMaps::reserveForConditions
void reserveForConditions(unsigned n)
Definition: L1GlobalTriggerObjectMaps.cc:193
L1GlobalTriggerObjectMaps::ConditionResult
Definition: L1GlobalTriggerObjectMaps.h:106
L1GlobalTriggerObjectMaps::CombinationsInCondition::CombinationsInCondition
CombinationsInCondition(unsigned char const *startOfObjectIndexes, unsigned nCombinations, unsigned short nObjectsPerCombination)
Definition: L1GlobalTriggerObjectMaps.cc:261
L1GlobalTriggerObjectMaps::m_conditionResults
std::vector< ConditionResult > m_conditionResults
Definition: L1GlobalTriggerObjectMaps.h:158
Exception.h
L1GlobalTriggerObjectMaps::getNumberOfConditions
unsigned getNumberOfConditions(int algorithmBitNumber) const
Number of conditions associated with an algorithm.
Definition: L1GlobalTriggerObjectMaps.cc:79
cms::Exception
Definition: Exception.h:70
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
L1GlobalTriggerObjectMaps::getStartEndIndex
void getStartEndIndex(int algorithmBitNumber, unsigned &startIndex, unsigned &endIndex) const
Definition: L1GlobalTriggerObjectMaps.cc:279
L1GlobalTriggerObjectMaps::getAlgorithmBitNumbers
void getAlgorithmBitNumbers(std::vector< int > &algorithmBitNumbers) const
Fills the vector with all the algorithm bit numbers.
Definition: L1GlobalTriggerObjectMaps.cc:70
L1GlobalTriggerObjectMaps
Definition: L1GlobalTriggerObjectMaps.h:24