File indexing completed on 2024-04-06 12:19:53
0001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelEnergyFpga.h"
0002 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
0003
0004 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetLeafCard.h"
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007
0008 using std::endl;
0009 using std::ostream;
0010 using std::vector;
0011
0012
0013 const unsigned int L1GctWheelEnergyFpga::MAX_LEAF_CARDS = L1GctWheelJetFpga::MAX_LEAF_CARDS;
0014
0015 L1GctWheelEnergyFpga::L1GctWheelEnergyFpga(int id, const std::vector<L1GctJetLeafCard*>& leafCards)
0016 : L1GctProcessor(),
0017 m_id(id),
0018 m_inputLeafCards(leafCards),
0019 m_inputEx(MAX_LEAF_CARDS),
0020 m_inputEy(MAX_LEAF_CARDS),
0021 m_inputEt(MAX_LEAF_CARDS),
0022 m_inputHt(MAX_LEAF_CARDS),
0023 m_outputEx(0),
0024 m_outputEy(0),
0025 m_outputEt(0),
0026 m_outputHt(0),
0027 m_setupOk(true),
0028 m_outputExPipe(),
0029 m_outputEyPipe(),
0030 m_outputEtPipe(),
0031 m_outputHtPipe() {
0032
0033 if (m_id != 0 && m_id != 1) {
0034 m_setupOk = false;
0035 if (m_verbose) {
0036 edm::LogWarning("L1GctSetupError") << "L1GctWheelEnergyFpga::L1GctWheelEnergyFpga() : Wheel Energy Fpga ID "
0037 << m_id << " has been incorrectly constructed!\n"
0038 << "ID number should be 0 or 1.\n";
0039 }
0040 }
0041
0042 if (m_inputLeafCards.size() != MAX_LEAF_CARDS) {
0043 m_setupOk = false;
0044 if (m_verbose) {
0045 edm::LogWarning("L1GctSetupError") << "L1GctWheelEnergyFpga::L1GctWheelEnergyFpga() : Wheel Energy Fpga ID "
0046 << m_id << " has been incorrectly constructed!\n"
0047 << "This class needs " << MAX_LEAF_CARDS << " leaf card pointers, yet only "
0048 << m_inputLeafCards.size() << " leaf card pointers are present.\n";
0049 }
0050 }
0051
0052 for (unsigned int i = 0; i < m_inputLeafCards.size(); ++i) {
0053 if (m_inputLeafCards.at(i) == nullptr) {
0054 m_setupOk = false;
0055 if (m_verbose) {
0056 edm::LogWarning("L1GctSetupError") << "L1GctWheelEnergyFpga::L1GctWheelEnergyFpga() : Wheel Energy Fpga ID "
0057 << m_id << " has been incorrectly constructed!\n"
0058 << "Input Leaf card pointer " << i << " has not been set!\n";
0059 }
0060 }
0061 }
0062 if (!m_setupOk && m_verbose) {
0063 edm::LogError("L1GctSetupError") << "L1GctWheelEnergyFpga has been incorrectly constructed";
0064 }
0065 }
0066
0067 L1GctWheelEnergyFpga::~L1GctWheelEnergyFpga() {}
0068
0069 ostream& operator<<(ostream& os, const L1GctWheelEnergyFpga& fpga) {
0070 os << "===L1GctWheelEnergyFPGA===" << endl;
0071 os << "ID : " << fpga.m_id << endl;
0072 os << "No. of Input Leaf Cards " << fpga.m_inputLeafCards.size() << endl;
0073 for (unsigned i = 0; i < fpga.m_inputLeafCards.size(); i++) {
0074 os << "LeafCard* " << i << " = " << fpga.m_inputLeafCards.at(i) << endl;
0075 }
0076 os << "Input Ex " << endl;
0077 for (unsigned i = 0; i < fpga.m_inputEx.size(); i++) {
0078 os << fpga.m_inputEx.at(i) << endl;
0079 }
0080 os << "Input Ey " << endl;
0081 for (unsigned i = 0; i < fpga.m_inputEy.size(); i++) {
0082 os << fpga.m_inputEy.at(i) << endl;
0083 }
0084 os << "Input Et " << endl;
0085 for (unsigned i = 0; i < fpga.m_inputEt.size(); i++) {
0086 os << fpga.m_inputEt.at(i) << endl;
0087 }
0088 os << "Input Ht " << endl;
0089 for (unsigned i = 0; i < fpga.m_inputHt.size(); i++) {
0090 os << (fpga.m_inputHt.at(i)) << endl;
0091 }
0092 os << "Output Ex " << fpga.m_outputEx << endl;
0093 os << "Output Ey " << fpga.m_outputEy << endl;
0094 os << "Output Et " << fpga.m_outputEt << endl;
0095 os << "Output Ht " << fpga.m_outputHt << endl;
0096 os << endl;
0097 return os;
0098 }
0099
0100 void L1GctWheelEnergyFpga::resetProcessor() {
0101 for (unsigned int i = 0; i < MAX_LEAF_CARDS; i++) {
0102 m_inputEx.at(i).reset();
0103 m_inputEy.at(i).reset();
0104 m_inputEt.at(i).reset();
0105 m_inputHt.at(i).reset();
0106 }
0107 m_outputEx.reset();
0108 m_outputEy.reset();
0109 m_outputEt.reset();
0110 m_outputHt.reset();
0111 }
0112
0113 void L1GctWheelEnergyFpga::resetPipelines() {
0114 m_outputExPipe.reset(numOfBx());
0115 m_outputEyPipe.reset(numOfBx());
0116 m_outputEtPipe.reset(numOfBx());
0117 m_outputHtPipe.reset(numOfBx());
0118 }
0119
0120 void L1GctWheelEnergyFpga::fetchInput() {
0121 if (m_setupOk) {
0122
0123 for (unsigned int i = 0; i < MAX_LEAF_CARDS; i++) {
0124 m_inputEx.at(i) = m_inputLeafCards.at(i)->getOutputEx();
0125 m_inputEy.at(i) = m_inputLeafCards.at(i)->getOutputEy();
0126 m_inputEt.at(i) = m_inputLeafCards.at(i)->getOutputEt();
0127 m_inputHt.at(i) = m_inputLeafCards.at(i)->getOutputHt();
0128 }
0129 }
0130 }
0131
0132 void L1GctWheelEnergyFpga::process() {
0133 if (m_setupOk) {
0134 m_outputEx = m_inputEx.at(0) + m_inputEx.at(1) + m_inputEx.at(2);
0135 m_outputEy = m_inputEy.at(0) + m_inputEy.at(1) + m_inputEy.at(2);
0136 m_outputEt = m_inputEt.at(0) + m_inputEt.at(1) + m_inputEt.at(2);
0137 m_outputHt = m_inputHt.at(0) + m_inputHt.at(1) + m_inputHt.at(2);
0138 if (m_outputEt.overFlow())
0139 m_outputEt.setValue(etTotalMaxValue);
0140 if (m_outputHt.overFlow())
0141 m_outputHt.setValue(htTotalMaxValue);
0142
0143 m_outputExPipe.store(m_outputEx, bxRel());
0144 m_outputEyPipe.store(m_outputEy, bxRel());
0145 m_outputEtPipe.store(m_outputEt, bxRel());
0146 m_outputHtPipe.store(m_outputHt, bxRel());
0147 }
0148 }
0149
0150
0151
0152 void L1GctWheelEnergyFpga::setInputEnergy(unsigned i, int ex, int ey, unsigned et, unsigned ht) {
0153
0154 if (i < MAX_LEAF_CARDS) {
0155 m_inputEx.at(i).setValue(ex);
0156 m_inputEy.at(i).setValue(ey);
0157 m_inputEt.at(i).setValue(et);
0158 m_inputHt.at(i).setValue(ht);
0159 }
0160 }
0161
0162
0163 std::vector<L1GctInternEtSum> L1GctWheelEnergyFpga::getInternalEtSums() const {
0164 std::vector<L1GctInternEtSum> result;
0165 for (int bx = 0; bx < numOfBx(); bx++) {
0166 result.push_back(L1GctInternEtSum::fromEmulatorMissEtxOrEty(m_outputExPipe.contents.at(bx).value(),
0167 m_outputExPipe.contents.at(bx).overFlow(),
0168 static_cast<int16_t>(bx - bxMin())));
0169 result.push_back(L1GctInternEtSum::fromEmulatorMissEtxOrEty(m_outputEyPipe.contents.at(bx).value(),
0170 m_outputEyPipe.contents.at(bx).overFlow(),
0171 static_cast<int16_t>(bx - bxMin())));
0172 result.push_back(L1GctInternEtSum::fromEmulatorTotalEtOrHt(m_outputEtPipe.contents.at(bx).value(),
0173 m_outputEtPipe.contents.at(bx).overFlow(),
0174 static_cast<int16_t>(bx - bxMin())));
0175 result.push_back(L1GctInternEtSum::fromEmulatorTotalEtOrHt(m_outputHtPipe.contents.at(bx).value(),
0176 m_outputHtPipe.contents.at(bx).overFlow(),
0177 static_cast<int16_t>(bx - bxMin())));
0178 }
0179 return result;
0180 }