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 //
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  std::stack<bool, std::vector<bool> > resultStack;
69  bool b1, b2;
70 
71  int opNumber = 0;
72 
73  for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
74  //LogTrace("L1TGlobal")
75  //<< "\nit->operation = " << it->operation
76  //<< "\nit->operand = '" << it->operand << "'\n"
77  //<< std::endl;
78 
79  switch (it->operation) {
81  CItEvalMap itCond = (conditionResultMaps.at(chipNumber)).find(it->operand);
82  if (itCond != (conditionResultMaps[chipNumber]).end()) {
83  if (nullptr == itCond->second) {
84  // it should never be happen, only valid conditions are in the maps
85  throw cms::Exception("FailModule")
86  << "\nCondition " << (it->operand) << " NULL pointer found in condition map" << std::endl;
87  }
88 
89  //
90  bool condResult = (itCond->second)->condLastResult();
91 
92  resultStack.push(condResult);
93 
94  // only conditions are added to /counted in m_operandTokenVector
95  // opNumber is the index of the condition in the logical expression
96  OperandToken opToken;
97  opToken.tokenName = it->operand;
98  opToken.tokenNumber = opNumber;
99  opToken.tokenResult = condResult;
100 
101  m_operandTokenVector.push_back(opToken);
102  opNumber++;
103 
104  //
105  CombinationsInCond const& combInCondition = (itCond->second)->getCombinationsInCond();
106  m_algoCombinationVector.push_back(combInCondition);
107 
108  } else {
109  // it should never be happen, all conditions are in the maps
110  throw cms::Exception("FailModule")
111  << "\nCondition " << (it->operand) << " not found in condition map" << std::endl;
112  }
113 
114  }
115 
116  break;
118  b1 = resultStack.top();
119  resultStack.pop(); // pop the top
120  resultStack.push(!b1); // and push the result
121  }
122 
123  break;
125  b1 = resultStack.top();
126  resultStack.pop();
127  b2 = resultStack.top();
128  resultStack.pop();
129  resultStack.push(b1 || b2);
130  }
131 
132  break;
134  b1 = resultStack.top();
135  resultStack.pop();
136  b2 = resultStack.top();
137  resultStack.pop();
138  resultStack.push(b1 && b2);
139  }
140 
141  break;
143  b1 = resultStack.top();
144  resultStack.pop();
145  b2 = resultStack.top();
146  resultStack.pop();
147  resultStack.push(b1 ^ b2);
148  }
149 
150  break;
151  default: {
152  // should not arrive here
153  }
154 
155  break;
156  }
157  }
158 
159  // get the result in the top of the stack
160  m_algoResult = resultStack.top();
161 }
162 
163 // print algorithm evaluation
164 void l1t::AlgorithmEvaluation::print(std::ostream& myCout) const {
165  myCout << std::endl;
166 
167  myCout << " Algorithm result: " << m_algoResult << std::endl;
168 
169  myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
170 
171  int operandTokenVectorSize = m_operandTokenVector.size();
172 
173  myCout << " Operand token vector size: " << operandTokenVectorSize;
174 
175  if (operandTokenVectorSize == 0) {
176  myCout << " - not properly initialized! " << std::endl;
177  } else {
178  myCout << std::endl;
179 
180  for (int i = 0; i < operandTokenVectorSize; ++i) {
181  myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t" << std::setw(25)
182  << (m_operandTokenVector[i]).tokenName << "\t" << (m_operandTokenVector[i]).tokenResult << std::endl;
183  }
184  }
185 
186  myCout << std::endl;
187 }
l1t::AlgorithmEvaluation::AlgorithmEvaluation
AlgorithmEvaluation(const GlobalAlgorithm &)
constructor
Definition: AlgorithmEvaluation.cc:42
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
GlobalLogicParser::OP_XOR
Definition: GlobalLogicParser.h:34
CombinationsInCond
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
Definition: L1GlobalTriggerObjectMapFwd.h:32
b2
static constexpr float b2
Definition: L1EGammaCrystalsEmulatorProducer.cc:83
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
b1
static constexpr float b1
Definition: L1EGammaCrystalsEmulatorProducer.cc:83
GlobalAlgorithm.h
GlobalAlgorithm
Definition: GlobalAlgorithm.h:32
GlobalLogicParser::OP_OPERAND
Definition: GlobalLogicParser.h:31
GlobalLogicParser::OP_AND
Definition: GlobalLogicParser.h:28
GlobalLogicParser::OperandToken::tokenNumber
int tokenNumber
Definition: GlobalLogicParser.h:21
GlobalLogicParser::OperandToken::tokenResult
bool tokenResult
Definition: GlobalLogicParser.h:22
ConditionEvaluation.h
l1t::AlgorithmEvaluation::evaluateAlgorithm
void evaluateAlgorithm(const int chipNumber, const std::vector< ConditionEvaluationMap > &)
evaluate an algorithm
Definition: AlgorithmEvaluation.cc:50
GlobalLogicParser::OP_NOT
Definition: GlobalLogicParser.h:30
l1t::AlgorithmEvaluation::CItEvalMap
ConditionEvaluationMap::const_iterator CItEvalMap
Definition: AlgorithmEvaluation.h:88
Exception
Definition: hltDiff.cc:245
Exception.h
GlobalLogicParser::OP_OR
Definition: GlobalLogicParser.h:29
AlgorithmEvaluation.h
GlobalLogicParser::OperandToken
Definition: GlobalLogicParser.h:19
l1t::AlgorithmEvaluation::print
void print(std::ostream &myCout) const
Definition: AlgorithmEvaluation.cc:164
GlobalLogicParser::OperandToken::tokenName
std::string tokenName
Definition: GlobalLogicParser.h:20