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 68 of file AlgorithmEvaluation.h.

Member Typedef Documentation

◆ CItEvalMap

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

Definition at line 88 of file AlgorithmEvaluation.h.

◆ ConditionEvaluationMap

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

copy constructor

destructor

Definition at line 87 of file AlgorithmEvaluation.h.

◆ ItEvalMap

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

Definition at line 89 of file AlgorithmEvaluation.h.

◆ OperandToken

Definition at line 72 of file AlgorithmEvaluation.h.

◆ RpnVector

Definition at line 71 of file AlgorithmEvaluation.h.

◆ TokenRPN

Definition at line 70 of file AlgorithmEvaluation.h.

Constructor & Destructor Documentation

◆ AlgorithmEvaluation()

AlgorithmEvaluation::AlgorithmEvaluation ( const GlobalAlgorithm alg)
explicit

constructor

constructor from an algorithm from event setup

Definition at line 42 of file AlgorithmEvaluation.cc.

44  // the rest is properly initialized by default
45 }

Member Function Documentation

◆ evaluateAlgorithm()

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

evaluate an algorithm

Definition at line 50 of file AlgorithmEvaluation.cc.

51  {
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 }

References b1, b2, Exception, spr::find(), 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().

◆ gtAlgoCombinationVector()

std::vector<CombinationsInCond>& l1t::AlgorithmEvaluation::gtAlgoCombinationVector ( )
inline

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

Definition at line 102 of file AlgorithmEvaluation.h.

102 { return m_algoCombinationVector; }

References m_algoCombinationVector.

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

◆ gtAlgoResult()

bool l1t::AlgorithmEvaluation::gtAlgoResult ( ) const
inline

get / set the result of the algorithm

Definition at line 93 of file AlgorithmEvaluation.h.

93 { return m_algoResult; }

References m_algoResult.

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

◆ operandTokenVector()

std::vector<GlobalLogicParser::OperandToken>& l1t::AlgorithmEvaluation::operandTokenVector ( )
inline

Definition at line 104 of file AlgorithmEvaluation.h.

104 { return m_operandTokenVector; }

References m_operandTokenVector.

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

◆ print()

void AlgorithmEvaluation::print ( std::ostream &  myCout) const

Definition at line 164 of file AlgorithmEvaluation.cc.

164  {
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 }

References mps_fire::i.

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

◆ setGtAlgoResult()

void l1t::AlgorithmEvaluation::setGtAlgoResult ( const bool  algoResult)
inline

Definition at line 95 of file AlgorithmEvaluation.h.

95 { m_algoResult = algoResult; }

References m_algoResult.

Member Data Documentation

◆ m_algoCombinationVector

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

Definition at line 118 of file AlgorithmEvaluation.h.

Referenced by gtAlgoCombinationVector().

◆ m_algoResult

bool l1t::AlgorithmEvaluation::m_algoResult
private

algorithm result

Definition at line 110 of file AlgorithmEvaluation.h.

Referenced by gtAlgoResult(), and setGtAlgoResult().

◆ m_logicalExpression

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

Definition at line 113 of file AlgorithmEvaluation.h.

◆ m_operandTokenVector

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

Definition at line 116 of file AlgorithmEvaluation.h.

Referenced by operandTokenVector().

◆ m_rpnVector

RpnVector const& l1t::AlgorithmEvaluation::m_rpnVector
private

Definition at line 114 of file AlgorithmEvaluation.h.

mps_fire.i
i
Definition: mps_fire.py:428
l1t::AlgorithmEvaluation::m_logicalExpression
std::string const & m_logicalExpression
Definition: AlgorithmEvaluation.h:113
GlobalLogicParser::OP_XOR
Definition: GlobalLogicParser.h:34
l1t::AlgorithmEvaluation::m_algoResult
bool m_algoResult
algorithm result
Definition: AlgorithmEvaluation.h:110
CombinationsInCond
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
Definition: L1GlobalTriggerObjectMapFwd.h:32
GlobalAlgorithm::algoRpnVector
const std::vector< GlobalLogicParser::TokenRPN > & algoRpnVector() const
return the RPN vector
Definition: GlobalAlgorithm.h:69
b2
static constexpr float b2
Definition: L1EGammaCrystalsEmulatorProducer.cc:82
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:82
GlobalLogicParser::OP_OPERAND
Definition: GlobalLogicParser.h:31
GlobalLogicParser::OP_AND
Definition: GlobalLogicParser.h:28
l1t::AlgorithmEvaluation::m_algoCombinationVector
std::vector< CombinationsInCond > m_algoCombinationVector
Definition: AlgorithmEvaluation.h:118
l1t::AlgorithmEvaluation::m_operandTokenVector
std::vector< OperandToken > m_operandTokenVector
Definition: AlgorithmEvaluation.h:116
GlobalAlgorithm::algoLogicalExpression
std::string const & algoLogicalExpression() const
get / set the logical expression for the algorithm
Definition: GlobalAlgorithm.h:62
l1t::AlgorithmEvaluation::m_rpnVector
RpnVector const & m_rpnVector
Definition: AlgorithmEvaluation.h:114
l1t::AlgorithmEvaluation::OperandToken
GlobalLogicParser::OperandToken OperandToken
Definition: AlgorithmEvaluation.h:72
GlobalLogicParser::OP_NOT
Definition: GlobalLogicParser.h:30
l1t::AlgorithmEvaluation::CItEvalMap
ConditionEvaluationMap::const_iterator CItEvalMap
Definition: AlgorithmEvaluation.h:88
Exception
Definition: hltDiff.cc:246
GlobalLogicParser::OP_OR
Definition: GlobalLogicParser.h:29
GlobalLogicParser::OperandToken::tokenName
std::string tokenName
Definition: GlobalLogicParser.h:20