CMS 3D CMS Logo

GTTFileWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/DemonstratorTools
4 // Class: GTTFileWriter
5 //
14 //
15 // Original Author: Thomas Williams <thomas.williams@stfc.ac.uk>
16 // Created: Mon, 15 Feb 2021 00:39:44 GMT
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 #include "ap_int.h"
24 
25 // user include files
28 
31 
34 
40 
45 
46 //
47 // class declaration
48 //
49 
50 class GTTFileWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
51 public:
52  explicit GTTFileWriter(const edm::ParameterSet&);
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  // ----------constants, enums and typedefs ---------
58  // NOTE: At least some of the info from these constants will eventually come from config files
59  static constexpr size_t kFramesPerTMUXPeriod = 9;
60  static constexpr size_t kGapLengthInput = 6;
61  static constexpr size_t kGapLengthOutput = 44;
62  static constexpr size_t kTrackTMUX = 18;
63  static constexpr size_t kGTTBoardTMUX = 6;
64  static constexpr size_t kMaxLinesPerFile = 1024;
65 
66  const std::map<l1t::demo::LinkId, std::vector<size_t>> kChannelIdsInput = {
67  /* logical channel within time slice -> vector of channel indices (one entry per time slice) */
68  {{"tracks", 0}, {0, 18, 36}},
69  {{"tracks", 1}, {1, 19, 37}},
70  {{"tracks", 2}, {2, 20, 38}},
71  {{"tracks", 3}, {3, 21, 39}},
72  {{"tracks", 4}, {4, 22, 40}},
73  {{"tracks", 5}, {5, 23, 41}},
74  {{"tracks", 6}, {6, 24, 42}},
75  {{"tracks", 7}, {7, 25, 43}},
76  {{"tracks", 8}, {8, 26, 44}},
77  {{"tracks", 9}, {9, 27, 45}},
78  {{"tracks", 10}, {10, 28, 46}},
79  {{"tracks", 11}, {11, 29, 47}},
80  {{"tracks", 12}, {12, 30, 48}},
81  {{"tracks", 13}, {13, 31, 49}},
82  {{"tracks", 14}, {14, 32, 50}},
83  {{"tracks", 15}, {15, 33, 51}},
84  {{"tracks", 16}, {16, 34, 52}},
85  {{"tracks", 17}, {17, 35, 53}}};
86 
87  const std::map<std::string, l1t::demo::ChannelSpec> kChannelSpecsInput = {
88  /* interface name -> {link TMUX, inter-packet gap} */
89  {"tracks", {kTrackTMUX, kGapLengthInput}}};
90 
91  const std::map<l1t::demo::LinkId, std::pair<l1t::demo::ChannelSpec, std::vector<size_t>>>
93  /* logical channel within time slice -> {{link TMUX, inter-packet gap}, vector of channel indices} */
94  {{"vertices", 0}, {{kGTTBoardTMUX, kGapLengthOutput}, {0}}}};
95 
97 
98  // ----------member functions ----------------------
99  void analyze(const edm::Event&, const edm::EventSetup&) override;
100  void endJob() override;
101 
102  // ----------member data ---------------------------
106 
110 };
111 
112 //
113 // class implementation
114 //
115 
117  : tracksToken_(consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))),
118  convertedTracksToken_(
119  consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("convertedTracks"))),
120  verticesToken_(consumes<edm::View<l1t::VertexWord>>(iConfig.getUntrackedParameter<edm::InputTag>("vertices"))),
121  fileWriterInputTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
122  iConfig.getUntrackedParameter<std::string>("inputFilename"),
123  kFramesPerTMUXPeriod,
124  kGTTBoardTMUX,
125  kMaxLinesPerFile,
126  kChannelIdsInput,
127  kChannelSpecsInput),
128  fileWriterConvertedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
129  iConfig.getUntrackedParameter<std::string>("inputConvertedFilename"),
130  kFramesPerTMUXPeriod,
131  kGTTBoardTMUX,
132  kMaxLinesPerFile,
133  kChannelIdsInput,
134  kChannelSpecsInput),
135  fileWriterOutputToCorrelator_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
136  iConfig.getUntrackedParameter<std::string>("outputFilename"),
137  kFramesPerTMUXPeriod,
138  kGTTBoardTMUX,
139  kMaxLinesPerFile,
140  kChannelSpecsOutputToCorrelator) {}
141 
143  using namespace edm;
144  using namespace l1t::demo::codecs;
145 
146  // 1) Encode track information onto vectors containing link data
147  const auto trackData(encodeTracks(iEvent.get(tracksToken_)));
148  const auto convertedTrackData(encodeTracks(iEvent.get(convertedTracksToken_)));
149  const auto outputData(encodeVertices(iEvent.get(verticesToken_)));
150 
151  // 2) Pack track information into 'event data' object, and pass that to file writer
152  l1t::demo::EventData eventDataTracks;
153  l1t::demo::EventData eventDataConvertedTracks;
154  for (size_t i = 0; i < 18; i++) {
155  eventDataTracks.add({"tracks", i}, trackData.at(i));
156  eventDataConvertedTracks.add({"tracks", i}, convertedTrackData.at(i));
157  }
158 
159  l1t::demo::EventData eventDataVertices;
160  eventDataVertices.add({"vertices", 0}, outputData.at(0));
161 
162  fileWriterInputTracks_.addEvent(eventDataTracks);
163  fileWriterConvertedTracks_.addEvent(eventDataConvertedTracks);
164  fileWriterOutputToCorrelator_.addEvent(eventDataVertices);
165 }
166 
167 // ------------ method called once each job just after ending the event loop ------------
169  // Writing pending events to file before exiting
173 }
174 
175 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
177  // GTTFileWriter
179  desc.addUntracked<edm::InputTag>("tracks", edm::InputTag("TTTracksFromTrackletEmulation", "Level1TTTracks"));
180  desc.addUntracked<edm::InputTag>("convertedTracks", edm::InputTag("L1GTTInputProducer", "Level1TTTracksConverted"));
181  desc.addUntracked<edm::InputTag>("vertices", edm::InputTag("VertexProducer", "l1verticesEmulation"));
182  desc.addUntracked<std::string>("inputFilename", "L1GTTInputFile");
183  desc.addUntracked<std::string>("inputConvertedFilename", "L1GTTInputConvertedFile");
184  desc.addUntracked<std::string>("outputFilename", "L1GTTOutputToCorrelatorFile");
185  desc.addUntracked<std::string>("format", "APx");
186  descriptions.add("GTTFileWriter", desc);
187 }
188 
189 //define this as a plug-in
static constexpr size_t kTrackTMUX
l1t::demo::BoardDataWriter fileWriterOutputToCorrelator_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addEvent(const EventData &data)
FileFormat parseFileFormat(const std::string &)
Definition: utilities.cc:70
delete x;
Definition: CaloConfig.h:22
edm::EDGetTokenT< edm::View< l1t::VertexWord > > verticesToken_
void add(const LinkId &, const std::vector< ap_uint< 64 >> &)
Definition: EventData.cc:14
static constexpr size_t kGapLengthOutput
std::array< std::vector< ap_uint< 64 > >, 18 > encodeTracks(const edm::View< TTTrack< Ref_Phase2TrackerDigi_ >> &, int debug=0)
Definition: codecs_tracks.cc:9
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::View< Track_t > > tracksToken_
static constexpr size_t kMaxLinesPerFile
GTTFileWriter(const edm::ParameterSet &)
static constexpr size_t kFramesPerTMUXPeriod
TTTrack< Ref_Phase2TrackerDigi_ > Track_t
l1t::demo::BoardDataWriter fileWriterInputTracks_
const std::map< l1t::demo::LinkId, std::pair< l1t::demo::ChannelSpec, std::vector< size_t > > > kChannelSpecsOutputToCorrelator
edm::EDGetTokenT< edm::View< Track_t > > convertedTracksToken_
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
std::array< std::vector< ap_uint< 64 > >, 1 > encodeVertices(const edm::View< l1t::VertexWord > &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::map< l1t::demo::LinkId, std::vector< size_t > > kChannelIdsInput
const std::map< std::string, l1t::demo::ChannelSpec > kChannelSpecsInput
HLT enums.
static constexpr size_t kGTTBoardTMUX
static constexpr size_t kGapLengthInput
Class representing information phase-2 ATCA I/O data corresponding to a single event, with logical channel IDs (essentially string-uint pairs, e.g. tracks-0 to tracks-17).
Definition: EventData.h:28
l1t::demo::BoardDataWriter fileWriterConvertedTracks_
void analyze(const edm::Event &, const edm::EventSetup &) override