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
L1GtLogicParser::OperandToken 
OperandToken
 
typedef std::vector< TokenRPNRpnVector
 
typedef L1GtLogicParser::TokenRPN TokenRPN
 

Public Member Functions

 AlgorithmEvaluation (const L1GtAlgorithm &)
 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
< L1GtLogicParser::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 73 of file AlgorithmEvaluation.h.

Member Typedef Documentation

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

Definition at line 95 of file AlgorithmEvaluation.h.

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

copy constructor

destructor

Definition at line 94 of file AlgorithmEvaluation.h.

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

Definition at line 96 of file AlgorithmEvaluation.h.

Definition at line 78 of file AlgorithmEvaluation.h.

Definition at line 77 of file AlgorithmEvaluation.h.

Definition at line 76 of file AlgorithmEvaluation.h.

Constructor & Destructor Documentation

AlgorithmEvaluation::AlgorithmEvaluation ( const L1GtAlgorithm alg)
explicit

constructor

constructor from an algorithm from event setup

Definition at line 45 of file AlgorithmEvaluation.cc.

45  :
46  m_algoResult(false),
49 
50  // the rest is properly initialized by default
51 
52 }
const std::vector< L1GtLogicParser::TokenRPN > & algoRpnVector() const
return the RPN vector
Definition: L1GtAlgorithm.h:89
std::string const & m_logicalExpression
std::string const & algoLogicalExpression() const
get / set the logical expression for the algorithm
Definition: L1GtAlgorithm.h:78
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 58 of file AlgorithmEvaluation.cc.

References Exception, spr::find(), L1GtLogicParser::OP_AND, L1GtLogicParser::OP_NOT, L1GtLogicParser::OP_OPERAND, L1GtLogicParser::OP_OR, L1GtLogicParser::OperandToken::tokenName, L1GtLogicParser::OperandToken::tokenNumber, and L1GtLogicParser::OperandToken::tokenResult.

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

59  {
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  static 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("l1t|Global")
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
179  while(!resultStack.empty()) resultStack.pop();
180 
181 }
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
L1GtLogicParser::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 115 of file AlgorithmEvaluation.h.

References m_algoCombinationVector.

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

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

get / set the result of the algorithm

Definition at line 101 of file AlgorithmEvaluation.h.

References m_algoResult.

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

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

Definition at line 119 of file AlgorithmEvaluation.h.

References m_operandTokenVector.

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

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

Definition at line 184 of file AlgorithmEvaluation.cc.

References i.

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

184  {
185 
186  myCout << std::endl;
187 
188  myCout << " Algorithm result: " << m_algoResult << std::endl;
189 
190  myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
191 
192  int operandTokenVectorSize = m_operandTokenVector.size();
193 
194  myCout << " Operand token vector size: " << operandTokenVectorSize;
195 
196  if (operandTokenVectorSize == 0) {
197  myCout << " - not properly initialized! " << std::endl;
198  }
199  else {
200  myCout << std::endl;
201 
202  for (int i = 0; i < operandTokenVectorSize; ++i) {
203 
204  myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t"
205  << std::setw(25) << (m_operandTokenVector[i]).tokenName << "\t"
206  << (m_operandTokenVector[i]).tokenResult
207  << std::endl;
208 
209  }
210 
211  }
212 
213  myCout << std::endl;
214 }
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 105 of file AlgorithmEvaluation.h.

References m_algoResult.

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

Member Data Documentation

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

Definition at line 136 of file AlgorithmEvaluation.h.

Referenced by gtAlgoCombinationVector().

bool l1t::AlgorithmEvaluation::m_algoResult
private

algorithm result

Definition at line 128 of file AlgorithmEvaluation.h.

Referenced by gtAlgoResult(), and setGtAlgoResult().

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

Definition at line 131 of file AlgorithmEvaluation.h.

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

Definition at line 134 of file AlgorithmEvaluation.h.

Referenced by operandTokenVector().

RpnVector const& l1t::AlgorithmEvaluation::m_rpnVector
private

Definition at line 132 of file AlgorithmEvaluation.h.