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