File indexing completed on 2024-07-03 04:18:03
0001
0002
0003
0004
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0007
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014
0015 #include "L1Trigger/DemonstratorTools/interface/BoardDataWriter.h"
0016 #include "L1Trigger/DemonstratorTools/interface/utilities.h"
0017
0018 #include "FWCore/Utilities/interface/EDGetToken.h"
0019
0020 #include "DataFormats/L1Trigger/interface/P2GTAlgoBlock.h"
0021
0022 #include "ap_int.h"
0023
0024 #include <vector>
0025 #include <algorithm>
0026 #include <string>
0027
0028 using namespace l1t;
0029
0030 class L1GTFinOrBoardWriter : public edm::one::EDAnalyzer<> {
0031 public:
0032 explicit L1GTFinOrBoardWriter(const edm::ParameterSet&);
0033
0034 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0035
0036 private:
0037 void analyze(const edm::Event&, const edm::EventSetup&) override;
0038 void endJob() override;
0039
0040 const std::array<unsigned int, 3> channelsLow_;
0041 const std::array<unsigned int, 3> channelsMid_;
0042 const std::array<unsigned int, 3> channelsHigh_;
0043 const unsigned int channelFinOr_;
0044 const edm::EDGetTokenT<P2GTAlgoBlockMap> algoBlocksToken_;
0045 l1t::demo::BoardDataWriter boardDataWriter_;
0046
0047 std::map<l1t::demo::LinkId, std::vector<ap_uint<64>>> linkData_;
0048 std::size_t tmuxCounter_;
0049 };
0050
0051 L1GTFinOrBoardWriter::L1GTFinOrBoardWriter(const edm::ParameterSet& config)
0052 : channelsLow_(config.getParameter<std::array<unsigned int, 3>>("channelsLow")),
0053 channelsMid_(config.getParameter<std::array<unsigned int, 3>>("channelsMid")),
0054 channelsHigh_(config.getParameter<std::array<unsigned int, 3>>("channelsHigh")),
0055 channelFinOr_(config.getParameter<unsigned int>("channelFinOr")),
0056 algoBlocksToken_(consumes<P2GTAlgoBlockMap>(config.getParameter<edm::InputTag>("algoBlocksTag"))),
0057 boardDataWriter_(l1t::demo::parseFileFormat(config.getParameter<std::string>("patternFormat")),
0058 config.getParameter<std::string>("outputFilename"),
0059 config.getParameter<std::string>("outputFileExtension"),
0060 9,
0061 2,
0062 config.getParameter<unsigned int>("maxLines"),
0063 [&]() {
0064 l1t::demo::BoardDataWriter::ChannelMap_t channelMap;
0065 channelMap.insert({l1t::demo::LinkId{"BeforeBxMaskAndPrescaleLow", channelsLow_[0]},
0066 {l1t::demo::ChannelSpec{2, 0, 0}, {channelsLow_[0]}}});
0067 channelMap.insert({l1t::demo::LinkId{"BeforePrescaleLow", channelsLow_[1]},
0068 {l1t::demo::ChannelSpec{2, 0, 0}, {channelsLow_[1]}}});
0069 channelMap.insert({l1t::demo::LinkId{"FinalLow", channelsLow_[2]},
0070 {l1t::demo::ChannelSpec{2, 0, 0}, {channelsLow_[2]}}});
0071
0072 channelMap.insert({l1t::demo::LinkId{"BeforeBxMaskAndPrescaleMid", channelsMid_[0]},
0073 {l1t::demo::ChannelSpec{2, 0, 0}, {channelsMid_[0]}}});
0074 channelMap.insert({l1t::demo::LinkId{"BeforePrescaleMid", channelsMid_[1]},
0075 {l1t::demo::ChannelSpec{2, 0, 0}, {channelsMid_[1]}}});
0076 channelMap.insert({l1t::demo::LinkId{"FinalMid", channelsMid_[2]},
0077 {l1t::demo::ChannelSpec{2, 0, 0}, {channelsMid_[2]}}});
0078
0079 channelMap.insert({l1t::demo::LinkId{"BeforeBxMaskAndPrescaleHigh", channelsHigh_[0]},
0080 {l1t::demo::ChannelSpec{2, 0, 0}, {channelsHigh_[0]}}});
0081 channelMap.insert({l1t::demo::LinkId{"BeforePrescaleHigh", channelsHigh_[1]},
0082 {l1t::demo::ChannelSpec{2, 0, 0}, {channelsHigh_[1]}}});
0083 channelMap.insert({l1t::demo::LinkId{"FinalHigh", channelsHigh_[2]},
0084 {l1t::demo::ChannelSpec{2, 0, 0}, {channelsHigh_[2]}}});
0085
0086 channelMap.insert({l1t::demo::LinkId{"FinOr", channelFinOr_},
0087 {l1t::demo::ChannelSpec{2, 0, 0}, {channelFinOr_}}});
0088
0089 return channelMap;
0090 }()),
0091 linkData_(),
0092 tmuxCounter_(0) {}
0093
0094 void L1GTFinOrBoardWriter::analyze(const edm::Event& event, const edm::EventSetup& iSetup) {
0095 const P2GTAlgoBlockMap& algoBlocks = event.get(algoBlocksToken_);
0096
0097 auto algoBlockIt = algoBlocks.begin();
0098
0099 if (tmuxCounter_ == 0) {
0100 linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleLow", channelsLow_[0]}] = std::vector<ap_uint<64>>(18, 0);
0101 linkData_[l1t::demo::LinkId{"BeforePrescaleLow", channelsLow_[1]}] = std::vector<ap_uint<64>>(18, 0);
0102 linkData_[l1t::demo::LinkId{"FinalLow", channelsLow_[2]}] = std::vector<ap_uint<64>>(18, 0);
0103 linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleMid", channelsMid_[0]}] = std::vector<ap_uint<64>>(18, 0);
0104 linkData_[l1t::demo::LinkId{"BeforePrescaleMid", channelsMid_[1]}] = std::vector<ap_uint<64>>(18, 0);
0105 linkData_[l1t::demo::LinkId{"FinalMid", channelsMid_[2]}] = std::vector<ap_uint<64>>(18, 0);
0106 linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleHigh", channelsHigh_[0]}] = std::vector<ap_uint<64>>(18, 0);
0107 linkData_[l1t::demo::LinkId{"BeforePrescaleHigh", channelsHigh_[1]}] = std::vector<ap_uint<64>>(18, 0);
0108 linkData_[l1t::demo::LinkId{"FinalHigh", channelsHigh_[2]}] = std::vector<ap_uint<64>>(18, 0);
0109 linkData_[l1t::demo::LinkId{"FinOr", channelFinOr_}] = std::vector<ap_uint<64>>(18, 0);
0110 }
0111
0112 for (std::size_t word = 0; word < 9; word++) {
0113 for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
0114 auto& [alogName, algoBlock] = *algoBlockIt;
0115 linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleLow", channelsLow_[0]}][word + tmuxCounter_ * 9].set(
0116 idx, algoBlock.decisionBeforeBxMaskAndPrescale());
0117 linkData_[l1t::demo::LinkId{"BeforePrescaleLow", channelsLow_[1]}][word + tmuxCounter_ * 9].set(
0118 idx, algoBlock.decisionBeforePrescale());
0119 linkData_[l1t::demo::LinkId{"FinalLow", channelsLow_[2]}][word + tmuxCounter_ * 9].set(idx,
0120 algoBlock.decisionFinal());
0121 }
0122 }
0123
0124 for (std::size_t word = 0; word < 9; word++) {
0125 for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
0126 auto& [alogName, algoBlock] = *algoBlockIt;
0127 linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleMid", channelsMid_[0]}][word + tmuxCounter_ * 9].set(
0128 idx, algoBlock.decisionBeforeBxMaskAndPrescale());
0129 linkData_[l1t::demo::LinkId{"BeforePrescaleMid", channelsMid_[1]}][word + tmuxCounter_ * 9].set(
0130 idx, algoBlock.decisionBeforePrescale());
0131 linkData_[l1t::demo::LinkId{"FinalMid", channelsMid_[2]}][word + tmuxCounter_ * 9].set(idx,
0132 algoBlock.decisionFinal());
0133 }
0134 }
0135
0136 for (std::size_t word = 0; word < 9; word++) {
0137 for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
0138 auto& [algoName, algoBlock] = *algoBlockIt;
0139 linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleHigh", channelsHigh_[0]}][word + tmuxCounter_ * 9].set(
0140 idx, algoBlock.decisionBeforeBxMaskAndPrescale());
0141 linkData_[l1t::demo::LinkId{"BeforePrescaleHigh", channelsHigh_[1]}][word + tmuxCounter_ * 9].set(
0142 idx, algoBlock.decisionBeforePrescale());
0143 linkData_[l1t::demo::LinkId{"FinalHigh", channelsHigh_[2]}][word + tmuxCounter_ * 9].set(
0144 idx, algoBlock.decisionFinal());
0145 }
0146 }
0147
0148 bool vetoed = false, vetoedPreview = false;
0149 int finOrByTypes = 0, finOrPreviewByTypes = 0;
0150 for (auto algoBlockIt = algoBlocks.begin(); algoBlockIt != algoBlocks.end(); algoBlockIt++) {
0151 auto& [alogName, algoBlock] = *algoBlockIt;
0152 vetoed |= (algoBlock.isVeto() && algoBlock.decisionFinal());
0153 vetoedPreview |= (algoBlock.isVeto() && algoBlock.decisionFinalPreview());
0154 finOrByTypes |= algoBlock.decisionFinal() ? algoBlock.triggerTypes() : 0;
0155 finOrPreviewByTypes |= algoBlock.decisionFinalPreview() ? algoBlock.triggerTypes() : 0;
0156 }
0157
0158
0159 ap_uint<64> finOrBits(0);
0160 finOrBits(7, 0) = finOrByTypes;
0161 finOrBits(15, 8) = finOrPreviewByTypes;
0162 finOrBits(23, 16) = vetoed ? 0 : finOrByTypes;
0163 finOrBits(31, 24) = vetoedPreview ? 0 : finOrPreviewByTypes;
0164
0165 linkData_[l1t::demo::LinkId{"FinOr", channelFinOr_}][0 + tmuxCounter_ * 9] = finOrBits;
0166
0167 if (tmuxCounter_ == 1) {
0168 boardDataWriter_.addEvent(l1t::demo::EventData(linkData_));
0169 }
0170
0171 tmuxCounter_ = (tmuxCounter_ + 1) % 2;
0172 }
0173
0174 void L1GTFinOrBoardWriter::endJob() {
0175 if (tmuxCounter_ == 1) {
0176 boardDataWriter_.addEvent(l1t::demo::EventData(linkData_));
0177 }
0178
0179 boardDataWriter_.flush();
0180 }
0181
0182 void L1GTFinOrBoardWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0183 edm::ParameterSetDescription desc;
0184 desc.add<std::string>("outputFilename");
0185 desc.add<std::string>("outputFileExtension", "txt");
0186 desc.add<edm::InputTag>("algoBlocksTag");
0187 desc.add<std::vector<unsigned int>>("channelsLow");
0188 desc.add<std::vector<unsigned int>>("channelsMid");
0189 desc.add<std::vector<unsigned int>>("channelsHigh");
0190 desc.add<unsigned int>("channelFinOr");
0191 desc.add<unsigned int>("maxLines", 1024);
0192 desc.add<std::string>("patternFormat", "EMPv2");
0193
0194 descriptions.addDefault(desc);
0195 }
0196
0197 DEFINE_FWK_MODULE(L1GTFinOrBoardWriter);