Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-14 22:43:08

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1Trigger/DemonstratorTools
0004 // Class:      GTTFileWriter
0005 //
0006 /**\class GTTFileWriter GTTFileWriter.cc L1Trigger/DemonstratorTools/plugins/GTTFileWriter.cc
0007 
0008  Description: Example EDAnalyzer class, illustrating how BoardDataWriter can be used to
0009    write I/O buffer files for hardware/firmware tests
0010 
0011  Implementation:
0012      [Notes on implementation]
0013 */
0014 //
0015 // Original Author:  Thomas Williams <thomas.williams@stfc.ac.uk>
0016 //         Created:  Mon, 15 Feb 2021 00:39:44 GMT
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 #include "ap_int.h"
0024 
0025 // user include files
0026 #include "FWCore/Framework/interface/Frameworkfwd.h"
0027 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0028 
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/Utilities/interface/InputTag.h"
0034 
0035 #include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h"
0036 #include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
0037 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0038 #include "DataFormats/L1Trigger/interface/VertexWord.h"
0039 #include "DataFormats/Common/interface/View.h"
0040 
0041 #include "L1Trigger/DemonstratorTools/interface/BoardDataWriter.h"
0042 #include "L1Trigger/DemonstratorTools/interface/codecs/tracks.h"
0043 #include "L1Trigger/DemonstratorTools/interface/codecs/vertices.h"
0044 #include "L1Trigger/DemonstratorTools/interface/utilities.h"
0045 
0046 //
0047 // class declaration
0048 //
0049 
0050 class GTTFileWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0051 public:
0052   explicit GTTFileWriter(const edm::ParameterSet&);
0053 
0054   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0055 
0056 private:
0057   // ----------constants, enums and typedefs ---------
0058   // NOTE: At least some of the info from these constants will eventually come from config files
0059   static constexpr size_t kFramesPerTMUXPeriod = 9;
0060   static constexpr size_t kGapLengthInput = 6;
0061   static constexpr size_t kGapLengthOutput = 44;
0062   static constexpr size_t kTrackTMUX = 18;
0063   static constexpr size_t kGTTBoardTMUX = 6;
0064   static constexpr size_t kMaxLinesPerFile = 1024;
0065 
0066   const std::map<l1t::demo::LinkId, std::vector<size_t>> kChannelIdsInput = {
0067       /* logical channel within time slice -> vector of channel indices (one entry per time slice) */
0068       {{"tracks", 0}, {0, 18, 36}},
0069       {{"tracks", 1}, {1, 19, 37}},
0070       {{"tracks", 2}, {2, 20, 38}},
0071       {{"tracks", 3}, {3, 21, 39}},
0072       {{"tracks", 4}, {4, 22, 40}},
0073       {{"tracks", 5}, {5, 23, 41}},
0074       {{"tracks", 6}, {6, 24, 42}},
0075       {{"tracks", 7}, {7, 25, 43}},
0076       {{"tracks", 8}, {8, 26, 44}},
0077       {{"tracks", 9}, {9, 27, 45}},
0078       {{"tracks", 10}, {10, 28, 46}},
0079       {{"tracks", 11}, {11, 29, 47}},
0080       {{"tracks", 12}, {12, 30, 48}},
0081       {{"tracks", 13}, {13, 31, 49}},
0082       {{"tracks", 14}, {14, 32, 50}},
0083       {{"tracks", 15}, {15, 33, 51}},
0084       {{"tracks", 16}, {16, 34, 52}},
0085       {{"tracks", 17}, {17, 35, 53}}};
0086 
0087   const std::map<std::string, l1t::demo::ChannelSpec> kChannelSpecsInput = {
0088       /* interface name -> {link TMUX, inter-packet gap} */
0089       {"tracks", {kTrackTMUX, kGapLengthInput}}};
0090 
0091   const std::map<l1t::demo::LinkId, std::pair<l1t::demo::ChannelSpec, std::vector<size_t>>>
0092       kChannelSpecsOutputToCorrelator = {
0093           /* logical channel within time slice -> {{link TMUX, inter-packet gap}, vector of channel indices} */
0094           {{"vertices", 0}, {{kGTTBoardTMUX, kGapLengthOutput}, {0}}}};
0095 
0096   typedef TTTrack<Ref_Phase2TrackerDigi_> Track_t;
0097 
0098   // ----------member functions ----------------------
0099   void analyze(const edm::Event&, const edm::EventSetup&) override;
0100   void endJob() override;
0101 
0102   // ----------member data ---------------------------
0103   edm::EDGetTokenT<edm::View<Track_t>> tracksToken_;
0104   edm::EDGetTokenT<edm::View<Track_t>> convertedTracksToken_;
0105   edm::EDGetTokenT<edm::View<l1t::VertexWord>> verticesToken_;
0106 
0107   l1t::demo::BoardDataWriter fileWriterInputTracks_;
0108   l1t::demo::BoardDataWriter fileWriterConvertedTracks_;
0109   l1t::demo::BoardDataWriter fileWriterOutputToCorrelator_;
0110 };
0111 
0112 //
0113 // class implementation
0114 //
0115 
0116 GTTFileWriter::GTTFileWriter(const edm::ParameterSet& iConfig)
0117     : tracksToken_(consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))),
0118       convertedTracksToken_(
0119           consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("convertedTracks"))),
0120       verticesToken_(consumes<edm::View<l1t::VertexWord>>(iConfig.getUntrackedParameter<edm::InputTag>("vertices"))),
0121       fileWriterInputTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
0122                              iConfig.getUntrackedParameter<std::string>("inputFilename"),
0123                              kFramesPerTMUXPeriod,
0124                              kGTTBoardTMUX,
0125                              kMaxLinesPerFile,
0126                              kChannelIdsInput,
0127                              kChannelSpecsInput),
0128       fileWriterConvertedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
0129                                  iConfig.getUntrackedParameter<std::string>("inputConvertedFilename"),
0130                                  kFramesPerTMUXPeriod,
0131                                  kGTTBoardTMUX,
0132                                  kMaxLinesPerFile,
0133                                  kChannelIdsInput,
0134                                  kChannelSpecsInput),
0135       fileWriterOutputToCorrelator_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
0136                                     iConfig.getUntrackedParameter<std::string>("outputFilename"),
0137                                     kFramesPerTMUXPeriod,
0138                                     kGTTBoardTMUX,
0139                                     kMaxLinesPerFile,
0140                                     kChannelSpecsOutputToCorrelator) {}
0141 
0142 void GTTFileWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0143   using namespace edm;
0144   using namespace l1t::demo::codecs;
0145 
0146   // 1) Encode track information onto vectors containing link data
0147   const auto trackData(encodeTracks(iEvent.get(tracksToken_)));
0148   const auto convertedTrackData(encodeTracks(iEvent.get(convertedTracksToken_)));
0149   const auto outputData(encodeVertices(iEvent.get(verticesToken_)));
0150 
0151   // 2) Pack track information into 'event data' object, and pass that to file writer
0152   l1t::demo::EventData eventDataTracks;
0153   l1t::demo::EventData eventDataConvertedTracks;
0154   for (size_t i = 0; i < 18; i++) {
0155     eventDataTracks.add({"tracks", i}, trackData.at(i));
0156     eventDataConvertedTracks.add({"tracks", i}, convertedTrackData.at(i));
0157   }
0158 
0159   l1t::demo::EventData eventDataVertices;
0160   eventDataVertices.add({"vertices", 0}, outputData.at(0));
0161 
0162   fileWriterInputTracks_.addEvent(eventDataTracks);
0163   fileWriterConvertedTracks_.addEvent(eventDataConvertedTracks);
0164   fileWriterOutputToCorrelator_.addEvent(eventDataVertices);
0165 }
0166 
0167 // ------------ method called once each job just after ending the event loop  ------------
0168 void GTTFileWriter::endJob() {
0169   // Writing pending events to file before exiting
0170   fileWriterInputTracks_.flush();
0171   fileWriterConvertedTracks_.flush();
0172   fileWriterOutputToCorrelator_.flush();
0173 }
0174 
0175 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0176 void GTTFileWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0177   // GTTFileWriter
0178   edm::ParameterSetDescription desc;
0179   desc.addUntracked<edm::InputTag>("tracks", edm::InputTag("l1tTTTracksFromTrackletEmulation", "Level1TTTracks"));
0180   desc.addUntracked<edm::InputTag>("convertedTracks", edm::InputTag("l1tGTTInputProducer", "Level1TTTracksConverted"));
0181   desc.addUntracked<edm::InputTag>("vertices", edm::InputTag("l1tVertexProducer", "l1verticesEmulation"));
0182   desc.addUntracked<std::string>("inputFilename", "L1GTTInputFile");
0183   desc.addUntracked<std::string>("inputConvertedFilename", "L1GTTInputConvertedFile");
0184   desc.addUntracked<std::string>("outputFilename", "L1GTTOutputToCorrelatorFile");
0185   desc.addUntracked<std::string>("format", "APx");
0186   descriptions.add("GTTFileWriter", desc);
0187 }
0188 
0189 //define this as a plug-in
0190 DEFINE_FWK_MODULE(GTTFileWriter);