Go to the documentation of this file.00001
00017
00018 #include "L1Trigger/GlobalTrigger/interface/L1GtAlgorithmEvaluation.h"
00019
00020
00021 #include <string>
00022
00023 #include <stack>
00024 #include <queue>
00025 #include <vector>
00026
00027 #include <iostream>
00028 #include <iomanip>
00029
00030 #include <boost/algorithm/string.hpp>
00031 #include <ext/hash_map>
00032
00033
00034
00035
00036 #include "DataFormats/L1GlobalTrigger/interface/L1GtLogicParser.h"
00037
00038
00039 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapFwd.h"
00040 #include "CondFormats/L1TObjects/interface/L1GtAlgorithm.h"
00041
00042 #include "L1Trigger/GlobalTrigger/interface/L1GtConditionEvaluation.h"
00043
00044 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00045 #include "FWCore/Utilities/interface/Exception.h"
00046
00047
00048 L1GtAlgorithmEvaluation::L1GtAlgorithmEvaluation() :
00049 L1GtLogicParser() {
00050
00051 m_algoResult = false;
00052
00053
00054 }
00055
00057 L1GtAlgorithmEvaluation::L1GtAlgorithmEvaluation(const L1GtAlgorithm& alg) :
00058 L1GtLogicParser() {
00059
00060 m_logicalExpression = alg.algoLogicalExpression();
00061 m_rpnVector = alg.algoRpnVector();
00062
00063 m_algoResult = false;
00064
00065
00066
00067 }
00068
00069
00070 L1GtAlgorithmEvaluation::L1GtAlgorithmEvaluation(L1GtAlgorithmEvaluation& cp) {
00071
00072
00073 m_logicalExpression = cp.logicalExpression();
00074 RpnVector m_rpnVector = cp.rpnVector();
00075
00076
00077 m_algoResult = cp.gtAlgoResult();
00078 m_algoCombinationVector = *(cp.gtAlgoCombinationVector());
00079
00080 }
00081
00082
00083 L1GtAlgorithmEvaluation::~L1GtAlgorithmEvaluation() {
00084
00085
00086
00087 }
00088
00089
00090
00092 void L1GtAlgorithmEvaluation::evaluateAlgorithm(const int chipNumber,
00093 const std::vector<ConditionEvaluationMap>& conditionResultMaps) {
00094
00095
00096 if (m_rpnVector.empty() ) {
00097 m_algoResult = false;
00098
00099
00100 throw cms::Exception("FailModule")
00101 << "\nEmpty RPN vector for the logical expression = "
00102 << m_logicalExpression
00103 << std::endl;
00104
00105 }
00106
00107
00108 int rpnVectorSize = m_rpnVector.size();
00109
00110 m_algoCombinationVector.reserve(rpnVectorSize);
00111 m_operandTokenVector.reserve(rpnVectorSize);
00112
00113
00114 std::stack<bool> resultStack;
00115 bool b1, b2;
00116
00117 int opNumber = 0;
00118
00119 for (RpnVector::const_iterator it = m_rpnVector.begin(); it != m_rpnVector.end(); it++) {
00120
00121
00122
00123
00124
00125
00126 switch (it->operation) {
00127
00128 case OP_OPERAND: {
00129
00130 CItEvalMap itCond = (conditionResultMaps.at(chipNumber)).find(it->operand);
00131 if (itCond != (conditionResultMaps[chipNumber]).end()) {
00132
00133
00134 bool condResult = (itCond->second)->condLastResult();
00135
00136 resultStack.push(condResult);
00137
00138
00139
00140 OperandToken opToken;
00141 opToken.tokenName = it->operand;
00142 opToken.tokenNumber = opNumber;
00143 opToken.tokenResult = condResult;
00144
00145 m_operandTokenVector.push_back(opToken);
00146 opNumber++;
00147
00148
00149 CombinationsInCond* combInCondition = (itCond->second)->getCombinationsInCond();
00150 m_algoCombinationVector.push_back(*combInCondition);
00151
00152 }
00153 else {
00154
00155
00156 throw cms::Exception("FailModule")
00157 << "\nCondition " << (it->operand) << " not found in condition map"
00158 << std::endl;
00159
00160 }
00161
00162 }
00163
00164 break;
00165 case OP_NOT: {
00166 b1 = resultStack.top();
00167 resultStack.pop();
00168 resultStack.push(!b1);
00169 }
00170
00171 break;
00172 case OP_OR: {
00173 b1 = resultStack.top();
00174 resultStack.pop();
00175 b2 = resultStack.top();
00176 resultStack.pop();
00177 resultStack.push(b1 || b2);
00178 }
00179
00180 break;
00181 case OP_AND: {
00182 b1 = resultStack.top();
00183 resultStack.pop();
00184 b2 = resultStack.top();
00185 resultStack.pop();
00186 resultStack.push(b1 && b2);
00187 }
00188
00189 break;
00190 default: {
00191
00192 }
00193
00194 break;
00195 }
00196
00197 }
00198
00199
00200
00201 m_algoResult = resultStack.top();
00202
00203
00204 }
00205
00206
00207 void L1GtAlgorithmEvaluation::print(std::ostream& myCout) const {
00208
00209 myCout << std::endl;
00210
00211 myCout << " Algorithm result: " << m_algoResult << std::endl;
00212
00213 myCout << " CombinationVector size: " << m_algoCombinationVector.size() << std::endl;
00214
00215 int operandTokenVectorSize = m_operandTokenVector.size();
00216
00217 myCout << " Operand token vector size: " << operandTokenVectorSize;
00218
00219 if (operandTokenVectorSize == 0) {
00220 myCout << " - not properly initialized! " << std::endl;
00221 }
00222 else {
00223 myCout << std::endl;
00224
00225 for (int i = 0; i < operandTokenVectorSize; ++i) {
00226
00227 myCout << " " << std::setw(5) << (m_operandTokenVector[i]).tokenNumber << "\t"
00228 << std::setw(25) << (m_operandTokenVector[i]).tokenName << "\t"
00229 << (m_operandTokenVector[i]).tokenResult
00230 << std::endl;
00231
00232 }
00233
00234 }
00235
00236 myCout << std::endl;
00237 }
00238