CMS 3D CMS Logo

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 <queue>
22 #include <stack>
23 #include <vector>
24 
25 #include <iomanip>
26 #include <iostream>
27 
28 #include <boost/algorithm/string.hpp>
29 #include <ext/hash_map>
30 
31 // user include files
32 
33 //
36 
38 
41 
44  : m_algoResult(false), m_logicalExpression(alg.algoLogicalExpression()), m_rpnVector(alg.algoRpnVector()) {
45  // the rest is properly initialized by default
46 }
47 
48 // methods
49 
52  const std::vector<ConditionEvaluationMap> &conditionResultMaps) {
53  // set result to false if there is no expression
54  if (m_rpnVector.empty()) {
55  m_algoResult = false;
56 
57  // it should never be happen
58  throw cms::Exception("FailModule") << "\nEmpty RPN vector for the logical expression = " << m_logicalExpression
59  << std::endl;
60  }
61 
62  // reserve memory
63  int rpnVectorSize = m_rpnVector.size();
64 
65  m_algoCombinationVector.reserve(rpnVectorSize);
66  m_operandTokenVector.reserve(rpnVectorSize);
67 
68  // stack containing temporary results
69  // FIXME we shall find a better solution than static
70  std::stack<bool, std::vector<bool>> resultStack;
71  bool b1, b2;
72 
73  int opNumber = 0;
74 
75  for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
76  // LogTrace("L1GlobalTrigger")
77  //<< "\nit->operation = " << it->operation
78  //<< "\nit->operand = '" << it->operand << "'\n"
79  //<< std::endl;
80 
81  switch (it->operation) {
83  CItEvalMap itCond = (conditionResultMaps.at(chipNumber)).find(it->operand);
84  if (itCond != (conditionResultMaps[chipNumber]).end()) {
85  if (nullptr == itCond->second) {
86  // it should never be happen, only valid conditions are in the maps
87  throw cms::Exception("FailModule")
88  << "\nCondition " << (it->operand) << " NULL pointer found in condition map" << std::endl;
89  }
90 
91  //
92  bool condResult = (itCond->second)->condLastResult();
93 
94  resultStack.push(condResult);
95 
96  // only conditions are added to /counted in m_operandTokenVector
97  // opNumber is the index of the condition in the logical expression
98  OperandToken opToken;
99  opToken.tokenName = it->operand;
100  opToken.tokenNumber = opNumber;
101  opToken.tokenResult = condResult;
102 
103  m_operandTokenVector.push_back(opToken);
104  opNumber++;
105 
106  //
107  CombinationsInCond const &combInCondition = (itCond->second)->getCombinationsInCond();
108  m_algoCombinationVector.push_back(combInCondition);
109 
110  } else {
111  // it should never be happen, all conditions are in the maps
112  throw cms::Exception("FailModule")
113  << "\nCondition " << (it->operand) << " not found in condition map" << std::endl;
114  }
115 
116  }
117 
118  break;
120  b1 = resultStack.top();
121  resultStack.pop(); // pop the top
122  resultStack.push(!b1); // and push the result
123  }
124 
125  break;
126  case L1GtLogicParser::OP_OR: {
127  b1 = resultStack.top();
128  resultStack.pop();
129  b2 = resultStack.top();
130  resultStack.pop();
131  resultStack.push(b1 || b2);
132  }
133 
134  break;
136  b1 = resultStack.top();
137  resultStack.pop();
138  b2 = resultStack.top();
139  resultStack.pop();
140  resultStack.push(b1 && b2);
141  }
142 
143  break;
144  default: {
145  // should not arrive here
146  }
147 
148  break;
149  }
150  }
151 
152  // get the result in the top of the stack
153 
154  m_algoResult = resultStack.top();
155 
156  // clear resultStack not needed since it is now a function temporary
157 }
158 
159 // print algorithm evaluation
160 void L1GtAlgorithmEvaluation::print(std::ostream &myCout) const {
161  myCout << std::endl;
162 
163  myCout << " Algorithm result: " << m_algoResult << std::endl;
164 
165  myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
166 
167  int operandTokenVectorSize = m_operandTokenVector.size();
168 
169  myCout << " Operand token vector size: " << operandTokenVectorSize;
170 
171  if (operandTokenVectorSize == 0) {
172  myCout << " - not properly initialized! " << std::endl;
173  } else {
174  myCout << std::endl;
175 
176  for (int i = 0; i < operandTokenVectorSize; ++i) {
177  myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t" << std::setw(25)
178  << (m_operandTokenVector[i]).tokenName << "\t" << (m_operandTokenVector[i]).tokenResult << std::endl;
179  }
180  }
181 
182  myCout << std::endl;
183 }
L1GtLogicParser::OperandToken
Definition: L1GtLogicParser.h:33
L1GtLogicParser::OP_AND
Definition: L1GtLogicParser.h:42
mps_fire.i
i
Definition: mps_fire.py:355
L1GtAlgorithm.h
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
L1GtAlgorithmEvaluation::m_algoResult
bool m_algoResult
algorithm result
Definition: L1GtAlgorithmEvaluation.h:105
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
L1GtLogicParser::OP_OR
Definition: L1GtLogicParser.h:43
L1GtAlgorithmEvaluation::m_operandTokenVector
std::vector< OperandToken > m_operandTokenVector
Definition: L1GtAlgorithmEvaluation.h:111
L1GtLogicParser::OperandToken::tokenResult
bool tokenResult
Definition: L1GtLogicParser.h:36
b1
static constexpr float b1
Definition: L1EGammaCrystalsEmulatorProducer.cc:83
L1GtLogicParser::OperandToken::tokenName
std::string tokenName
Definition: L1GtLogicParser.h:34
L1GtAlgorithmEvaluation::print
void print(std::ostream &myCout) const
Definition: L1GtAlgorithmEvaluation.cc:160
L1GtConditionEvaluation.h
L1GtAlgorithmEvaluation::m_logicalExpression
const std::string & m_logicalExpression
Definition: L1GtAlgorithmEvaluation.h:108
L1GtAlgorithm
Definition: L1GtAlgorithm.h:32
L1GtAlgorithmEvaluation.h
L1GtLogicParser::OP_OPERAND
Definition: L1GtLogicParser.h:45
L1GtAlgorithmEvaluation::m_algoCombinationVector
std::vector< CombinationsInCond > m_algoCombinationVector
Definition: L1GtAlgorithmEvaluation.h:113
L1GtAlgorithmEvaluation::m_rpnVector
const RpnVector & m_rpnVector
Definition: L1GtAlgorithmEvaluation.h:109
L1GtLogicParser::OP_NOT
Definition: L1GtLogicParser.h:44
L1GlobalTriggerObjectMapFwd.h
Exception
Definition: hltDiff.cc:246
L1GtLogicParser::OperandToken::tokenNumber
int tokenNumber
Definition: L1GtLogicParser.h:35
L1GtAlgorithmEvaluation::L1GtAlgorithmEvaluation
L1GtAlgorithmEvaluation(const L1GtAlgorithm &)
constructor
Definition: L1GtAlgorithmEvaluation.cc:43
Exception.h
L1GtAlgorithmEvaluation::CItEvalMap
ConditionEvaluationMap::const_iterator CItEvalMap
Definition: L1GtAlgorithmEvaluation.h:83
L1GtAlgorithmEvaluation::evaluateAlgorithm
void evaluateAlgorithm(const int chipNumber, const std::vector< ConditionEvaluationMap > &)
evaluate an algorithm
Definition: L1GtAlgorithmEvaluation.cc:51