CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GtAlgorithmEvaluation.cc
Go to the documentation of this file.
1 
17 // this class header
19 
20 // system include files
21 #include <string>
22 
23 #include <stack>
24 #include <queue>
25 #include <vector>
26 
27 #include <iostream>
28 #include <iomanip>
29 
30 #include <boost/algorithm/string.hpp>
31 #include <ext/hash_map>
32 
33 // user include files
34 
35 
36 //
39 
41 
44 
45 
48  m_algoResult(false),
49  m_logicalExpression(alg.algoLogicalExpression()),
50  m_rpnVector(alg.algoRpnVector()){
51 
52  // the rest is properly initialized by default
53 
54 }
55 
56 
57 // methods
58 
61  const std::vector<ConditionEvaluationMap>& conditionResultMaps) {
62 
63  // set result to false if there is no expression
64  if (m_rpnVector.empty() ) {
65  m_algoResult = false;
66 
67  // it should never be happen
68  throw cms::Exception("FailModule")
69  << "\nEmpty RPN vector for the logical expression = "
71  << std::endl;
72 
73  }
74 
75  // reserve memory
76  int rpnVectorSize = m_rpnVector.size();
77 
78  m_algoCombinationVector.reserve(rpnVectorSize);
79  m_operandTokenVector.reserve(rpnVectorSize);
80 
81  // stack containing temporary results
82  // FIXME we shall find a better solution than static
83  static std::stack<bool, std::vector<bool> > resultStack;
84  bool b1, b2;
85 
86  int opNumber = 0;
87 
88  for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
89 
90  //LogTrace("L1GlobalTrigger")
91  //<< "\nit->operation = " << it->operation
92  //<< "\nit->operand = '" << it->operand << "'\n"
93  //<< std::endl;
94 
95  switch (it->operation) {
96 
98 
99  CItEvalMap itCond = (conditionResultMaps.at(chipNumber)).find(it->operand);
100  if (itCond != (conditionResultMaps[chipNumber]).end()) {
101 
102  if (0 == itCond->second) {
103  // it should never be happen, only valid conditions are in the maps
104  throw cms::Exception("FailModule") << "\nCondition "
105  << (it->operand)
106  << " NULL pointer found in condition map"
107  << std::endl;
108  }
109 
110  //
111  bool condResult = (itCond->second)->condLastResult();
112 
113  resultStack.push(condResult);
114 
115  // only conditions are added to /counted in m_operandTokenVector
116  // opNumber is the index of the condition in the logical expression
117  OperandToken opToken;
118  opToken.tokenName = it->operand;
119  opToken.tokenNumber = opNumber;
120  opToken.tokenResult = condResult;
121 
122  m_operandTokenVector.push_back(opToken);
123  opNumber++;
124 
125  //
126  CombinationsInCond const & combInCondition = (itCond->second)->getCombinationsInCond();
127  m_algoCombinationVector.push_back(combInCondition);
128 
129  }
130  else {
131 
132  // it should never be happen, all conditions are in the maps
133  throw cms::Exception("FailModule")
134  << "\nCondition " << (it->operand) << " not found in condition map"
135  << std::endl;
136 
137  }
138 
139  }
140 
141  break;
143  b1 = resultStack.top();
144  resultStack.pop(); // pop the top
145  resultStack.push(!b1); // and push the result
146  }
147 
148  break;
149  case L1GtLogicParser::OP_OR: {
150  b1 = resultStack.top();
151  resultStack.pop();
152  b2 = resultStack.top();
153  resultStack.pop();
154  resultStack.push(b1 || b2);
155  }
156 
157  break;
159  b1 = resultStack.top();
160  resultStack.pop();
161  b2 = resultStack.top();
162  resultStack.pop();
163  resultStack.push(b1 && b2);
164  }
165 
166  break;
167  default: {
168  // should not arrive here
169  }
170 
171  break;
172  }
173 
174  }
175 
176  // get the result in the top of the stack
177 
178  m_algoResult = resultStack.top();
179 
180  // clear resultStack
181  while(!resultStack.empty()) resultStack.pop();
182 
183 }
184 
185 // print algorithm evaluation
186 void L1GtAlgorithmEvaluation::print(std::ostream& myCout) const {
187 
188  myCout << std::endl;
189 
190  myCout << " Algorithm result: " << m_algoResult << std::endl;
191 
192  myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
193 
194  int operandTokenVectorSize = m_operandTokenVector.size();
195 
196  myCout << " Operand token vector size: " << operandTokenVectorSize;
197 
198  if (operandTokenVectorSize == 0) {
199  myCout << " - not properly initialized! " << std::endl;
200  }
201  else {
202  myCout << std::endl;
203 
204  for (int i = 0; i < operandTokenVectorSize; ++i) {
205 
206  myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t"
207  << std::setw(25) << (m_operandTokenVector[i]).tokenName << "\t"
208  << (m_operandTokenVector[i]).tokenResult
209  << std::endl;
210 
211  }
212 
213  }
214 
215  myCout << std::endl;
216 }
217 
int i
Definition: DBlmapReader.cc:9
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:7
std::vector< CombinationsInCond > m_algoCombinationVector
void print(std::ostream &myCout) const
L1GtAlgorithmEvaluation(const L1GtAlgorithm &)
constructor
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
std::string const & m_logicalExpression
ConditionEvaluationMap::const_iterator CItEvalMap
void evaluateAlgorithm(const int chipNumber, const std::vector< ConditionEvaluationMap > &)
evaluate an algorithm