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