CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(), GlobalLogicParser::OP_AND, GlobalLogicParser::OP_NOT, GlobalLogicParser::OP_OPERAND, GlobalLogicParser::OP_OR, 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  // FIXME we shall find a better solution than static
80  static std::stack<bool, std::vector<bool> > resultStack;
81  bool b1, b2;
82 
83  int opNumber = 0;
84 
85  for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
86 
87  //LogTrace("L1TGlobal")
88  //<< "\nit->operation = " << it->operation
89  //<< "\nit->operand = '" << it->operand << "'\n"
90  //<< std::endl;
91 
92  switch (it->operation) {
93 
95 
96  CItEvalMap itCond = (conditionResultMaps.at(chipNumber)).find(it->operand);
97  if (itCond != (conditionResultMaps[chipNumber]).end()) {
98 
99  if (0 == itCond->second) {
100  // it should never be happen, only valid conditions are in the maps
101  throw cms::Exception("FailModule") << "\nCondition "
102  << (it->operand)
103  << " NULL pointer found in condition map"
104  << std::endl;
105  }
106 
107  //
108  bool condResult = (itCond->second)->condLastResult();
109 
110  resultStack.push(condResult);
111 
112  // only conditions are added to /counted in m_operandTokenVector
113  // opNumber is the index of the condition in the logical expression
114  OperandToken opToken;
115  opToken.tokenName = it->operand;
116  opToken.tokenNumber = opNumber;
117  opToken.tokenResult = condResult;
118 
119  m_operandTokenVector.push_back(opToken);
120  opNumber++;
121 
122  //
123  CombinationsInCond const & combInCondition = (itCond->second)->getCombinationsInCond();
124  m_algoCombinationVector.push_back(combInCondition);
125 
126  }
127  else {
128 
129  // it should never be happen, all conditions are in the maps
130  throw cms::Exception("FailModule")
131  << "\nCondition " << (it->operand) << " not found in condition map"
132  << std::endl;
133 
134  }
135 
136  }
137 
138  break;
140  b1 = resultStack.top();
141  resultStack.pop(); // pop the top
142  resultStack.push(!b1); // and push the result
143  }
144 
145  break;
147  b1 = resultStack.top();
148  resultStack.pop();
149  b2 = resultStack.top();
150  resultStack.pop();
151  resultStack.push(b1 || b2);
152  }
153 
154  break;
156  b1 = resultStack.top();
157  resultStack.pop();
158  b2 = resultStack.top();
159  resultStack.pop();
160  resultStack.push(b1 && b2);
161  }
162 
163  break;
164  default: {
165  // should not arrive here
166  }
167 
168  break;
169  }
170 
171  }
172 
173  // get the result in the top of the stack
174 
175  m_algoResult = resultStack.top();
176 
177  // clear resultStack
178  while(!resultStack.empty()) resultStack.pop();
179 
180 }
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:7
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.

References m_algoCombinationVector.

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.

References m_algoResult.

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 m_operandTokenVector.

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 183 of file AlgorithmEvaluation.cc.

References i.

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

183  {
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 }
int i
Definition: DBlmapReader.cc:9
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.

References m_algoResult.

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 gtAlgoCombinationVector().

bool l1t::AlgorithmEvaluation::m_algoResult
private

algorithm result

Definition at line 127 of file AlgorithmEvaluation.h.

Referenced by gtAlgoResult(), and setGtAlgoResult().

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

Definition at line 130 of file AlgorithmEvaluation.h.

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

Definition at line 133 of file AlgorithmEvaluation.h.

Referenced by operandTokenVector().

RpnVector const& l1t::AlgorithmEvaluation::m_rpnVector
private

Definition at line 131 of file AlgorithmEvaluation.h.