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 std::unordered_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 39 of file AlgorithmEvaluation.h.

Member Typedef Documentation

◆ CItEvalMap

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

Definition at line 59 of file AlgorithmEvaluation.h.

◆ ConditionEvaluationMap

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

copy constructor

destructor

Definition at line 58 of file AlgorithmEvaluation.h.

◆ ItEvalMap

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

Definition at line 60 of file AlgorithmEvaluation.h.

◆ OperandToken

Definition at line 43 of file AlgorithmEvaluation.h.

◆ RpnVector

Definition at line 42 of file AlgorithmEvaluation.h.

◆ TokenRPN

Definition at line 41 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 39 of file AlgorithmEvaluation.cc.

41  // the rest is properly initialized by default
42 }
std::string const & algoLogicalExpression() const
get / set the logical expression for the algorithm
std::string const & m_logicalExpression
RpnVector const & m_rpnVector
const std::vector< GlobalLogicParser::TokenRPN > & algoRpnVector() const
return the RPN vector
bool m_algoResult
algorithm result

Member Function Documentation

◆ evaluateAlgorithm()

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

evaluate an algorithm

Definition at line 47 of file AlgorithmEvaluation.cc.

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

48  {
49  // set result to false if there is no expression
50  if (m_rpnVector.empty()) {
51  m_algoResult = false;
52 
53  // it should never be happen
54  throw cms::Exception("FailModule") << "\nEmpty RPN vector for the logical expression = " << m_logicalExpression
55  << std::endl;
56  }
57 
58  // reserve memory
59  int rpnVectorSize = m_rpnVector.size();
60 
61  m_algoCombinationVector.reserve(rpnVectorSize);
62  m_operandTokenVector.reserve(rpnVectorSize);
63 
64  // stack containing temporary results
65  std::stack<bool, std::vector<bool> > resultStack;
66  bool b1, b2;
67 
68  int opNumber = 0;
69 
70  for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
71  //LogTrace("L1TGlobal")
72  //<< "\nit->operation = " << it->operation
73  //<< "\nit->operand = '" << it->operand << "'\n"
74  //<< std::endl;
75 
76  switch (it->operation) {
78  CItEvalMap itCond = (conditionResultMaps.at(chipNumber)).find(it->operand);
79  if (itCond != (conditionResultMaps[chipNumber]).end()) {
80  if (nullptr == itCond->second) {
81  // it should never be happen, only valid conditions are in the maps
82  throw cms::Exception("FailModule")
83  << "\nCondition " << (it->operand) << " NULL pointer found in condition map" << std::endl;
84  }
85 
86  //
87  bool condResult = (itCond->second)->condLastResult();
88 
89  resultStack.push(condResult);
90 
91  // only conditions are added to /counted in m_operandTokenVector
92  // opNumber is the index of the condition in the logical expression
93  OperandToken opToken;
94  opToken.tokenName = it->operand;
95  opToken.tokenNumber = opNumber;
96  opToken.tokenResult = condResult;
97 
98  m_operandTokenVector.push_back(opToken);
99  opNumber++;
100 
101  //
102  CombinationsInCond const& combInCondition = (itCond->second)->getCombinationsInCond();
103  m_algoCombinationVector.push_back(combInCondition);
104 
105  } else {
106  // it should never be happen, all conditions are in the maps
107  throw cms::Exception("FailModule")
108  << "\nCondition " << (it->operand) << " not found in condition map" << std::endl;
109  }
110 
111  }
112 
113  break;
115  b1 = resultStack.top();
116  resultStack.pop(); // pop the top
117  resultStack.push(!b1); // and push the result
118  }
119 
120  break;
122  b1 = resultStack.top();
123  resultStack.pop();
124  b2 = resultStack.top();
125  resultStack.pop();
126  resultStack.push(b1 || b2);
127  }
128 
129  break;
131  b1 = resultStack.top();
132  resultStack.pop();
133  b2 = resultStack.top();
134  resultStack.pop();
135  resultStack.push(b1 && b2);
136  }
137 
138  break;
140  b1 = resultStack.top();
141  resultStack.pop();
142  b2 = resultStack.top();
143  resultStack.pop();
144  resultStack.push(b1 ^ b2);
145  }
146 
147  break;
148  default: {
149  // should not arrive here
150  }
151 
152  break;
153  }
154  }
155 
156  // get the result in the top of the stack
157  m_algoResult = resultStack.top();
158 }
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:19
std::string const & m_logicalExpression
bias2_t b2[25]
Definition: b2.h:9
RpnVector const & m_rpnVector
GlobalLogicParser::OperandToken OperandToken
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
static constexpr float b1
bool m_algoResult
algorithm result
std::vector< OperandToken > m_operandTokenVector

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

References m_algoCombinationVector.

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

73 { return m_algoCombinationVector; }
std::vector< CombinationsInCond > m_algoCombinationVector

◆ gtAlgoResult()

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

get / set the result of the algorithm

Definition at line 64 of file AlgorithmEvaluation.h.

References m_algoResult.

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

64 { return m_algoResult; }
bool m_algoResult
algorithm result

◆ operandTokenVector()

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

Definition at line 75 of file AlgorithmEvaluation.h.

References m_operandTokenVector.

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

75 { return m_operandTokenVector; }
std::vector< OperandToken > m_operandTokenVector

◆ print()

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

Definition at line 161 of file AlgorithmEvaluation.cc.

References mps_fire::i.

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

161  {
162  myCout << std::endl;
163 
164  myCout << " Algorithm result: " << m_algoResult << std::endl;
165 
166  myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
167 
168  int operandTokenVectorSize = m_operandTokenVector.size();
169 
170  myCout << " Operand token vector size: " << operandTokenVectorSize;
171 
172  if (operandTokenVectorSize == 0) {
173  myCout << " - not properly initialized! " << std::endl;
174  } else {
175  myCout << std::endl;
176 
177  for (int i = 0; i < operandTokenVectorSize; ++i) {
178  myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t" << std::setw(25)
179  << (m_operandTokenVector[i]).tokenName << "\t" << (m_operandTokenVector[i]).tokenResult << std::endl;
180  }
181  }
182 
183  myCout << std::endl;
184 }
std::vector< CombinationsInCond > m_algoCombinationVector
bool m_algoResult
algorithm result
std::vector< OperandToken > m_operandTokenVector

◆ setGtAlgoResult()

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

Definition at line 66 of file AlgorithmEvaluation.h.

References m_algoResult.

66 { m_algoResult = algoResult; }
bool m_algoResult
algorithm result

Member Data Documentation

◆ m_algoCombinationVector

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

Definition at line 89 of file AlgorithmEvaluation.h.

Referenced by gtAlgoCombinationVector().

◆ m_algoResult

bool l1t::AlgorithmEvaluation::m_algoResult
private

algorithm result

Definition at line 81 of file AlgorithmEvaluation.h.

Referenced by gtAlgoResult(), and setGtAlgoResult().

◆ m_logicalExpression

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

Definition at line 84 of file AlgorithmEvaluation.h.

◆ m_operandTokenVector

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

Definition at line 87 of file AlgorithmEvaluation.h.

Referenced by operandTokenVector().

◆ m_rpnVector

RpnVector const& l1t::AlgorithmEvaluation::m_rpnVector
private

Definition at line 85 of file AlgorithmEvaluation.h.