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 ---------------------------
84 
91 };
92 
93 //
94 // class implementation
95 //
96 
98  : tracksToken_(consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("tracks"))),
99  convertedTracksToken_(
100  consumes<edm::View<Track_t>>(iConfig.getUntrackedParameter<edm::InputTag>("convertedTracks"))),
101  convertedTrackCollectionToken_(
102  consumes<TrackCollection_t>(iConfig.getUntrackedParameter<edm::InputTag>("convertedTracks"))),
103  selectedTracksToken_(
104  consumes<TrackRefCollection_t>(iConfig.getUntrackedParameter<edm::InputTag>("selectedTracks"))),
105  vertexAssociatedTracksToken_(
106  consumes<TrackRefCollection_t>(iConfig.getUntrackedParameter<edm::InputTag>("vertexAssociatedTracks"))),
107  verticesToken_(consumes<edm::View<l1t::VertexWord>>(iConfig.getUntrackedParameter<edm::InputTag>("vertices"))),
108  jetsToken_(consumes<edm::View<l1t::TkJetWord>>(iConfig.getUntrackedParameter<edm::InputTag>("jets"))),
109  htMissToken_(consumes<edm::View<l1t::EtSum>>(iConfig.getUntrackedParameter<edm::InputTag>("htmiss"))),
110  etMissToken_(consumes<edm::View<l1t::EtSum>>(iConfig.getUntrackedParameter<edm::InputTag>("etmiss"))),
111  fileWriterInputTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
112  iConfig.getUntrackedParameter<std::string>("inputFilename"),
113  iConfig.getUntrackedParameter<std::string>("fileExtension"),
115  l1t::demo::gtt::kGTTBoardTMUX,
116  l1t::demo::gtt::kMaxLinesPerFile,
117  l1t::demo::gtt::kChannelIdsInput,
118  l1t::demo::gtt::kChannelSpecsInput),
119  fileWriterConvertedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
120  iConfig.getUntrackedParameter<std::string>("inputConvertedFilename"),
121  iConfig.getUntrackedParameter<std::string>("fileExtension"),
123  l1t::demo::gtt::kGTTBoardTMUX,
124  l1t::demo::gtt::kMaxLinesPerFile,
125  l1t::demo::gtt::kChannelIdsInput,
126  l1t::demo::gtt::kChannelSpecsInput),
127  fileWriterSelectedTracks_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
128  iConfig.getUntrackedParameter<std::string>("selectedTracksFilename"),
129  iConfig.getUntrackedParameter<std::string>("fileExtension"),
131  l1t::demo::gtt::kGTTBoardTMUX,
132  l1t::demo::gtt::kMaxLinesPerFile,
133  l1t::demo::gtt::kChannelIdsInput,
134  l1t::demo::gtt::kChannelSpecsInput),
135  fileWriterVertexAssociatedTracks_(
136  l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
137  iConfig.getUntrackedParameter<std::string>("vertexAssociatedTracksFilename"),
138  iConfig.getUntrackedParameter<std::string>("fileExtension"),
140  l1t::demo::gtt::kGTTBoardTMUX,
141  l1t::demo::gtt::kMaxLinesPerFile,
142  l1t::demo::gtt::kChannelIdsInput,
143  l1t::demo::gtt::kChannelSpecsInput),
144  fileWriterOutputToCorrelator_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
145  iConfig.getUntrackedParameter<std::string>("outputCorrelatorFilename"),
146  iConfig.getUntrackedParameter<std::string>("fileExtension"),
148  l1t::demo::gtt::kGTTBoardTMUX,
149  l1t::demo::gtt::kMaxLinesPerFile,
152  fileWriterOutputToGlobalTrigger_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
153  iConfig.getUntrackedParameter<std::string>("outputGlobalTriggerFilename"),
154  iConfig.getUntrackedParameter<std::string>("fileExtension"),
156  l1t::demo::gtt::kGTTBoardTMUX,
157  l1t::demo::gtt::kMaxLinesPerFile,
160 
162  using namespace edm;
163  using namespace l1t::demo::codecs;
164 
165  // 0) Gather the necessary collections
166  const auto& tracksCollection = iEvent.get(tracksToken_);
167  const auto& convertedTracksCollection = iEvent.get(convertedTracksToken_);
168  const auto& verticesCollection = iEvent.get(verticesToken_);
169  const auto& jetsCollection = iEvent.get(jetsToken_);
170  const auto& htMissCollection = iEvent.get(htMissToken_);
171  const auto& etMissCollection = iEvent.get(etMissToken_);
172 
173  edm::Handle<TrackCollection_t> convertedTracksHandle;
174  edm::Handle<TrackRefCollection_t> selectedTracksHandle;
175  edm::Handle<TrackRefCollection_t> vertexAssociatedTracksHandle;
176  iEvent.getByToken(convertedTrackCollectionToken_, convertedTracksHandle);
177  iEvent.getByToken(selectedTracksToken_, selectedTracksHandle);
178  iEvent.getByToken(vertexAssociatedTracksToken_, vertexAssociatedTracksHandle);
179 
180  // 1) Encode 'object' information onto vectors containing link data
181  const auto trackData(encodeTracks(tracksCollection));
182  const auto convertedTrackData(encodeTracks(convertedTracksCollection));
183  const auto selectedTrackData(encodeTracks(convertedTracksHandle, selectedTracksHandle));
184  const auto vertexAssociatedTrackData(encodeTracks(convertedTracksHandle, vertexAssociatedTracksHandle));
185  const auto vertexData(encodeVertices(verticesCollection));
186  const auto jetsData(encodeTkJets(jetsCollection));
187  const auto htMissData(encodeHtSums(htMissCollection));
188  const auto etMissData(encodeEtSums(etMissCollection));
189 
190  // 2) Pack 'object' information into 'event data' object
191  l1t::demo::EventData eventDataTracks;
192  l1t::demo::EventData eventDataConvertedTracks;
193  l1t::demo::EventData eventDataSelectedTracks;
194  l1t::demo::EventData eventDataVertexAssociatedTracks;
195  for (size_t i = 0; i < 18; i++) {
196  eventDataTracks.add({"tracks", i}, trackData.at(i));
197  eventDataConvertedTracks.add({"tracks", i}, convertedTrackData.at(i));
198  eventDataSelectedTracks.add({"tracks", i}, selectedTrackData.at(i));
199  eventDataVertexAssociatedTracks.add({"tracks", i}, vertexAssociatedTrackData.at(i));
200  }
201 
202  l1t::demo::EventData eventDataVertices;
203  eventDataVertices.add({"vertices", 0}, vertexData.at(0));
204 
205  // 2b) For the global trigger 'event data' combine different objects into one 'logical' link
206  std::vector<ap_uint<64>> sumsData;
207  sumsData.insert(sumsData.end(), jetsData.at(0).begin(), jetsData.at(0).end());
208  sumsData.insert(sumsData.end(), 24, 0);
209  sumsData.insert(sumsData.end(), htMissData.at(0).begin(), htMissData.at(0).end());
210  sumsData.insert(sumsData.end(), 1, 0);
211  sumsData.insert(sumsData.end(), etMissData.at(0).begin(), etMissData.at(0).end());
212 
213  std::vector<ap_uint<64>> tracksVerticesData;
214  tracksVerticesData.insert(tracksVerticesData.end(), 36, 0);
215  tracksVerticesData.insert(tracksVerticesData.end(), vertexData.at(0).begin(), vertexData.at(0).end());
216  tracksVerticesData.insert(tracksVerticesData.end(), 2, 0);
217 
218  l1t::demo::EventData eventDataGlobalTrigger;
219  eventDataGlobalTrigger.add({"sums", 0}, sumsData);
220  eventDataGlobalTrigger.add({"taus", 1}, std::vector<ap_uint<64>>(18, 0)); // Placeholder until tau object is written
221  eventDataGlobalTrigger.add({"mesons", 2},
222  std::vector<ap_uint<64>>(39, 0)); // Placeholder until light meson objects are written
223  eventDataGlobalTrigger.add({"vertices", 3}, tracksVerticesData);
224 
225  // 3) Pass the 'event data' object to the file writer
226 
227  fileWriterInputTracks_.addEvent(eventDataTracks);
228  fileWriterConvertedTracks_.addEvent(eventDataConvertedTracks);
229  fileWriterSelectedTracks_.addEvent(eventDataSelectedTracks);
230  fileWriterVertexAssociatedTracks_.addEvent(eventDataVertexAssociatedTracks);
231  fileWriterOutputToCorrelator_.addEvent(eventDataVertices);
232  fileWriterOutputToGlobalTrigger_.addEvent(eventDataGlobalTrigger);
233 }
234 
235 // ------------ method called once each job just after ending the event loop ------------
237  // Writing pending events to file before exiting
242 }
243 
244 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
246  // GTTFileWriter
248  desc.addUntracked<edm::InputTag>("tracks", edm::InputTag("l1tTTTracksFromTrackletEmulation", "Level1TTTracks"));
249  desc.addUntracked<edm::InputTag>("convertedTracks", edm::InputTag("l1tGTTInputProducer", "Level1TTTracksConverted"));
250  desc.addUntracked<edm::InputTag>("selectedTracks",
251  edm::InputTag("l1tTrackSelectionProducer", "Level1TTTracksSelectedEmulation"));
252  desc.addUntracked<edm::InputTag>(
253  "vertexAssociatedTracks",
254  edm::InputTag("l1tTrackSelectionProducer", "Level1TTTracksSelectedAssociatedEmulation"));
255  desc.addUntracked<edm::InputTag>("vertices", edm::InputTag("l1tVertexProducer", "L1VerticesEmulation"));
256  desc.addUntracked<edm::InputTag>("jets", edm::InputTag("l1tTrackJetsEmulation", "L1TrackJets"));
257  desc.addUntracked<edm::InputTag>("htmiss", edm::InputTag("l1tTrackerEmuHTMiss", "L1TrackerEmuHTMiss"));
258  desc.addUntracked<edm::InputTag>("etmiss", edm::InputTag("l1tTrackerEmuEtMiss", "L1TrackerEmuEtMiss"));
259  desc.addUntracked<std::string>("inputFilename", "L1GTTInputFile");
260  desc.addUntracked<std::string>("inputConvertedFilename", "L1GTTInputConvertedFile");
261  desc.addUntracked<std::string>("selectedTracksFilename", "L1GTTSelectedTracksFile");
262  desc.addUntracked<std::string>("vertexAssociatedTracksFilename", "L1GTTVertexAssociatedTracksFile");
263  desc.addUntracked<std::string>("outputCorrelatorFilename", "L1GTTOutputToCorrelatorFile");
264  desc.addUntracked<std::string>("outputGlobalTriggerFilename", "L1GTTOutputToGlobalTriggerFile");
265  desc.addUntracked<std::string>("format", "APx");
266  desc.addUntracked<std::string>("fileExtension", "txt");
267  descriptions.add("GTTFileWriter", desc);
268 }
269 
270 //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_
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_
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< edm::View< Track_t > > tracksToken_