CMS 3D CMS Logo

L1GtAlgorithmEvaluation.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <string>
20 
21 #include <queue>
22 #include <stack>
23 #include <vector>
24 
25 #include <iomanip>
26 #include <iostream>
27 
28 #include <boost/algorithm/string.hpp>
29 
30 // user include files
31 
32 //
35 
37 
40 
43  : m_algoResult(false), m_logicalExpression(alg.algoLogicalExpression()), m_rpnVector(alg.algoRpnVector()) {
44  // the rest is properly initialized by default
45 }
46 
47 // methods
48 
51  const std::vector<ConditionEvaluationMap> &conditionResultMaps) {
52  // set result to false if there is no expression
53  if (m_rpnVector.empty()) {
54  m_algoResult = false;
55 
56  // it should never be happen
57  throw cms::Exception("FailModule") << "\nEmpty RPN vector for the logical expression = " << m_logicalExpression
58  << std::endl;
59  }
60 
61  // reserve memory
62  int rpnVectorSize = m_rpnVector.size();
63 
64  m_algoCombinationVector.reserve(rpnVectorSize);
65  m_operandTokenVector.reserve(rpnVectorSize);
66 
67  // stack containing temporary results
68  // FIXME we shall find a better solution than static
69  std::stack<bool, std::vector<bool>> resultStack;
70  bool b1, b2;
71 
72  int opNumber = 0;
73 
74  for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
75  // LogTrace("L1GlobalTrigger")
76  //<< "\nit->operation = " << it->operation
77  //<< "\nit->operand = '" << it->operand << "'\n"
78  //<< std::endl;
79 
80  switch (it->operation) {
82  CItEvalMap itCond = (conditionResultMaps.at(chipNumber)).find(it->operand);
83  if (itCond != (conditionResultMaps[chipNumber]).end()) {
84  if (nullptr == itCond->second) {
85  // it should never be happen, only valid conditions are in the maps
86  throw cms::Exception("FailModule")
87  << "\nCondition " << (it->operand) << " NULL pointer found in condition map" << std::endl;
88  }
89 
90  //
91  bool condResult = (itCond->second)->condLastResult();
92 
93  resultStack.push(condResult);
94 
95  // only conditions are added to /counted in m_operandTokenVector
96  // opNumber is the index of the condition in the logical expression
97  OperandToken opToken;
98  opToken.tokenName = it->operand;
99  opToken.tokenNumber = opNumber;
100  opToken.tokenResult = condResult;
101 
102  m_operandTokenVector.push_back(opToken);
103  opNumber++;
104 
105  //
106  CombinationsInCond const &combInCondition = (itCond->second)->getCombinationsInCond();
107  m_algoCombinationVector.push_back(combInCondition);
108 
109  } else {
110  // it should never be happen, all conditions are in the maps
111  throw cms::Exception("FailModule")
112  << "\nCondition " << (it->operand) << " not found in condition map" << std::endl;
113  }
114 
115  }
116 
117  break;
119  b1 = resultStack.top();
120  resultStack.pop(); // pop the top
121  resultStack.push(!b1); // and push the result
122  }
123 
124  break;
125  case L1GtLogicParser::OP_OR: {
126  b1 = resultStack.top();
127  resultStack.pop();
128  b2 = resultStack.top();
129  resultStack.pop();
130  resultStack.push(b1 || b2);
131  }
132 
133  break;
135  b1 = resultStack.top();
136  resultStack.pop();
137  b2 = resultStack.top();
138  resultStack.pop();
139  resultStack.push(b1 && b2);
140  }
141 
142  break;
143  default: {
144  // should not arrive here
145  }
146 
147  break;
148  }
149  }
150 
151  // get the result in the top of the stack
152 
153  m_algoResult = resultStack.top();
154 
155  // clear resultStack not needed since it is now a function temporary
156 }
157 
158 // print algorithm evaluation
159 void L1GtAlgorithmEvaluation::print(std::ostream &myCout) const {
160  myCout << std::endl;
161 
162  myCout << " Algorithm result: " << m_algoResult << std::endl;
163 
164  myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
165 
166  int operandTokenVectorSize = m_operandTokenVector.size();
167 
168  myCout << " Operand token vector size: " << operandTokenVectorSize;
169 
170  if (operandTokenVectorSize == 0) {
171  myCout << " - not properly initialized! " << std::endl;
172  } else {
173  myCout << std::endl;
174 
175  for (int i = 0; i < operandTokenVectorSize; ++i) {
176  myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t" << std::setw(25)
177  << (m_operandTokenVector[i]).tokenName << "\t" << (m_operandTokenVector[i]).tokenResult << std::endl;
178  }
179  }
180 
181  myCout << std::endl;
182 }
bool m_algoResult
algorithm result
std::vector< OperandToken > m_operandTokenVector
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void print(std::ostream &myCout) const
std::vector< CombinationsInCond > m_algoCombinationVector
L1GtAlgorithmEvaluation(const L1GtAlgorithm &)
constructor
static constexpr float b2
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
std::string const & m_logicalExpression
ConditionEvaluationMap::const_iterator CItEvalMap
static constexpr float b1
void evaluateAlgorithm(const int chipNumber, const std::vector< ConditionEvaluationMap > &)
evaluate an algorithm