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 
43 
51 
52 //
53 // class declaration
54 //
55 
56 class GTTFileWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
57 public:
58  explicit GTTFileWriter(const edm::ParameterSet&);
59 
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61 
62 private:
63  // ----------constants, enums and typedefs ---------
64  // NOTE: At least some of the info from these constants will eventually come from config files
65  static constexpr size_t kFramesPerTMUXPeriod = 9;
66  static constexpr size_t kGapLengthInput = 6;
67  static constexpr size_t kGapLengthOutputToCorrelator = 44;
68  static constexpr size_t kGapLengthOutputToGlobalTriggerSums = 3;
69  static constexpr size_t kGapLengthOutputToGlobalTriggerTaus = 36;
70  static constexpr size_t kGapLengthOutputToGlobalTriggerMesons = 15;
71  static constexpr size_t kGapLengthOutputToGlobalTriggerVertices = 6;
72  static constexpr size_t kTrackTMUX = 18;
73  static constexpr size_t kGTTBoardTMUX = 6;
74  static constexpr size_t kMaxLinesPerFile = 1024;
75 
76  const std::map<l1t::demo::LinkId, std::vector<size_t>> kChannelIdsInput = {
77  /* logical channel within time slice -> vector of channel indices (one entry per time slice) */
78  {{"tracks", 0}, {0, 18, 36}},
79  {{"tracks", 1}, {1, 19, 37}},
80  {{"tracks", 2}, {2, 20, 38}},
81  {{"tracks", 3}, {3, 21, 39}},
82  {{"tracks", 4}, {4, 22, 40}},
83  {{"tracks", 5}, {5, 23, 41}},
84  {{"tracks", 6}, {6, 24, 42}},
85  {{"tracks", 7}, {7, 25, 43}},
86  {{"tracks", 8}, {8, 26, 44}},
87  {{"tracks", 9}, {9, 27, 45}},
88  {{"tracks", 10}, {10, 28, 46}},
89  {{"tracks", 11}, {11, 29, 47}},
90  {{"tracks", 12}, {12, 30, 48}},
91  {{"tracks", 13}, {13, 31, 49}},
92  {{"tracks", 14}, {14, 32, 50}},
93  {{"tracks", 15}, {15, 33, 51}},
94  {{"tracks", 16}, {16, 34, 52}},
95  {{"tracks", 17}, {17, 35, 53}}};
96 
97  const std::map<std::string, l1t::demo::ChannelSpec> kChannelSpecsInput = {
98  /* interface name -> {link TMUX, inter-packet gap} */
99  {"tracks", {kTrackTMUX, kGapLengthInput}}};
100 
101  const std::map<l1t::demo::LinkId, std::pair<l1t::demo::ChannelSpec, std::vector<size_t>>>
103  /* logical channel within time slice -> {{link TMUX, inter-packet gap}, vector of channel indices} */
104  {{"vertices", 0}, {{kGTTBoardTMUX, kGapLengthOutputToCorrelator}, {0}}}};
105 
106  const std::map<l1t::demo::LinkId, std::vector<size_t>> kChannelIdsOutputToGlobalTrigger = {
107  /* logical channel within time slice -> vector of channel indices (one entry per time slice) */
108  {{"sums", 0}, {0}},
109  {{"taus", 1}, {1}},
110  {{"mesons", 2}, {2}},
111  {{"vertices", 3}, {3}}};
112 
113  const std::map<std::string, l1t::demo::ChannelSpec> kChannelSpecsOutputToGlobalTrigger = {
114  /* interface name -> {link TMUX, inter-packet gap} */
119 
121  typedef std::vector<Track_t> TrackCollection_t;
123 
124  // ----------member functions ----------------------
125  void analyze(const edm::Event&, const edm::EventSetup&) override;
126  void endJob() override;
127 
128  // ----------member data ---------------------------
138 
145 };
146 
147 //
148 // class implementation
149 //
150 
152  : tracksToken_(consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))),
153  convertedTracksToken_(
154  consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("convertedTracks"))),
155  convertedTrackCollectionToken_(
156  consumes<TrackCollection_t>(iConfig.getUntrackedParameter<edm::InputTag>("convertedTracks"))),
157  selectedTracksToken_(
158  consumes<TrackRefCollection_t>(iConfig.getUntrackedParameter<edm::InputTag>("selectedTracks"))),
159  vertexAssociatedTracksToken_(
160  consumes<TrackRefCollection_t>(iConfig.getUntrackedParameter<edm::InputTag>("vertexAssociatedTracks"))),
161  verticesToken_(consumes<edm::View<l1t::VertexWord>>(iConfig.getUntrackedParameter<edm::InputTag>("vertices"))),
162  jetsToken_(consumes<edm::View<l1t::TkJetWord>>(iConfig.getUntrackedParameter<edm::InputTag>("jets"))),
163  htMissToken_(consumes<edm::View<l1t::EtSum>>(iConfig.getUntrackedParameter<edm::InputTag>("htmiss"))),
164  etMissToken_(consumes<edm::View<l1t::EtSum>>(iConfig.getUntrackedParameter<edm::InputTag>("etmiss"))),
165  fileWriterInputTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
166  iConfig.getUntrackedParameter<std::string>("inputFilename"),
167  kFramesPerTMUXPeriod,
168  kGTTBoardTMUX,
169  kMaxLinesPerFile,
170  kChannelIdsInput,
171  kChannelSpecsInput),
172  fileWriterConvertedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
173  iConfig.getUntrackedParameter<std::string>("inputConvertedFilename"),
174  kFramesPerTMUXPeriod,
175  kGTTBoardTMUX,
176  kMaxLinesPerFile,
177  kChannelIdsInput,
178  kChannelSpecsInput),
179  fileWriterSelectedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
180  iConfig.getUntrackedParameter<std::string>("selectedTracksFilename"),
181  kFramesPerTMUXPeriod,
182  kGTTBoardTMUX,
183  kMaxLinesPerFile,
184  kChannelIdsInput,
185  kChannelSpecsInput),
186  fileWriterVertexAssociatedTracks_(
187  l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
188  iConfig.getUntrackedParameter<std::string>("vertexAssociatedTracksFilename"),
189  kFramesPerTMUXPeriod,
190  kGTTBoardTMUX,
191  kMaxLinesPerFile,
192  kChannelIdsInput,
193  kChannelSpecsInput),
194  fileWriterOutputToCorrelator_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
195  iConfig.getUntrackedParameter<std::string>("outputCorrelatorFilename"),
196  kFramesPerTMUXPeriod,
197  kGTTBoardTMUX,
198  kMaxLinesPerFile,
199  kChannelSpecsOutputToCorrelator),
200  fileWriterOutputToGlobalTrigger_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
201  iConfig.getUntrackedParameter<std::string>("outputGlobalTriggerFilename"),
202  kFramesPerTMUXPeriod,
203  kGTTBoardTMUX,
204  kMaxLinesPerFile,
205  kChannelIdsOutputToGlobalTrigger,
206  kChannelSpecsOutputToGlobalTrigger) {}
207 
209  using namespace edm;
210  using namespace l1t::demo::codecs;
211 
212  // 0) Gather the necessary collections
213  const auto& tracksCollection = iEvent.get(tracksToken_);
214  const auto& convertedTracksCollection = iEvent.get(convertedTracksToken_);
215  const auto& verticesCollection = iEvent.get(verticesToken_);
216  const auto& jetsCollection = iEvent.get(jetsToken_);
217  const auto& htMissCollection = iEvent.get(htMissToken_);
218  const auto& etMissCollection = iEvent.get(etMissToken_);
219 
220  edm::Handle<TrackCollection_t> convertedTracksHandle;
221  edm::Handle<TrackRefCollection_t> selectedTracksHandle;
222  edm::Handle<TrackRefCollection_t> vertexAssociatedTracksHandle;
223  iEvent.getByToken(convertedTrackCollectionToken_, convertedTracksHandle);
224  iEvent.getByToken(selectedTracksToken_, selectedTracksHandle);
225  iEvent.getByToken(vertexAssociatedTracksToken_, vertexAssociatedTracksHandle);
226 
227  // 1) Encode 'object' information onto vectors containing link data
228  const auto trackData(encodeTracks(tracksCollection));
229  const auto convertedTrackData(encodeTracks(convertedTracksCollection));
230  const auto selectedTrackData(encodeTracks(convertedTracksHandle, selectedTracksHandle));
231  const auto vertexAssociatedTrackData(encodeTracks(convertedTracksHandle, vertexAssociatedTracksHandle));
232  const auto vertexData(encodeVertices(verticesCollection));
233  const auto jetsData(encodeTkJets(jetsCollection));
234  const auto htMissData(encodeHtSums(htMissCollection));
235  const auto etMissData(encodeEtSums(etMissCollection));
236 
237  // 2) Pack 'object' information into 'event data' object
238  l1t::demo::EventData eventDataTracks;
239  l1t::demo::EventData eventDataConvertedTracks;
240  l1t::demo::EventData eventDataSelectedTracks;
241  l1t::demo::EventData eventDataVertexAssociatedTracks;
242  for (size_t i = 0; i < 18; i++) {
243  eventDataTracks.add({"tracks", i}, trackData.at(i));
244  eventDataConvertedTracks.add({"tracks", i}, convertedTrackData.at(i));
245  eventDataSelectedTracks.add({"tracks", i}, selectedTrackData.at(i));
246  eventDataVertexAssociatedTracks.add({"tracks", i}, vertexAssociatedTrackData.at(i));
247  }
248 
249  l1t::demo::EventData eventDataVertices;
250  eventDataVertices.add({"vertices", 0}, vertexData.at(0));
251 
252  // 2b) For the global trigger 'event data' combine different objects into one 'logical' link
253  std::vector<ap_uint<64>> sumsData;
254  sumsData.insert(sumsData.end(), jetsData.at(0).begin(), jetsData.at(0).end());
255  sumsData.insert(sumsData.end(), 24, 0);
256  sumsData.insert(sumsData.end(), htMissData.at(0).begin(), htMissData.at(0).end());
257  sumsData.insert(sumsData.end(), 1, 0);
258  sumsData.insert(sumsData.end(), etMissData.at(0).begin(), etMissData.at(0).end());
259 
260  std::vector<ap_uint<64>> tracksVerticesData;
261  tracksVerticesData.insert(tracksVerticesData.end(), 36, 0);
262  tracksVerticesData.insert(tracksVerticesData.end(), vertexData.at(0).begin(), vertexData.at(0).end());
263  tracksVerticesData.insert(tracksVerticesData.end(), 2, 0);
264 
265  l1t::demo::EventData eventDataGlobalTrigger;
266  eventDataGlobalTrigger.add({"sums", 0}, sumsData);
267  eventDataGlobalTrigger.add({"taus", 1}, std::vector<ap_uint<64>>(18, 0)); // Placeholder until tau object is written
268  eventDataGlobalTrigger.add({"mesons", 2},
269  std::vector<ap_uint<64>>(39, 0)); // Placeholder until light meson objects are written
270  eventDataGlobalTrigger.add({"vertices", 3}, tracksVerticesData);
271 
272  // 3) Pass the 'event data' object to the file writer
273 
274  fileWriterInputTracks_.addEvent(eventDataTracks);
275  fileWriterConvertedTracks_.addEvent(eventDataConvertedTracks);
276  fileWriterSelectedTracks_.addEvent(eventDataSelectedTracks);
277  fileWriterVertexAssociatedTracks_.addEvent(eventDataVertexAssociatedTracks);
278  fileWriterOutputToCorrelator_.addEvent(eventDataVertices);
279  fileWriterOutputToGlobalTrigger_.addEvent(eventDataGlobalTrigger);
280 }
281 
282 // ------------ method called once each job just after ending the event loop ------------
284  // Writing pending events to file before exiting
289 }
290 
291 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
293  // GTTFileWriter
295  desc.addUntracked<edm::InputTag>("tracks", edm::InputTag("l1tTTTracksFromTrackletEmulation", "Level1TTTracks"));
296  desc.addUntracked<edm::InputTag>("convertedTracks", edm::InputTag("l1tGTTInputProducer", "Level1TTTracksConverted"));
297  desc.addUntracked<edm::InputTag>("selectedTracks",
298  edm::InputTag("l1tTrackSelectionProducer", "Level1TTTracksSelectedEmulation"));
299  desc.addUntracked<edm::InputTag>(
300  "vertexAssociatedTracks",
301  edm::InputTag("l1tTrackSelectionProducer", "Level1TTTracksSelectedAssociatedEmulation"));
302  desc.addUntracked<edm::InputTag>("vertices", edm::InputTag("l1tVertexProducer", "l1verticesEmulation"));
303  desc.addUntracked<edm::InputTag>("jets", edm::InputTag("l1tTrackJetsEmulation", "L1TrackJets"));
304  desc.addUntracked<edm::InputTag>("htmiss", edm::InputTag("l1tTrackerEmuHTMiss", "L1TrackerEmuHTMiss"));
305  desc.addUntracked<edm::InputTag>("etmiss", edm::InputTag("l1tTrackerEmuEtMiss", "L1TrackerEmuEtMiss"));
306  desc.addUntracked<std::string>("inputFilename", "L1GTTInputFile");
307  desc.addUntracked<std::string>("inputConvertedFilename", "L1GTTInputConvertedFile");
308  desc.addUntracked<std::string>("selectedTracksFilename", "L1GTTSelectedTracksFile");
309  desc.addUntracked<std::string>("vertexAssociatedTracksFilename", "L1GTTVertexAssociatedTracksFile");
310  desc.addUntracked<std::string>("outputCorrelatorFilename", "L1GTTOutputToCorrelatorFile");
311  desc.addUntracked<std::string>("outputGlobalTriggerFilename", "L1GTTOutputToGlobalTriggerFile");
312  desc.addUntracked<std::string>("format", "APx");
313  descriptions.add("GTTFileWriter", desc);
314 }
315 
316 //define this as a plug-in
l1t::demo::BoardDataWriter fileWriterVertexAssociatedTracks_
static constexpr size_t kTrackTMUX
l1t::demo::BoardDataWriter fileWriterOutputToCorrelator_
std::array< std::vector< ap_uint< 64 > >, 1 > encodeHtSums(const edm::View< l1t::EtSum > &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< edm::View< l1t::EtSum > > etMissToken_
void endJob() override
const edm::EDGetTokenT< edm::View< Track_t > > convertedTracksToken_
void addEvent(const EventData &data)
FileFormat parseFileFormat(const std::string &)
Definition: utilities.cc:70
delete x;
Definition: CaloConfig.h:22
void add(const LinkId &, const std::vector< ap_uint< 64 >> &)
Definition: EventData.cc:14
std::array< std::vector< ap_uint< 64 > >, 18 > encodeTracks(const edm::View< TTTrack< Ref_Phase2TrackerDigi_ >> &, int debug=0)
const edm::EDGetTokenT< edm::View< l1t::EtSum > > htMissToken_
const edm::EDGetTokenT< edm::View< l1t::VertexWord > > verticesToken_
const edm::EDGetTokenT< edm::View< l1t::TkJetWord > > jetsToken_
int iEvent
Definition: GenABIO.cc:224
static constexpr size_t kMaxLinesPerFile
GTTFileWriter(const edm::ParameterSet &)
static constexpr size_t kGapLengthOutputToGlobalTriggerMesons
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
static constexpr size_t kGapLengthOutputToGlobalTriggerTaus
std::array< std::vector< ap_uint< 64 > >, 1 > encodeEtSums(const edm::View< l1t::EtSum > &)
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 > &)
static constexpr size_t kGapLengthOutputToCorrelator
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::map< l1t::demo::LinkId, std::vector< size_t > > kChannelIdsInput
l1t::demo::BoardDataWriter fileWriterSelectedTracks_
const std::map< std::string, l1t::demo::ChannelSpec > kChannelSpecsInput
static constexpr size_t kGapLengthOutputToGlobalTriggerVertices
HLT enums.
std::vector< Track_t > TrackCollection_t
const std::map< std::string, l1t::demo::ChannelSpec > kChannelSpecsOutputToGlobalTrigger
static constexpr size_t kGTTBoardTMUX
const edm::EDGetTokenT< TrackCollection_t > convertedTrackCollectionToken_
const edm::EDGetTokenT< TrackRefCollection_t > selectedTracksToken_
std::array< std::vector< ap_uint< 64 > >, 1 > encodeTkJets(const edm::View< l1t::TkJetWord > &)
Definition: codecs_tkjets.cc:9
static constexpr size_t kGapLengthInput
static constexpr size_t kGapLengthOutputToGlobalTriggerSums
l1t::demo::BoardDataWriter fileWriterOutputToGlobalTrigger_
edm::RefVector< TrackCollection_t > TrackRefCollection_t
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
const edm::EDGetTokenT< TrackRefCollection_t > vertexAssociatedTracksToken_
l1t::demo::BoardDataWriter fileWriterConvertedTracks_
const std::map< l1t::demo::LinkId, std::vector< size_t > > kChannelIdsOutputToGlobalTrigger
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< edm::View< Track_t > > tracksToken_