CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
l1t::AlgorithmEvaluation Class Reference

#include <AlgorithmEvaluation.h>

Public Types

typedef ConditionEvaluationMap::const_iterator CItEvalMap
 
typedef __gnu_cxx::hash_map< std::string, ConditionEvaluation * > ConditionEvaluationMap
 copy constructor More...
 
typedef ConditionEvaluationMap::iterator ItEvalMap
 
typedef GlobalLogicParser::OperandToken OperandToken
 
typedef std::vector< TokenRPNRpnVector
 
typedef GlobalLogicParser::TokenRPN TokenRPN
 

Public Member Functions

 AlgorithmEvaluation (const GlobalAlgorithm &)
 constructor More...
 
void evaluateAlgorithm (const int chipNumber, const std::vector< ConditionEvaluationMap > &)
 evaluate an algorithm More...
 
std::vector< CombinationsInCond > & gtAlgoCombinationVector ()
 
bool gtAlgoResult () const
 get / set the result of the algorithm More...
 
std::vector< GlobalLogicParser::OperandToken > & operandTokenVector ()
 
void print (std::ostream &myCout) const
 
void setGtAlgoResult (const bool algoResult)
 

Private Attributes

std::vector< CombinationsInCondm_algoCombinationVector
 
bool m_algoResult
 algorithm result More...
 
std::string const & m_logicalExpression
 
std::vector< OperandTokenm_operandTokenVector
 
RpnVector const & m_rpnVector
 

Detailed Description

Definition at line 72 of file AlgorithmEvaluation.h.

Member Typedef Documentation

typedef ConditionEvaluationMap::const_iterator l1t::AlgorithmEvaluation::CItEvalMap

Definition at line 94 of file AlgorithmEvaluation.h.

typedef __gnu_cxx ::hash_map<std::string, ConditionEvaluation*> l1t::AlgorithmEvaluation::ConditionEvaluationMap

copy constructor

destructor

Definition at line 93 of file AlgorithmEvaluation.h.

typedef ConditionEvaluationMap::iterator l1t::AlgorithmEvaluation::ItEvalMap

Definition at line 95 of file AlgorithmEvaluation.h.

Definition at line 77 of file AlgorithmEvaluation.h.

Definition at line 76 of file AlgorithmEvaluation.h.

Definition at line 75 of file AlgorithmEvaluation.h.

Constructor & Destructor Documentation

AlgorithmEvaluation::AlgorithmEvaluation ( const GlobalAlgorithm alg)
explicit

constructor

constructor from an algorithm from event setup

Definition at line 44 of file AlgorithmEvaluation.cc.

44  :
45  m_algoResult(false),
48 
49  // the rest is properly initialized by default
50 
51 }
std::string const & algoLogicalExpression() const
get / set the logical expression for the algorithm
std::string const & m_logicalExpression
const std::vector< GlobalLogicParser::TokenRPN > & algoRpnVector() const
return the RPN vector
bool m_algoResult
algorithm result

Member Function Documentation

void AlgorithmEvaluation::evaluateAlgorithm ( const int  chipNumber,
const std::vector< ConditionEvaluationMap > &  conditionResultMaps 
)

evaluate an algorithm

Definition at line 57 of file AlgorithmEvaluation.cc.

References Exception, spr::find(), m_algoCombinationVector, m_algoResult, m_logicalExpression, m_operandTokenVector, m_rpnVector, GlobalLogicParser::OP_AND, GlobalLogicParser::OP_NOT, GlobalLogicParser::OP_OPERAND, GlobalLogicParser::OP_OR, GlobalLogicParser::OP_XOR, GlobalLogicParser::OperandToken::tokenName, GlobalLogicParser::OperandToken::tokenNumber, and GlobalLogicParser::OperandToken::tokenResult.

Referenced by l1t::GlobalBoard::runGTL().

58  {
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 (nullptr == 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;
164  b1 = resultStack.top();
165  resultStack.pop();
166  b2 = resultStack.top();
167  resultStack.pop();
168  resultStack.push(b1 ^ b2);
169  }
170 
171  break;
172  default: {
173  // should not arrive here
174  }
175 
176  break;
177  }
178 
179  }
180 
181  // get the result in the top of the stack
182  m_algoResult = resultStack.top();
183 }
ConditionEvaluationMap::const_iterator CItEvalMap
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
GlobalLogicParser::OperandToken OperandToken
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
bool m_algoResult
algorithm result
std::vector< OperandToken > m_operandTokenVector
std::vector<CombinationsInCond>& l1t::AlgorithmEvaluation::gtAlgoCombinationVector ( )
inline

get all the object combinations evaluated to true in the conditions from the algorithm

Definition at line 114 of file AlgorithmEvaluation.h.

Referenced by l1t::GlobalBoard::runGTL().

114  {
116  }
std::vector< CombinationsInCond > m_algoCombinationVector
bool l1t::AlgorithmEvaluation::gtAlgoResult ( ) const
inline

get / set the result of the algorithm

Definition at line 100 of file AlgorithmEvaluation.h.

Referenced by l1t::GlobalBoard::runGTL().

100  {
101  return m_algoResult;
102  }
bool m_algoResult
algorithm result
std::vector<GlobalLogicParser::OperandToken>& l1t::AlgorithmEvaluation::operandTokenVector ( )
inline

Definition at line 118 of file AlgorithmEvaluation.h.

References edm::print().

Referenced by l1t::GlobalBoard::runGTL().

118  {
119  return m_operandTokenVector;
120  }
std::vector< OperandToken > m_operandTokenVector
void AlgorithmEvaluation::print ( std::ostream &  myCout) const

Definition at line 186 of file AlgorithmEvaluation.cc.

References mps_fire::i, m_algoCombinationVector, m_algoResult, and m_operandTokenVector.

Referenced by l1t::GlobalBoard::runGTL().

186  {
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 }
std::vector< CombinationsInCond > m_algoCombinationVector
bool m_algoResult
algorithm result
std::vector< OperandToken > m_operandTokenVector
void l1t::AlgorithmEvaluation::setGtAlgoResult ( const bool  algoResult)
inline

Definition at line 104 of file AlgorithmEvaluation.h.

104  {
105  m_algoResult = algoResult;
106  }
bool m_algoResult
algorithm result

Member Data Documentation

std::vector<CombinationsInCond> l1t::AlgorithmEvaluation::m_algoCombinationVector
private

Definition at line 135 of file AlgorithmEvaluation.h.

Referenced by evaluateAlgorithm(), and print().

bool l1t::AlgorithmEvaluation::m_algoResult
private

algorithm result

Definition at line 127 of file AlgorithmEvaluation.h.

Referenced by evaluateAlgorithm(), and print().

std::string const& l1t::AlgorithmEvaluation::m_logicalExpression
private

Definition at line 130 of file AlgorithmEvaluation.h.

Referenced by evaluateAlgorithm().

std::vector<OperandToken> l1t::AlgorithmEvaluation::m_operandTokenVector
private

Definition at line 133 of file AlgorithmEvaluation.h.

Referenced by evaluateAlgorithm(), and print().

RpnVector const& l1t::AlgorithmEvaluation::m_rpnVector
private

Definition at line 131 of file AlgorithmEvaluation.h.

Referenced by evaluateAlgorithm().