File indexing completed on 2024-04-06 12:20:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include "L1Trigger/L1TGlobal/interface/GlobalAlgorithm.h"
0019
0020
0021 #include <iostream>
0022 #include <iomanip>
0023
0024
0025
0026
0027
0028
0029
0030 GlobalAlgorithm::GlobalAlgorithm() {
0031
0032
0033 m_algoBitNumber = -1;
0034 m_algoChipNumber = -1;
0035 }
0036
0037
0038 GlobalAlgorithm::GlobalAlgorithm(const std::string& algoNameValue) : m_algoName(algoNameValue) {
0039
0040
0041 m_algoBitNumber = -1;
0042 m_algoChipNumber = -1;
0043 }
0044
0045
0046 GlobalAlgorithm::GlobalAlgorithm(const std::string& algoNameValue, const std::string& algoLogicalExpressionValue)
0047 : m_algoName(algoNameValue), m_algoLogicalExpression(algoLogicalExpressionValue) {
0048 GlobalLogicParser logicParser(m_algoLogicalExpression);
0049 m_algoRpnVector = logicParser.rpnVector();
0050
0051
0052 m_algoBitNumber = -1;
0053 m_algoChipNumber = -1;
0054 }
0055
0056
0057 GlobalAlgorithm::GlobalAlgorithm(const std::string& algoNameValue,
0058 const std::string& algoLogicalExpressionValue,
0059 const int algoBitNumberValue)
0060 : m_algoName(algoNameValue),
0061 m_algoLogicalExpression(algoLogicalExpressionValue),
0062 m_algoBitNumber(algoBitNumberValue)
0063
0064 {
0065 GlobalLogicParser logicParser(m_algoLogicalExpression);
0066 m_algoRpnVector = logicParser.rpnVector();
0067
0068
0069 m_algoChipNumber = -1;
0070 }
0071
0072
0073 GlobalAlgorithm::~GlobalAlgorithm() {
0074
0075 }
0076
0077
0078
0079
0080 const int GlobalAlgorithm::algoChipNumber(const int numberConditionChips,
0081 const int pinsOnConditionChip,
0082 const std::vector<int>& orderConditionChip) const {
0083 int posChip = (m_algoBitNumber / pinsOnConditionChip) + 1;
0084 for (int iChip = 0; iChip < numberConditionChips; ++iChip) {
0085 if (posChip == orderConditionChip[iChip]) {
0086 return iChip;
0087 }
0088 }
0089
0090
0091 return -1;
0092 }
0093
0094
0095 const int GlobalAlgorithm::algoOutputPin(const int numberConditionChips,
0096 const int pinsOnConditionChip,
0097 const std::vector<int>& orderConditionChip) const {
0098 int iChip = algoChipNumber(numberConditionChips, pinsOnConditionChip, orderConditionChip);
0099
0100 int outputPin = m_algoBitNumber - (orderConditionChip[iChip] - 1) * pinsOnConditionChip + 1;
0101
0102 return outputPin;
0103 }
0104
0105
0106 void GlobalAlgorithm::print(std::ostream& myCout) const {
0107 myCout << std::endl;
0108
0109 myCout << " Algorithm name: " << m_algoName << std::endl;
0110 myCout << " Algorithm alias: " << m_algoAlias << std::endl;
0111
0112 myCout << " Bit number: " << m_algoBitNumber;
0113 if (m_algoBitNumber < 0) {
0114 myCout << " - not properly initialized! " << std::endl;
0115 } else {
0116 myCout << std::endl;
0117 }
0118
0119 myCout << " Located on chip number: " << m_algoChipNumber;
0120 if (m_algoChipNumber < 0) {
0121 myCout << " - not properly initialized! " << std::endl;
0122 } else {
0123 myCout << std::endl;
0124 }
0125
0126 myCout << " Logical expresssion: " << m_algoLogicalExpression << std::endl;
0127
0128 int rpnVectorSize = m_algoRpnVector.size();
0129
0130 myCout << " RPN vector size: " << rpnVectorSize;
0131
0132 if (rpnVectorSize == 0) {
0133 myCout << " - not properly initialized! " << std::endl;
0134 } else {
0135 myCout << std::endl;
0136
0137 for (int i = 0; i < rpnVectorSize; ++i) {
0138 myCout << " ( " << (m_algoRpnVector[i]).operation << ", " << (m_algoRpnVector[i]).operand << " )"
0139 << std::endl;
0140 }
0141 }
0142
0143 myCout << std::endl;
0144 }
0145
0146
0147 std::ostream& operator<<(std::ostream& os, const GlobalAlgorithm& result) {
0148 result.print(os);
0149 return os;
0150 }