File indexing completed on 2025-01-14 23:16:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "L1Trigger/L1TGlobal/interface/AlgorithmEvaluation.h"
0017
0018
0019 #include <string>
0020
0021 #include <stack>
0022 #include <queue>
0023 #include <vector>
0024
0025 #include <iostream>
0026 #include <iomanip>
0027
0028
0029
0030
0031 #include "L1Trigger/L1TGlobal/interface/GlobalAlgorithm.h"
0032
0033 #include "L1Trigger/L1TGlobal/interface/ConditionEvaluation.h"
0034
0035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0036 #include "FWCore/Utilities/interface/Exception.h"
0037
0038
0039 l1t::AlgorithmEvaluation::AlgorithmEvaluation(const GlobalAlgorithm& alg)
0040 : m_algoResult(false), m_logicalExpression(alg.algoLogicalExpression()), m_rpnVector(alg.algoRpnVector()) {
0041
0042 }
0043
0044
0045
0046
0047 void l1t::AlgorithmEvaluation::evaluateAlgorithm(const int chipNumber,
0048 const std::vector<ConditionEvaluationMap>& conditionResultMaps) {
0049
0050 if (m_rpnVector.empty()) {
0051 m_algoResult = false;
0052
0053
0054 throw cms::Exception("FailModule") << "\nEmpty RPN vector for the logical expression = " << m_logicalExpression
0055 << std::endl;
0056 }
0057
0058
0059 int rpnVectorSize = m_rpnVector.size();
0060
0061 m_algoCombinationVector.reserve(rpnVectorSize);
0062 m_operandTokenVector.reserve(rpnVectorSize);
0063
0064
0065 std::stack<bool, std::vector<bool> > resultStack;
0066 bool b1, b2;
0067
0068 int opNumber = 0;
0069
0070 for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
0071
0072
0073
0074
0075
0076 switch (it->operation) {
0077 case GlobalLogicParser::OP_OPERAND: {
0078 auto itCond = conditionResultMaps.at(chipNumber).find(it->operand);
0079 if (itCond != (conditionResultMaps[chipNumber]).end()) {
0080 if (nullptr == itCond->second) {
0081
0082 throw cms::Exception("FailModule")
0083 << "\nCondition " << (it->operand) << " NULL pointer found in condition map" << std::endl;
0084 }
0085
0086
0087 bool condResult = (itCond->second)->condLastResult();
0088
0089 resultStack.push(condResult);
0090
0091
0092
0093 OperandToken opToken;
0094 opToken.tokenName = it->operand;
0095 opToken.tokenNumber = opNumber;
0096 opToken.tokenResult = condResult;
0097
0098 m_operandTokenVector.push_back(opToken);
0099 opNumber++;
0100
0101
0102 auto const& combInCondition = (itCond->second)->getCombinationsInCond();
0103 m_algoCombinationVector.push_back(combInCondition);
0104
0105 } else {
0106
0107 throw cms::Exception("FailModule")
0108 << "\nCondition " << (it->operand) << " not found in condition map" << std::endl;
0109 }
0110
0111 }
0112
0113 break;
0114 case GlobalLogicParser::OP_NOT: {
0115 b1 = resultStack.top();
0116 resultStack.pop();
0117 resultStack.push(!b1);
0118 }
0119
0120 break;
0121 case GlobalLogicParser::OP_OR: {
0122 b1 = resultStack.top();
0123 resultStack.pop();
0124 b2 = resultStack.top();
0125 resultStack.pop();
0126 resultStack.push(b1 || b2);
0127 }
0128
0129 break;
0130 case GlobalLogicParser::OP_AND: {
0131 b1 = resultStack.top();
0132 resultStack.pop();
0133 b2 = resultStack.top();
0134 resultStack.pop();
0135 resultStack.push(b1 && b2);
0136 }
0137
0138 break;
0139 case GlobalLogicParser::OP_XOR: {
0140 b1 = resultStack.top();
0141 resultStack.pop();
0142 b2 = resultStack.top();
0143 resultStack.pop();
0144 resultStack.push(b1 ^ b2);
0145 }
0146
0147 break;
0148 default: {
0149
0150 }
0151
0152 break;
0153 }
0154 }
0155
0156
0157 m_algoResult = resultStack.top();
0158 }
0159
0160
0161 void l1t::AlgorithmEvaluation::print(std::ostream& myCout) const {
0162 myCout << std::endl;
0163
0164 myCout << " Algorithm result: " << m_algoResult << std::endl;
0165
0166 myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
0167
0168 int operandTokenVectorSize = m_operandTokenVector.size();
0169
0170 myCout << " Operand token vector size: " << operandTokenVectorSize;
0171
0172 if (operandTokenVectorSize == 0) {
0173 myCout << " - not properly initialized! " << std::endl;
0174 } else {
0175 myCout << std::endl;
0176
0177 for (int i = 0; i < operandTokenVectorSize; ++i) {
0178 myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t" << std::setw(25)
0179 << (m_operandTokenVector[i]).tokenName << "\t" << (m_operandTokenVector[i]).tokenResult << std::endl;
0180 }
0181 }
0182
0183 myCout << std::endl;
0184 }