CMS 3D CMS Logo

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 #include <boost/algorithm/string.hpp>
29 #include <ext/hash_map>
30 
31 // user include files
32 
33 
34 //
36 
38 
41 
42 
45  m_algoResult(false),
46  m_logicalExpression(alg.algoLogicalExpression()),
47  m_rpnVector(alg.algoRpnVector()){
48 
49  // the rest is properly initialized by default
50 
51 }
52 
53 
54 // methods
55 
58  const std::vector<ConditionEvaluationMap>& conditionResultMaps) {
59 
60  // set result to false if there is no expression
61  if (m_rpnVector.empty() ) {
62  m_algoResult = false;
63 
64  // it should never be happen
65  throw cms::Exception("FailModule")
66  << "\nEmpty RPN vector for the logical expression = "
68  << std::endl;
69 
70  }
71 
72  // reserve memory
73  int rpnVectorSize = m_rpnVector.size();
74 
75  m_algoCombinationVector.reserve(rpnVectorSize);
76  m_operandTokenVector.reserve(rpnVectorSize);
77 
78  // stack containing temporary results
79  std::stack<bool, std::vector<bool> > resultStack;
80  bool b1, b2;
81 
82  int opNumber = 0;
83 
84  for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
85 
86  //LogTrace("L1TGlobal")
87  //<< "\nit->operation = " << it->operation
88  //<< "\nit->operand = '" << it->operand << "'\n"
89  //<< std::endl;
90 
91  switch (it->operation) {
92 
94 
95  CItEvalMap itCond = (conditionResultMaps.at(chipNumber)).find(it->operand);
96  if (itCond != (conditionResultMaps[chipNumber]).end()) {
97 
98  if (0 == itCond->second) {
99  // it should never be happen, only valid conditions are in the maps
100  throw cms::Exception("FailModule") << "\nCondition "
101  << (it->operand)
102  << " NULL pointer found in condition map"
103  << std::endl;
104  }
105 
106  //
107  bool condResult = (itCond->second)->condLastResult();
108 
109  resultStack.push(condResult);
110 
111  // only conditions are added to /counted in m_operandTokenVector
112  // opNumber is the index of the condition in the logical expression
113  OperandToken opToken;
114  opToken.tokenName = it->operand;
115  opToken.tokenNumber = opNumber;
116  opToken.tokenResult = condResult;
117 
118  m_operandTokenVector.push_back(opToken);
119  opNumber++;
120 
121  //
122  CombinationsInCond const & combInCondition = (itCond->second)->getCombinationsInCond();
123  m_algoCombinationVector.push_back(combInCondition);
124 
125  }
126  else {
127 
128  // it should never be happen, all conditions are in the maps
129  throw cms::Exception("FailModule")
130  << "\nCondition " << (it->operand) << " not found in condition map"
131  << std::endl;
132 
133  }
134 
135  }
136 
137  break;
139  b1 = resultStack.top();
140  resultStack.pop(); // pop the top
141  resultStack.push(!b1); // and push the result
142  }
143 
144  break;
146  b1 = resultStack.top();
147  resultStack.pop();
148  b2 = resultStack.top();
149  resultStack.pop();
150  resultStack.push(b1 || b2);
151  }
152 
153  break;
155  b1 = resultStack.top();
156  resultStack.pop();
157  b2 = resultStack.top();
158  resultStack.pop();
159  resultStack.push(b1 && b2);
160  }
161 
162  break;
163  default: {
164  // should not arrive here
165  }
166 
167  break;
168  }
169 
170  }
171 
172  // get the result in the top of the stack
173  m_algoResult = resultStack.top();
174 }
175 
176 // print algorithm evaluation
177 void l1t::AlgorithmEvaluation::print(std::ostream& myCout) const {
178 
179  myCout << std::endl;
180 
181  myCout << " Algorithm result: " << m_algoResult << std::endl;
182 
183  myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
184 
185  int operandTokenVectorSize = m_operandTokenVector.size();
186 
187  myCout << " Operand token vector size: " << operandTokenVectorSize;
188 
189  if (operandTokenVectorSize == 0) {
190  myCout << " - not properly initialized! " << std::endl;
191  }
192  else {
193  myCout << std::endl;
194 
195  for (int i = 0; i < operandTokenVectorSize; ++i) {
196 
197  myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t"
198  << std::setw(25) << (m_operandTokenVector[i]).tokenName << "\t"
199  << (m_operandTokenVector[i]).tokenResult
200  << std::endl;
201 
202  }
203 
204  }
205 
206  myCout << std::endl;
207 }
208 
ConditionEvaluationMap::const_iterator CItEvalMap
void print(std::ostream &myCout) const
std::vector< CombinationsInCond > m_algoCombinationVector
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::string const & m_logicalExpression
AlgorithmEvaluation(const GlobalAlgorithm &)
constructor
void evaluateAlgorithm(const int chipNumber, const std::vector< ConditionEvaluationMap > &)
evaluate an algorithm
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
bool m_algoResult
algorithm result
std::vector< OperandToken > m_operandTokenVector