Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-03 04:18:02

0001 /**
0002  * AlgoBoardDataWriter for validation with hardware.
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 L1GTAlgoBoardWriter : public edm::one::EDAnalyzer<> {
0031 public:
0032   explicit L1GTAlgoBoardWriter(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, 2> channels_;
0041   const std::array<unsigned long long, 9> algoBitMask_;
0042   const edm::EDGetTokenT<P2GTAlgoBlockMap> algoBlocksToken_;
0043   l1t::demo::BoardDataWriter boardDataWriter_;
0044 
0045   std::map<l1t::demo::LinkId, std::vector<ap_uint<64>>> linkData_;
0046   std::size_t tmuxCounter_;
0047 };
0048 
0049 L1GTAlgoBoardWriter::L1GTAlgoBoardWriter(const edm::ParameterSet& config)
0050     : channels_(config.getParameter<std::array<unsigned int, 2>>("channels")),
0051       algoBitMask_(config.getParameter<std::array<unsigned long long, 9>>("algoBitMask")),
0052       algoBlocksToken_(consumes<P2GTAlgoBlockMap>(config.getParameter<edm::InputTag>("algoBlocksTag"))),
0053       boardDataWriter_(
0054           l1t::demo::parseFileFormat(config.getParameter<std::string>("patternFormat")),
0055           config.getParameter<std::string>("outputFilename"),
0056           config.getParameter<std::string>("outputFileExtension"),
0057           9,
0058           2,
0059           config.getParameter<unsigned int>("maxLines"),
0060           [](const std::array<unsigned int, 2>& channels) {
0061             l1t::demo::BoardDataWriter::ChannelMap_t channelMap;
0062             for (unsigned int channel : channels) {
0063               channelMap.insert({l1t::demo::LinkId{"Algos", channel}, {l1t::demo::ChannelSpec{2, 0, 0}, {channel}}});
0064             }
0065             return channelMap;
0066           }(channels_)),
0067       linkData_(),
0068       tmuxCounter_(0) {}
0069 
0070 void L1GTAlgoBoardWriter::analyze(const edm::Event& event, const edm::EventSetup& iSetup) {
0071   const P2GTAlgoBlockMap& algoBlocks = event.get(algoBlocksToken_);
0072 
0073   auto algoBlockIt = algoBlocks.begin();
0074   auto algoMaskIt = algoBitMask_.begin();
0075 
0076   for (unsigned int channel : channels_) {
0077     if (tmuxCounter_ == 0) {
0078       linkData_[{"Algos", channel}] = std::vector<ap_uint<64>>(18, 0);
0079     }
0080 
0081     for (std::size_t word = 0; word < 9; word++) {
0082       ap_uint<64> mask = algoMaskIt != algoBitMask_.end() ? *algoMaskIt++ : ~static_cast<unsigned long long>(0);
0083 
0084       for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
0085         auto& [algoName, algoBlock] = *algoBlockIt;
0086         linkData_[{"Algos", channel}][word + tmuxCounter_ * 9].set(
0087             idx, algoBlock.decisionBeforeBxMaskAndPrescale() && mask.bit(idx));
0088       }
0089     }
0090   }
0091 
0092   if (tmuxCounter_ == 1) {
0093     boardDataWriter_.addEvent(l1t::demo::EventData(linkData_));
0094   }
0095 
0096   tmuxCounter_ = (tmuxCounter_ + 1) % 2;
0097 }
0098 
0099 void L1GTAlgoBoardWriter::endJob() {
0100   if (tmuxCounter_ == 1) {
0101     boardDataWriter_.addEvent(l1t::demo::EventData(linkData_));
0102   }
0103 
0104   boardDataWriter_.flush();
0105 }
0106 
0107 void L1GTAlgoBoardWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0108   edm::ParameterSetDescription desc;
0109   desc.add<std::string>("outputFilename");
0110   desc.add<std::string>("outputFileExtension", "txt");
0111   desc.add<edm::InputTag>("algoBlocksTag");
0112   desc.add<std::vector<unsigned int>>("channels");
0113   desc.add<std::vector<unsigned long long>>("algoBitMask",
0114                                             {0xffffffffffffffffull,
0115                                              0xffffffffffffffffull,
0116                                              0xffffffffffffffffull,
0117                                              0xffffffffffffffffull,
0118                                              0xffffffffffffffffull,
0119                                              0xffffffffffffffffull,
0120                                              0xffffffffffffffffull,
0121                                              0xffffffffffffffffull,
0122                                              0xffffffffffffffffull});
0123   desc.add<unsigned int>("maxLines", 1024);
0124   desc.add<std::string>("patternFormat", "EMPv2");
0125 
0126   descriptions.addDefault(desc);
0127 }
0128 
0129 DEFINE_FWK_MODULE(L1GTAlgoBoardWriter);