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 
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 //
37 
39 
42 
43 
46  m_algoResult(false),
47  m_logicalExpression(alg.algoLogicalExpression()),
48  m_rpnVector(alg.algoRpnVector()){
49 
50  // the rest is properly initialized by default
51 
52 }
53 
54 
55 // methods
56 
59  const std::vector<ConditionEvaluationMap>& conditionResultMaps) {
60 
61  // set result to false if there is no expression
62  if (m_rpnVector.empty() ) {
63  m_algoResult = false;
64 
65  // it should never be happen
66  throw cms::Exception("FailModule")
67  << "\nEmpty RPN vector for the logical expression = "
69  << std::endl;
70 
71  }
72 
73  // reserve memory
74  int rpnVectorSize = m_rpnVector.size();
75 
76  m_algoCombinationVector.reserve(rpnVectorSize);
77  m_operandTokenVector.reserve(rpnVectorSize);
78 
79  // stack containing temporary results
80  // FIXME we shall find a better solution than static
81  std::stack<bool, std::vector<bool> > resultStack;
82  bool b1, b2;
83 
84  int opNumber = 0;
85 
86  for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
87 
88  //LogTrace("L1GlobalTrigger")
89  //<< "\nit->operation = " << it->operation
90  //<< "\nit->operand = '" << it->operand << "'\n"
91  //<< std::endl;
92 
93  switch (it->operation) {
94 
96 
97  CItEvalMap itCond = (conditionResultMaps.at(chipNumber)).find(it->operand);
98  if (itCond != (conditionResultMaps[chipNumber]).end()) {
99 
100  if (0 == itCond->second) {
101  // it should never be happen, only valid conditions are in the maps
102  throw cms::Exception("FailModule") << "\nCondition "
103  << (it->operand)
104  << " NULL pointer found in condition map"
105  << std::endl;
106  }
107 
108  //
109  bool condResult = (itCond->second)->condLastResult();
110 
111  resultStack.push(condResult);
112 
113  // only conditions are added to /counted in m_operandTokenVector
114  // opNumber is the index of the condition in the logical expression
115  OperandToken opToken;
116  opToken.tokenName = it->operand;
117  opToken.tokenNumber = opNumber;
118  opToken.tokenResult = condResult;
119 
120  m_operandTokenVector.push_back(opToken);
121  opNumber++;
122 
123  //
124  CombinationsInCond const & combInCondition = (itCond->second)->getCombinationsInCond();
125  m_algoCombinationVector.push_back(combInCondition);
126 
127  }
128  else {
129 
130  // it should never be happen, all conditions are in the maps
131  throw cms::Exception("FailModule")
132  << "\nCondition " << (it->operand) << " not found in condition map"
133  << std::endl;
134 
135  }
136 
137  }
138 
139  break;
141  b1 = resultStack.top();
142  resultStack.pop(); // pop the top
143  resultStack.push(!b1); // and push the result
144  }
145 
146  break;
147  case L1GtLogicParser::OP_OR: {
148  b1 = resultStack.top();
149  resultStack.pop();
150  b2 = resultStack.top();
151  resultStack.pop();
152  resultStack.push(b1 || b2);
153  }
154 
155  break;
157  b1 = resultStack.top();
158  resultStack.pop();
159  b2 = resultStack.top();
160  resultStack.pop();
161  resultStack.push(b1 && b2);
162  }
163 
164  break;
165  default: {
166  // should not arrive here
167  }
168 
169  break;
170  }
171 
172  }
173 
174  // get the result in the top of the stack
175 
176  m_algoResult = resultStack.top();
177 
178  // clear resultStack not needed since it is now a function temporary
179 
180 }
181 
182 // print algorithm evaluation
183 void L1GtAlgorithmEvaluation::print(std::ostream& myCout) const {
184 
185  myCout << std::endl;
186 
187  myCout << " Algorithm result: " << m_algoResult << std::endl;
188 
189  myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
190 
191  int operandTokenVectorSize = m_operandTokenVector.size();
192 
193  myCout << " Operand token vector size: " << operandTokenVectorSize;
194 
195  if (operandTokenVectorSize == 0) {
196  myCout << " - not properly initialized! " << std::endl;
197  }
198  else {
199  myCout << std::endl;
200 
201  for (int i = 0; i < operandTokenVectorSize; ++i) {
202 
203  myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t"
204  << std::setw(25) << (m_operandTokenVector[i]).tokenName << "\t"
205  << (m_operandTokenVector[i]).tokenResult
206  << std::endl;
207 
208  }
209 
210  }
211 
212  myCout << std::endl;
213 }
214 
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
volatile std::atomic< bool > shutdown_flag false
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