CMS 3D CMS Logo

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