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 
52 
53 //
54 // class declaration
55 //
56 
57 class GTTFileWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
58 public:
59  explicit GTTFileWriter(const edm::ParameterSet&);
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
62 
63 private:
64  // ----------constants, enums and typedefs ---------
65 
67  typedef std::vector<Track_t> TrackCollection_t;
69 
70  // ----------member functions ----------------------
71  void analyze(const edm::Event&, const edm::EventSetup&) override;
72  void endJob() override;
73 
74  // ----------member data ---------------------------
86 
93 };
94 
95 //
96 // class implementation
97 //
98 
100  : tracksToken_(consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))),
101  convertedTracksToken_(
102  consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("convertedTracks"))),
103  convertedTrackCollectionToken_(
104  consumes<TrackCollection_t>(iConfig.getUntrackedParameter<edm::InputTag>("convertedTracks"))),
105  selectedTracksToken_(
106  consumes<TrackRefCollection_t>(iConfig.getUntrackedParameter<edm::InputTag>("selectedTracks"))),
107  vertexAssociatedTracksToken_(
108  consumes<TrackRefCollection_t>(iConfig.getUntrackedParameter<edm::InputTag>("vertexAssociatedTracks"))),
109  verticesToken_(consumes<edm::View<l1t::VertexWord>>(iConfig.getUntrackedParameter<edm::InputTag>("vertices"))),
110  jetsToken_(consumes<edm::View<l1t::TkJetWord>>(iConfig.getUntrackedParameter<edm::InputTag>("jets"))),
111  jetsDispToken_(consumes<edm::View<l1t::TkJetWord>>(iConfig.getUntrackedParameter<edm::InputTag>("jetsdisp"))),
112  htMissToken_(consumes<edm::View<l1t::EtSum>>(iConfig.getUntrackedParameter<edm::InputTag>("htmiss"))),
113  htMissDispToken_(consumes<edm::View<l1t::EtSum>>(iConfig.getUntrackedParameter<edm::InputTag>("htmissdisp"))),
114  etMissToken_(consumes<edm::View<l1t::EtSum>>(iConfig.getUntrackedParameter<edm::InputTag>("etmiss"))),
115  fileWriterInputTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
116  iConfig.getUntrackedParameter<std::string>("inputFilename"),
117  iConfig.getUntrackedParameter<std::string>("fileExtension"),
119  l1t::demo::gtt::kGTTBoardTMUX,
120  l1t::demo::gtt::kMaxLinesPerFile,
121  l1t::demo::gtt::kChannelIdsInput,
122  l1t::demo::gtt::kChannelSpecsInput),
123  fileWriterConvertedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
124  iConfig.getUntrackedParameter<std::string>("inputConvertedFilename"),
125  iConfig.getUntrackedParameter<std::string>("fileExtension"),
127  l1t::demo::gtt::kGTTBoardTMUX,
128  l1t::demo::gtt::kMaxLinesPerFile,
129  l1t::demo::gtt::kChannelIdsInput,
130  l1t::demo::gtt::kChannelSpecsInput),
131  fileWriterSelectedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
132  iConfig.getUntrackedParameter<std::string>("selectedTracksFilename"),
133  iConfig.getUntrackedParameter<std::string>("fileExtension"),
135  l1t::demo::gtt::kGTTBoardTMUX,
136  l1t::demo::gtt::kMaxLinesPerFile,
137  l1t::demo::gtt::kChannelIdsInput,
138  l1t::demo::gtt::kChannelSpecsInput),
139  fileWriterVertexAssociatedTracks_(
140  l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
141  iConfig.getUntrackedParameter<std::string>("vertexAssociatedTracksFilename"),
142  iConfig.getUntrackedParameter<std::string>("fileExtension"),
144  l1t::demo::gtt::kGTTBoardTMUX,
145  l1t::demo::gtt::kMaxLinesPerFile,
146  l1t::demo::gtt::kChannelIdsInput,
147  l1t::demo::gtt::kChannelSpecsInput),
148  fileWriterOutputToCorrelator_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
149  iConfig.getUntrackedParameter<std::string>("outputCorrelatorFilename"),
150  iConfig.getUntrackedParameter<std::string>("fileExtension"),
152  l1t::demo::gtt::kGTTBoardTMUX,
153  l1t::demo::gtt::kMaxLinesPerFile,
156  fileWriterOutputToGlobalTrigger_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
157  iConfig.getUntrackedParameter<std::string>("outputGlobalTriggerFilename"),
158  iConfig.getUntrackedParameter<std::string>("fileExtension"),
160  l1t::demo::gtt::kGTTBoardTMUX,
161  l1t::demo::gtt::kMaxLinesPerFile,
164 
166  using namespace edm;
167  using namespace l1t::demo::codecs;
168 
169  // 0) Gather the necessary collections
170  const auto& tracksCollection = iEvent.get(tracksToken_);
171  const auto& convertedTracksCollection = iEvent.get(convertedTracksToken_);
172  const auto& verticesCollection = iEvent.get(verticesToken_);
173  const auto& jetsCollection = iEvent.get(jetsToken_);
174  const auto& jetsDispCollection = iEvent.get(jetsDispToken_);
175  const auto& htMissCollection = iEvent.get(htMissToken_);
176  const auto& htMissDispCollection = iEvent.get(htMissDispToken_);
177  const auto& etMissCollection = iEvent.get(etMissToken_);
178 
179  edm::Handle<TrackCollection_t> convertedTracksHandle;
180  edm::Handle<TrackRefCollection_t> selectedTracksHandle;
181  edm::Handle<TrackRefCollection_t> vertexAssociatedTracksHandle;
182  iEvent.getByToken(convertedTrackCollectionToken_, convertedTracksHandle);
183  iEvent.getByToken(selectedTracksToken_, selectedTracksHandle);
184  iEvent.getByToken(vertexAssociatedTracksToken_, vertexAssociatedTracksHandle);
185 
186  // 1) Encode 'object' information onto vectors containing link data
187  const auto trackData(encodeTracks(tracksCollection));
188  const auto convertedTrackData(encodeTracks(convertedTracksCollection));
189  const auto selectedTrackData(encodeTracks(convertedTracksHandle, selectedTracksHandle));
190  const auto vertexAssociatedTrackData(encodeTracks(convertedTracksHandle, vertexAssociatedTracksHandle));
191  const auto vertexData(encodeVertices(verticesCollection));
192  const auto jetsData(encodeTkJets(jetsCollection));
193  const auto jetsDispData(encodeTkJets(jetsDispCollection));
194  const auto htMissData(encodeHtSums(htMissCollection));
195  const auto htMissDispData(encodeHtSums(htMissDispCollection));
196  const auto etMissData(encodeEtSums(etMissCollection));
197 
198  // 2) Pack 'object' information into 'event data' object
199  l1t::demo::EventData eventDataTracks;
200  l1t::demo::EventData eventDataConvertedTracks;
201  l1t::demo::EventData eventDataSelectedTracks;
202  l1t::demo::EventData eventDataVertexAssociatedTracks;
203  for (size_t i = 0; i < 18; i++) {
204  eventDataTracks.add({"tracks", i}, trackData.at(i));
205  eventDataConvertedTracks.add({"tracks", i}, convertedTrackData.at(i));
206  eventDataSelectedTracks.add({"tracks", i}, selectedTrackData.at(i));
207  eventDataVertexAssociatedTracks.add({"tracks", i}, vertexAssociatedTrackData.at(i));
208  }
209 
210  l1t::demo::EventData eventDataVertices;
211  eventDataVertices.add({"vertices", 0}, vertexData.at(0));
212 
213  // 2b) For the global trigger 'event data' combine different objects into one 'logical' link
214  std::vector<ap_uint<64>> sumsData;
215  sumsData.insert(sumsData.end(), jetsData.at(0).begin(), jetsData.at(0).end());
216  sumsData.insert(sumsData.end(), jetsDispData.at(0).begin(), jetsDispData.at(0).end());
217  sumsData.insert(sumsData.end(), htMissData.at(0).begin(), htMissData.at(0).end());
218  sumsData.insert(sumsData.end(), htMissDispData.at(0).begin(), htMissDispData.at(0).end());
219  sumsData.insert(sumsData.end(), etMissData.at(0).begin(), etMissData.at(0).end());
220 
221  std::vector<ap_uint<64>> tracksVerticesData;
222  tracksVerticesData.insert(tracksVerticesData.end(), 36, 0);
223  tracksVerticesData.insert(tracksVerticesData.end(), vertexData.at(0).begin(), vertexData.at(0).end());
224  tracksVerticesData.insert(tracksVerticesData.end(), 2, 0);
225 
226  l1t::demo::EventData eventDataGlobalTrigger;
227  eventDataGlobalTrigger.add({"sums", 0}, sumsData);
228  eventDataGlobalTrigger.add({"taus", 1}, std::vector<ap_uint<64>>(18, 0)); // Placeholder until tau object is written
229  eventDataGlobalTrigger.add({"mesons", 2},
230  std::vector<ap_uint<64>>(39, 0)); // Placeholder until light meson objects are written
231  eventDataGlobalTrigger.add({"vertices", 3}, tracksVerticesData);
232 
233  // 3) Pass the 'event data' object to the file writer
234 
235  fileWriterInputTracks_.addEvent(eventDataTracks);
236  fileWriterConvertedTracks_.addEvent(eventDataConvertedTracks);
237  fileWriterSelectedTracks_.addEvent(eventDataSelectedTracks);
238  fileWriterVertexAssociatedTracks_.addEvent(eventDataVertexAssociatedTracks);
239  fileWriterOutputToCorrelator_.addEvent(eventDataVertices);
240  fileWriterOutputToGlobalTrigger_.addEvent(eventDataGlobalTrigger);
241 }
242 
243 // ------------ method called once each job just after ending the event loop ------------
245  // Writing pending events to file before exiting
250 }
251 
252 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
254  // GTTFileWriter
256  desc.addUntracked<edm::InputTag>("tracks", edm::InputTag("l1tTTTracksFromTrackletEmulation", "Level1TTTracks"));
257  desc.addUntracked<edm::InputTag>("convertedTracks", edm::InputTag("l1tGTTInputProducer", "Level1TTTracksConverted"));
258  desc.addUntracked<edm::InputTag>("selectedTracks",
259  edm::InputTag("l1tTrackSelectionProducer", "Level1TTTracksSelectedEmulation"));
260  desc.addUntracked<edm::InputTag>(
261  "vertexAssociatedTracks",
262  edm::InputTag("l1tTrackSelectionProducer", "Level1TTTracksSelectedAssociatedEmulation"));
263  desc.addUntracked<edm::InputTag>("vertices", edm::InputTag("l1tVertexProducer", "L1VerticesEmulation"));
264  desc.addUntracked<edm::InputTag>("jets", edm::InputTag("l1tTrackJetsEmulation", "L1TrackJets"));
265  desc.addUntracked<edm::InputTag>("jetsdisp", edm::InputTag("l1tTrackJetsExtendedEmulation", "L1TrackJetsExtended"));
266  desc.addUntracked<edm::InputTag>("htmiss", edm::InputTag("l1tTrackerEmuHTMiss", "L1TrackerEmuHTMiss"));
267  desc.addUntracked<edm::InputTag>("htmissdisp",
268  edm::InputTag("l1tTrackerEmuHTMissExtended", "L1TrackerEmuHTMissExtended"));
269  desc.addUntracked<edm::InputTag>("etmiss", edm::InputTag("l1tTrackerEmuEtMiss", "L1TrackerEmuEtMiss"));
270  desc.addUntracked<std::string>("inputFilename", "L1GTTInputFile");
271  desc.addUntracked<std::string>("inputConvertedFilename", "L1GTTInputConvertedFile");
272  desc.addUntracked<std::string>("selectedTracksFilename", "L1GTTSelectedTracksFile");
273  desc.addUntracked<std::string>("vertexAssociatedTracksFilename", "L1GTTVertexAssociatedTracksFile");
274  desc.addUntracked<std::string>("outputCorrelatorFilename", "L1GTTOutputToCorrelatorFile");
275  desc.addUntracked<std::string>("outputGlobalTriggerFilename", "L1GTTOutputToGlobalTriggerFile");
276  desc.addUntracked<std::string>("format", "APx");
277  desc.addUntracked<std::string>("fileExtension", "txt");
278  descriptions.add("GTTFileWriter", desc);
279 }
280 
281 //define this as a plug-in
l1t::demo::BoardDataWriter fileWriterVertexAssociatedTracks_
static constexpr size_t kMaxLinesPerFile
Definition: GTTInterface.h:26
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_
const edm::EDGetTokenT< edm::View< l1t::EtSum > > htMissDispToken_
void endJob() override
static const std::map< l1t::demo::LinkId, std::vector< size_t > > kChannelIdsInput
Definition: GTTInterface.h:31
const edm::EDGetTokenT< edm::View< Track_t > > convertedTracksToken_
void addEvent(const EventData &data)
FileFormat parseFileFormat(const std::string &)
Definition: utilities.cc:73
delete x;
Definition: CaloConfig.h:22
void add(const LinkId &, const std::vector< ap_uint< 64 >> &)
Definition: EventData.cc:14
static const std::map< std::string, l1t::demo::ChannelSpec > kChannelSpecsOutputToGlobalTrigger
Definition: GTTInterface.h:99
static const std::map< std::string, l1t::demo::ChannelSpec > kChannelSpecsOutputToCorrelator
Definition: GTTInterface.h:87
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_
static constexpr size_t kFramesPerTMUXPeriod
Definition: GTTInterface.h:16
int iEvent
Definition: GenABIO.cc:224
static constexpr size_t kGTTBoardTMUX
Definition: GTTInterface.h:24
GTTFileWriter(const edm::ParameterSet &)
static const std::map< l1t::demo::LinkId, std::vector< size_t > > kChannelIdsOutputToGlobalTrigger
Definition: GTTInterface.h:92
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TTTrack< Ref_Phase2TrackerDigi_ > Track_t
l1t::demo::BoardDataWriter fileWriterInputTracks_
static const std::map< std::string, l1t::demo::ChannelSpec > kChannelSpecsInput
Definition: GTTInterface.h:74
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 > &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
l1t::demo::BoardDataWriter fileWriterSelectedTracks_
HLT enums.
std::vector< Track_t > TrackCollection_t
const edm::EDGetTokenT< TrackCollection_t > convertedTrackCollectionToken_
static const std::map< l1t::demo::LinkId, std::vector< size_t > > kChannelIdsOutputToCorrelator
Definition: GTTInterface.h:83
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
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 edm::EDGetTokenT< edm::View< l1t::TkJetWord > > jetsDispToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< edm::View< Track_t > > tracksToken_