CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
L1GtAlgorithmEvaluation Class Reference

#include <L1GtAlgorithmEvaluation.h>

Public Types

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

Public Member Functions

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...
 
 L1GtAlgorithmEvaluation (const L1GtAlgorithm &)
 constructor 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...
 
const std::string & m_logicalExpression
 
std::vector< OperandTokenm_operandTokenVector
 
const RpnVectorm_rpnVector
 

Detailed Description

Description: Evaluation of a L1 Global Trigger algorithm.

Implementation: <TODO: enter implementation details>

Author
: Vasile Mihai Ghete - HEPHY Vienna

Definition at line 62 of file L1GtAlgorithmEvaluation.h.

Member Typedef Documentation

◆ CItEvalMap

typedef ConditionEvaluationMap::const_iterator L1GtAlgorithmEvaluation::CItEvalMap

Definition at line 83 of file L1GtAlgorithmEvaluation.h.

◆ ConditionEvaluationMap

typedef __gnu_cxx ::hash_map<std::string, L1GtConditionEvaluation *> L1GtAlgorithmEvaluation::ConditionEvaluationMap

copy constructor

destructor

Definition at line 82 of file L1GtAlgorithmEvaluation.h.

◆ ItEvalMap

typedef ConditionEvaluationMap::iterator L1GtAlgorithmEvaluation::ItEvalMap

Definition at line 84 of file L1GtAlgorithmEvaluation.h.

◆ OperandToken

Definition at line 66 of file L1GtAlgorithmEvaluation.h.

◆ RpnVector

Definition at line 65 of file L1GtAlgorithmEvaluation.h.

◆ TokenRPN

Definition at line 64 of file L1GtAlgorithmEvaluation.h.

Constructor & Destructor Documentation

◆ L1GtAlgorithmEvaluation()

L1GtAlgorithmEvaluation::L1GtAlgorithmEvaluation ( const L1GtAlgorithm alg)
explicit

constructor

constructor from an algorithm from event setup

Definition at line 43 of file L1GtAlgorithmEvaluation.cc.

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

Member Function Documentation

◆ evaluateAlgorithm()

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

evaluate an algorithm

Definition at line 51 of file L1GtAlgorithmEvaluation.cc.

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

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

Referenced by L1GlobalTriggerGTL::run().

◆ gtAlgoCombinationVector()

std::vector<CombinationsInCond>& L1GtAlgorithmEvaluation::gtAlgoCombinationVector ( )
inline

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

Definition at line 97 of file L1GtAlgorithmEvaluation.h.

97 { return m_algoCombinationVector; }

References m_algoCombinationVector.

Referenced by L1GlobalTriggerGTL::run().

◆ gtAlgoResult()

bool L1GtAlgorithmEvaluation::gtAlgoResult ( ) const
inline

get / set the result of the algorithm

Definition at line 88 of file L1GtAlgorithmEvaluation.h.

88 { return m_algoResult; }

References m_algoResult.

Referenced by L1GlobalTriggerGTL::run().

◆ operandTokenVector()

std::vector<L1GtLogicParser::OperandToken>& L1GtAlgorithmEvaluation::operandTokenVector ( )
inline

Definition at line 99 of file L1GtAlgorithmEvaluation.h.

99 { return m_operandTokenVector; }

References m_operandTokenVector.

Referenced by L1GlobalTriggerGTL::run().

◆ print()

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

Definition at line 160 of file L1GtAlgorithmEvaluation.cc.

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

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

Referenced by L1GlobalTriggerGTL::run().

◆ setGtAlgoResult()

void L1GtAlgorithmEvaluation::setGtAlgoResult ( const bool  algoResult)
inline

Definition at line 90 of file L1GtAlgorithmEvaluation.h.

90 { m_algoResult = algoResult; }

References m_algoResult.

Member Data Documentation

◆ m_algoCombinationVector

std::vector<CombinationsInCond> L1GtAlgorithmEvaluation::m_algoCombinationVector
private

Definition at line 113 of file L1GtAlgorithmEvaluation.h.

Referenced by evaluateAlgorithm(), gtAlgoCombinationVector(), and print().

◆ m_algoResult

bool L1GtAlgorithmEvaluation::m_algoResult
private

algorithm result

Definition at line 105 of file L1GtAlgorithmEvaluation.h.

Referenced by evaluateAlgorithm(), gtAlgoResult(), print(), and setGtAlgoResult().

◆ m_logicalExpression

const std::string& L1GtAlgorithmEvaluation::m_logicalExpression
private

Definition at line 108 of file L1GtAlgorithmEvaluation.h.

Referenced by evaluateAlgorithm().

◆ m_operandTokenVector

std::vector<OperandToken> L1GtAlgorithmEvaluation::m_operandTokenVector
private

Definition at line 111 of file L1GtAlgorithmEvaluation.h.

Referenced by evaluateAlgorithm(), operandTokenVector(), and print().

◆ m_rpnVector

const RpnVector& L1GtAlgorithmEvaluation::m_rpnVector
private

Definition at line 109 of file L1GtAlgorithmEvaluation.h.

Referenced by evaluateAlgorithm().

L1GtAlgorithm::algoLogicalExpression
std::string const & algoLogicalExpression() const
get / set the logical expression for the algorithm
Definition: L1GtAlgorithm.h:62
L1GtLogicParser::OP_AND
Definition: L1GtLogicParser.h:42
mps_fire.i
i
Definition: mps_fire.py:428
L1GtAlgorithmEvaluation::m_algoResult
bool m_algoResult
algorithm result
Definition: L1GtAlgorithmEvaluation.h:105
CombinationsInCond
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
Definition: L1GlobalTriggerObjectMapFwd.h:32
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
L1GtLogicParser::OP_OR
Definition: L1GtLogicParser.h:43
L1GtAlgorithmEvaluation::m_operandTokenVector
std::vector< OperandToken > m_operandTokenVector
Definition: L1GtAlgorithmEvaluation.h:111
b1
static constexpr float b1
Definition: L1EGammaCrystalsEmulatorProducer.cc:82
L1GtLogicParser::OperandToken::tokenName
std::string tokenName
Definition: L1GtLogicParser.h:34
L1GtAlgorithmEvaluation::OperandToken
L1GtLogicParser::OperandToken OperandToken
Definition: L1GtAlgorithmEvaluation.h:66
L1GtAlgorithmEvaluation::m_logicalExpression
const std::string & m_logicalExpression
Definition: L1GtAlgorithmEvaluation.h:108
L1GtAlgorithm::algoRpnVector
const std::vector< L1GtLogicParser::TokenRPN > & algoRpnVector() const
return the RPN vector
Definition: L1GtAlgorithm.h:69
L1GtLogicParser::OP_OPERAND
Definition: L1GtLogicParser.h:45
L1GtAlgorithmEvaluation::m_algoCombinationVector
std::vector< CombinationsInCond > m_algoCombinationVector
Definition: L1GtAlgorithmEvaluation.h:113
L1GtAlgorithmEvaluation::m_rpnVector
const RpnVector & m_rpnVector
Definition: L1GtAlgorithmEvaluation.h:109
L1GtLogicParser::OP_NOT
Definition: L1GtLogicParser.h:44
Exception
Definition: hltDiff.cc:246
L1GtAlgorithmEvaluation::CItEvalMap
ConditionEvaluationMap::const_iterator CItEvalMap
Definition: L1GtAlgorithmEvaluation.h:83