CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GlobalTriggerObjectMaps.cc
Go to the documentation of this file.
1 
19 
20 #include <algorithm>
21 #include <limits>
22 
24 
30 }
31 
32 bool L1GlobalTriggerObjectMaps::algorithmExists(int algorithmBitNumber) const {
33  std::vector<AlgorithmResult>::const_iterator i =
34  std::lower_bound(m_algorithmResults.begin(),
35  m_algorithmResults.end(),
36  AlgorithmResult(0, algorithmBitNumber, false));
37  if (i == m_algorithmResults.end() || i->algorithmBitNumber() != algorithmBitNumber) {
38  return false;
39  }
40  return true;
41 }
42 
43 bool L1GlobalTriggerObjectMaps::algorithmResult(int algorithmBitNumber) const {
44  std::vector<AlgorithmResult>::const_iterator i =
45  std::lower_bound(m_algorithmResults.begin(),
46  m_algorithmResults.end(),
47  AlgorithmResult(0, algorithmBitNumber, false));
48  if (i == m_algorithmResults.end() || i->algorithmBitNumber() != algorithmBitNumber) {
49  cms::Exception ex("L1GlobalTrigger");
50  ex << "algorithmBitNumber not found";
51  ex.addContext("Calling L1GlobalTriggerObjectMaps::algorithmResult");
52  throw ex;
53  }
54  return i->algorithmResult();
55 }
56 
58 updateOperandTokenVector(int algorithmBitNumber,
59  std::vector<L1GtLogicParser::OperandToken>& operandTokenVector) const {
60  unsigned startIndex = 0;
61  unsigned endIndex = 0;
62  getStartEndIndex(algorithmBitNumber, startIndex, endIndex);
63 
64  unsigned length = endIndex - startIndex;
65  if (length != operandTokenVector.size()) {
66  cms::Exception ex("L1GlobalTrigger");
67  ex << "operand token vector size does not match number of conditions";
68  ex.addContext("Calling L1GlobalTriggerObjectMaps::updateOperandTokenVector");
69  throw ex;
70  }
71 
72  for (unsigned i = 0; i < length; ++i) {
73  operandTokenVector[i].tokenResult = m_conditionResults[startIndex + i].conditionResult();
74  }
75 }
76 
78 getAlgorithmBitNumbers(std::vector<int>& algorithmBitNumbers) const {
79  algorithmBitNumbers.clear();
80  for (std::vector<AlgorithmResult>::const_iterator i = m_algorithmResults.begin(),
81  iEnd = m_algorithmResults.end(); i != iEnd; ++i) {
82  algorithmBitNumbers.push_back(i->algorithmBitNumber());
83  }
84 }
85 
87 getNumberOfConditions(int algorithmBitNumber) const {
88 
89  unsigned startIndex = 0;
90  unsigned endIndex = 0;
91  getStartEndIndex(algorithmBitNumber, startIndex, endIndex);
92  return endIndex - startIndex;
93 }
94 
96 getConditionsInAlgorithm(int algorithmBitNumber) const {
97  unsigned startIndex = 0;
98  unsigned endIndex = 0;
99  getStartEndIndex(algorithmBitNumber, startIndex, endIndex);
100  return ConditionsInAlgorithm(&m_conditionResults[startIndex], endIndex - startIndex);
101 }
102 
104 getCombinationsInCondition(int algorithmBitNumber,
105  unsigned conditionNumber) const {
106  unsigned startIndex = 0;
107  unsigned endIndex = 0;
108  getStartEndIndex(algorithmBitNumber, startIndex, endIndex);
109 
110  if (endIndex <= startIndex + conditionNumber) {
111  cms::Exception ex("L1GlobalTrigger");
112  ex << "Condition number is out of range";
113  ex.addContext("Calling L1GlobalTriggerObjectMaps::getCombinationsInCondition");
114  throw ex;
115  }
116 
117  unsigned endObjectIndex = m_combinations.size();
118  unsigned nextConditionIndex = startIndex + conditionNumber + 1U;
119  if (nextConditionIndex < m_conditionResults.size()) {
120  endObjectIndex = m_conditionResults[nextConditionIndex].startIndexOfCombinations();
121  }
122  unsigned beginObjectIndex = m_conditionResults[startIndex + conditionNumber].startIndexOfCombinations();
123  unsigned short nObjectsPerCombination = m_conditionResults[startIndex + conditionNumber].nObjectsPerCombination();
124 
125  if (endObjectIndex == beginObjectIndex) {
126  return CombinationsInCondition(0, 0, 0);
127  }
128  if (endObjectIndex < beginObjectIndex ||
129  m_combinations.size() < endObjectIndex ||
130  nObjectsPerCombination == 0 ||
131  (endObjectIndex - beginObjectIndex) % nObjectsPerCombination != 0) {
132  cms::Exception ex("L1GlobalTrigger");
133  ex << "Indexes to combinations are invalid";
134  ex.addContext("Calling L1GlobalTriggerObjectMaps::getCombinationsInCondition");
135  throw ex;
136  }
137  return CombinationsInCondition(&m_combinations[beginObjectIndex],
138  (endObjectIndex - beginObjectIndex) / nObjectsPerCombination,
139  nObjectsPerCombination);
140 }
141 
144  m_algorithmResults.reserve(n);
145 }
146 
148 pushBackAlgorithm(unsigned startIndexOfConditions,
149  int algorithmBitNumber,
150  bool algorithmResult) {
151  m_algorithmResults.push_back(AlgorithmResult(startIndexOfConditions,
152  algorithmBitNumber,
153  algorithmResult));
154 }
155 
157  // None of these checks should ever fail unless there
158  // is a bug in the code filling this object
159  for (std::vector<AlgorithmResult>::const_iterator i = m_algorithmResults.begin(),
160  iEnd = m_algorithmResults.end(); i != iEnd; ++i) {
161  std::vector<AlgorithmResult>::const_iterator j = i;
162  ++j;
163  if (j != iEnd && !(*i < *j)) {
164  cms::Exception ex("L1GlobalTrigger");
165  ex << "AlgorithmResults should be sorted in increasing order of bit number with no duplicates. It is not.";
166  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
167  throw ex;
168  }
169  unsigned endIndex =
170  (j != iEnd) ? j->startIndexOfConditions() : m_conditionResults.size();
171 
172  if (endIndex < i->startIndexOfConditions()) {
173  cms::Exception ex("L1GlobalTrigger");
174  ex << "startIndexOfConditions decreases or exceeds the size of m_conditionResults";
175  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
176  throw ex;
177  }
178  }
179  for (std::vector<ConditionResult>::const_iterator i = m_conditionResults.begin(),
180  iEnd = m_conditionResults.end(); i != iEnd; ++i) {
181  std::vector<ConditionResult>::const_iterator j = i;
182  ++j;
183  unsigned endIndex =
184  (j != iEnd) ? j->startIndexOfCombinations() : m_combinations.size();
185 
186  if (endIndex < i->startIndexOfCombinations()) {
187  cms::Exception ex("L1GlobalTrigger");
188  ex << "startIndexOfCombinations decreases or exceeds the size of m_conditionResults";
189  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
190  throw ex;
191  }
192  unsigned length = endIndex - i->startIndexOfCombinations();
193  if (length == 0U) {
194  if (i->nObjectsPerCombination() != 0U) {
195  cms::Exception ex("L1GlobalTrigger");
196  ex << "Length is zero and nObjectsInCombination is not zero";
197  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
198  throw ex;
199  }
200  } else {
201  if (i->nObjectsPerCombination() == 0 || length % i->nObjectsPerCombination() != 0) {
202  cms::Exception ex("L1GlobalTrigger");
203  ex << "Size indicated by startIndexOfCombinations is not a multiple of nObjectsInCombination";
204  ex.addContext("Calling L1GlobalTriggerObjectMaps::consistencyCheck");
205  throw ex;
206  }
207  }
208  }
209 }
210 
213  m_conditionResults.reserve(n);
214 }
215 
217 pushBackCondition(unsigned startIndexOfCombinations,
218  unsigned short nObjectsPerCombination,
219  bool conditionResult) {
220  m_conditionResults.push_back(ConditionResult(startIndexOfCombinations,
221  nObjectsPerCombination,
222  conditionResult));
223 }
224 
227  m_combinations.reserve(n);
228 }
229 
231 pushBackObjectIndex(unsigned char objectIndex) {
232  m_combinations.push_back(objectIndex);
233 }
234 
237  m_namesParameterSetID = psetID;
238 }
239 
242  m_startIndexOfConditions(0),
243  m_algorithmBitNumber(0),
244  m_algorithmResult(false) {
245 }
246 
248 AlgorithmResult(unsigned startIndexOfConditions,
249  int algorithmBitNumber,
250  bool algorithmResult) :
251  m_startIndexOfConditions(startIndexOfConditions),
252  m_algorithmResult(algorithmResult) {
253 
254  // We made the decision to try to save space in the data format
255  // and fit this object into 8 bytes by making the persistent
256  // algorithmBitNumber a short. This creates something very
257  // ugly below. In practice the range should never be exceeded.
258  // In fact it is currently always supposed to be less than 128.
259  // I hope this never comes back to haunt us for some unexpected reason.
260  // I cringe when I look at it, but cannot think of any practical
261  // harm ... It is probably a real bug if anyone ever
262  // tries to shove a big int into here.
263  if (algorithmBitNumber < std::numeric_limits<short>::min() ||
264  algorithmBitNumber > std::numeric_limits<short>::max()) {
265  cms::Exception ex("L1GlobalTrigger");
266  ex << "algorithmBitNumber out of range of a short int";
267  ex.addContext("Calling L1GlobalTriggerObjectMaps::AlgorithmResult::AlgorithmResult");
268  throw ex;
269  }
270  m_algorithmBitNumber = static_cast<short>(algorithmBitNumber);
271 }
272 
275  m_startIndexOfCombinations(0),
276  m_nObjectsPerCombination(0),
277  m_conditionResult(false) {
278 }
279 
281 ConditionResult(unsigned startIndexOfCombinations,
282  unsigned short nObjectsPerCombination,
283  bool conditionResult) :
284  m_startIndexOfCombinations(startIndexOfCombinations),
285  m_nObjectsPerCombination(nObjectsPerCombination),
286  m_conditionResult(conditionResult) {
287 }
288 
290 ConditionsInAlgorithm(ConditionResult const* conditionResults,
291  unsigned nConditions) :
292  m_conditionResults(conditionResults),
293  m_nConditions(nConditions) {
294 }
295 
297 getConditionResult(unsigned condition) const {
298  if (condition >= m_nConditions) {
299  cms::Exception ex("L1GlobalTrigger");
300  ex << "argument out of range";
301  ex.addContext("Calling L1GlobalTriggerObjectMaps::ConditionsInAlgorithm::getConditionResult");
302  throw ex;
303  }
304  return (m_conditionResults + condition)->conditionResult();
305 }
306 
308 CombinationsInCondition(unsigned char const* startOfObjectIndexes,
309  unsigned nCombinations,
310  unsigned short nObjectsPerCombination) :
311  m_startOfObjectIndexes(startOfObjectIndexes),
312  m_nCombinations(nCombinations),
313  m_nObjectsPerCombination(nObjectsPerCombination) {
314 }
315 
317 getObjectIndex(unsigned combination,
318  unsigned object) const {
319  if (combination >= m_nCombinations ||
320  object >= m_nObjectsPerCombination) {
321  cms::Exception ex("L1GlobalTrigger");
322  ex << "arguments out of range";
323  ex.addContext("Calling L1GlobalTriggerObjectMaps::CombinationsInCondition::getObjectIndex");
324  throw ex;
325  }
326  return m_startOfObjectIndexes[combination * m_nObjectsPerCombination + object];
327 }
328 
330 getStartEndIndex(int algorithmBitNumber, unsigned& startIndex, unsigned& endIndex) const {
331  std::vector<AlgorithmResult>::const_iterator iAlgo =
332  std::lower_bound(m_algorithmResults.begin(),
333  m_algorithmResults.end(),
334  AlgorithmResult(0, algorithmBitNumber, false));
335 
336  if (iAlgo == m_algorithmResults.end() || iAlgo->algorithmBitNumber() != algorithmBitNumber) {
337  cms::Exception ex("L1GlobalTrigger");
338  ex << "algorithmBitNumber not found";
339  ex.addContext("Calling L1GlobalTriggerObjectMaps::getStartEndIndex");
340  throw ex;
341  }
342 
343  startIndex = iAlgo->startIndexOfConditions();
344  ++iAlgo;
345  endIndex = (iAlgo != m_algorithmResults.end()) ?
346  iAlgo->startIndexOfConditions() : m_conditionResults.size();
347 
348  if (endIndex < startIndex || m_conditionResults.size() < endIndex) {
349  cms::Exception ex("L1GlobalTrigger");
350  ex << "index out of order or out of range";
351  ex.addContext("Calling L1GlobalTriggerObjectMaps::getStartEndIndex");
352  throw ex;
353  }
354 }
unsigned char getObjectIndex(unsigned combination, unsigned object) const
int i
Definition: DBlmapReader.cc:9
void pushBackCondition(unsigned startIndexOfCombinations, unsigned short nObjectsPerCombination, bool conditionResult)
void pushBackObjectIndex(unsigned char objectIndex)
ConditionsInAlgorithm(ConditionResult const *conditionResults, unsigned nConditions)
edm::ParameterSetID m_namesParameterSetID
#define min(a, b)
Definition: mlp_lapack.h:161
void swap(Hash< I > &other)
Definition: Hash.h:202
void getAlgorithmBitNumbers(std::vector< int > &algorithmBitNumbers) const
Fills the vector with all the algorithm bit numbers.
bool algorithmExists(int algorithmBitNumber) const
Returns true if there is an entry for this algorithm bit number.
void swap(L1GlobalTriggerObjectMaps &rh)
std::vector< AlgorithmResult > m_algorithmResults
const T & max(const T &a, const T &b)
int j
Definition: DBlmapReader.cc:9
std::vector< unsigned char > m_combinations
std::vector< ConditionResult > m_conditionResults
CombinationsInCondition(unsigned char const *startOfObjectIndexes, unsigned nCombinations, unsigned short nObjectsPerCombination)
void updateOperandTokenVector(int algorithmBitNumber, std::vector< L1GtLogicParser::OperandToken > &operandTokenVector) const
Update the condition result in the operandTokenVector.
void pushBackAlgorithm(unsigned startIndexOfConditions, int algorithmBitNumber, bool algorithmResult)
CombinationsInCondition getCombinationsInCondition(int algorithmBitNumber, unsigned conditionNumber) const
unsigned getNumberOfConditions(int algorithmBitNumber) const
Number of conditions associated with an algorithm.
void setNamesParameterSetID(edm::ParameterSetID const &psetID)
void addContext(std::string const &context)
Definition: Exception.cc:227
list object
Definition: dbtoconf.py:77
ConditionsInAlgorithm getConditionsInAlgorithm(int algorithmBitNumber) const
bool algorithmResult(int algorithmBitNumber) const
Returns whether an algorithm trigger passed or failed.
void getStartEndIndex(int algorithmBitNumber, unsigned &startIndex, unsigned &endIndex) const