CMS 3D CMS Logo

L1GTOutputObjectWriter.cc
Go to the documentation of this file.
4 
7 
10 
12 
15 
17 
19 
20 #include <vector>
21 #include <array>
22 #include <tuple>
23 #include <string>
24 #include <fstream>
25 #include <limits>
26 
27 #include <optional>
28 
29 using namespace l1t;
30 
31 static constexpr std::array<std::tuple<const char*, std::size_t, std::size_t>, 27> OUTPUT_CHANNELS_VU9P{
32  {{"GTTPromptJets", 2, 6},
33  {"GTTDisplacedJets", 6, 10},
34  {"GTTPromptHtSum", 10, 11},
35  {"GTTDisplacedHtSum", 11, 12},
36  {"GTTEtSum", 12, 13},
37  {"GTTHadronicTaus", 13, 16},
38  {"CL2JetsSC4", 24, 28},
39  {"CL2JetsSC8", 28, 32},
40  {"CL2Taus", 34, 37},
41  {"CL2HtSum", 37, 38},
42  {"CL2EtSum", 38, 39},
43  {"GCTNonIsoEg", 48, 50},
44  {"GCTIsoEg", 50, 52},
45  {"GCTJets", 52, 54},
46  {"GCTTaus", 54, 56},
47  {"GCTHtSum", 56, 57},
48  {"GCTEtSum", 57, 58},
49  {"GMTSaPromptMuons", 60, 62},
50  {"GMTSaDisplacedMuons", 62, 64},
51  {"GMTTkMuons", 64, 67},
52  {"GMTTopo", 67, 69},
53  {"CL2Electrons", 80, 83},
54  {"CL2Photons", 83, 86},
55  {"GTTPhiCandidates", 104, 107},
56  {"GTTRhoCandidates", 107, 110},
57  {"GTTBsCandidates", 110, 113},
58  {"GTTPrimaryVert", 113, 115}}};
59 
60 static constexpr std::array<std::tuple<const char*, std::size_t, std::size_t>, 27> OUTPUT_CHANNELS_VU13P{
61  {{"GTTPromptJets", 2, 6},
62  {"GTTDisplacedJets", 6, 10},
63  {"GTTPromptHtSum", 10, 11},
64  {"GTTDisplacedHtSum", 11, 12},
65  {"GTTEtSum", 12, 13},
66  {"GTTHadronicTaus", 13, 16},
67  {"GCTNonIsoEg", 26, 28},
68  {"GCTIsoEg", 28, 30},
69  {"GCTJets", 30, 32},
70  {"CL2JetsSC4", 32, 36},
71  {"CL2JetsSC8", 36, 40},
72  {"CL2Taus", 40, 43},
73  {"CL2HtSum", 43, 44},
74  {"CL2EtSum", 44, 45},
75  {"GMTSaPromptMuons", 68, 70},
76  {"GMTSaDisplacedMuons", 70, 72},
77  {"GMTTkMuons", 72, 75},
78  {"GMTTopo", 75, 77},
79  {"CL2Electrons", 80, 83},
80  {"CL2Photons", 83, 86},
81  {"GCTTaus", 96, 98},
82  {"GCTHtSum", 98, 99},
83  {"GCTEtSum", 99, 100},
84  {"GTTPhiCandidates", 112, 115},
85  {"GTTRhoCandidates", 115, 118},
86  {"GTTBsCandidates", 118, 121},
87  {"GTTPrimaryVert", 121, 123}}};
88 
90 public:
92 
93  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
94 
95 private:
96  template <typename T>
97  std::vector<std::unique_ptr<L1TGT_BaseInterface>> fillCollection(
99  void analyze(const edm::Event&, const edm::EventSetup&) override;
100  void endJob() override;
101 
129  const std::array<std::tuple<const char*, std::size_t, std::size_t>, 27> outputChannelDef_;
131 };
132 
134  : gctNonIsoEgToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GCTNonIsoEg"))),
135  gctIsoEgToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GCTIsoEg"))),
136  gctJetsToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GCTJets"))),
137  gctTausToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GCTTaus"))),
138  gctHtSumToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GCTHtSum"))),
139  gctEtSumToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GCTEtSum"))),
140  gmtSaPromptMuonsToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GMTSaPromptMuons"))),
141  gmtSaDisplacedMuonsToken_(
142  consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GMTSaDisplacedMuons"))),
143  gmtTkMuonsToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GMTTkMuons"))),
144  gmtTopoToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GMTTopo"))),
145  gttPromptJetsToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTPromptJets"))),
146  gttDisplacedJetsToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTDisplacedJets"))),
147  gttPhiCandidatesToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTPhiCandidates"))),
148  gttRhoCandidatesToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTRhoCandidates"))),
149  gttBsCandidatesToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTBsCandidates"))),
150  gttHadronicTausToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTHadronicTaus"))),
151  gttPrimaryVertToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTPrimaryVert"))),
152  gttPromptHtSumToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTPromptHtSum"))),
153  gttDisplacedHtSumToken_(
154  consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTDisplacedHtSum"))),
155  gttEtSumToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("GTTEtSum"))),
156  cl2JetsSc4Token_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("CL2JetsSC4"))),
157  cl2JetsSc8Token_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("CL2JetsSC8"))),
158  cl2TausToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("CL2Taus"))),
159  cl2ElectronsToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("CL2Electrons"))),
160  cl2PhotonsToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("CL2Photons"))),
161  cl2HtSumToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("CL2HtSum"))),
162  cl2EtSumToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("CL2EtSum"))),
163  outputChannelDef_(config.getParameter<std::string>("platform") == "VU13P" ? OUTPUT_CHANNELS_VU13P
165  boardDataWriter_(l1t::demo::parseFileFormat(config.getParameter<std::string>("patternFormat")),
166  config.getParameter<std::string>("outputFilename"),
167  config.getParameter<std::string>("outputFileExtension"),
168  9,
169  1,
170  config.getParameter<unsigned int>("maxLines"),
171  [&]() {
173  for (const auto& [name, start, end] : outputChannelDef_) {
174  for (std::size_t i = start; i < end; i++) {
175  channelMap.insert({{name, i - start}, {{1, 0}, {i}}});
176  }
177  }
178  return channelMap;
179  }()) {}
180 
183  desc.add<edm::InputTag>("GCTNonIsoEg");
184  desc.add<edm::InputTag>("GCTIsoEg");
185  desc.add<edm::InputTag>("GCTJets");
186  desc.add<edm::InputTag>("GCTTaus");
187  desc.add<edm::InputTag>("GCTHtSum");
188  desc.add<edm::InputTag>("GCTEtSum");
189  desc.add<edm::InputTag>("GMTSaPromptMuons");
190  desc.add<edm::InputTag>("GMTSaDisplacedMuons");
191  desc.add<edm::InputTag>("GMTTkMuons");
192  desc.add<edm::InputTag>("GMTTopo");
193  desc.add<edm::InputTag>("GTTPromptJets");
194  desc.add<edm::InputTag>("GTTDisplacedJets");
195  desc.add<edm::InputTag>("GTTPhiCandidates");
196  desc.add<edm::InputTag>("GTTRhoCandidates");
197  desc.add<edm::InputTag>("GTTBsCandidates");
198  desc.add<edm::InputTag>("GTTHadronicTaus");
199  desc.add<edm::InputTag>("GTTPrimaryVert");
200  desc.add<edm::InputTag>("GTTPromptHtSum");
201  desc.add<edm::InputTag>("GTTDisplacedHtSum");
202  desc.add<edm::InputTag>("GTTEtSum");
203  desc.add<edm::InputTag>("CL2JetsSC4");
204  desc.add<edm::InputTag>("CL2JetsSC8");
205  desc.add<edm::InputTag>("CL2Taus");
206  desc.add<edm::InputTag>("CL2Electrons");
207  desc.add<edm::InputTag>("CL2Photons");
208  desc.add<edm::InputTag>("CL2HtSum");
209  desc.add<edm::InputTag>("CL2EtSum");
210 
211  desc.add<unsigned int>("maxLines", 1024);
212  desc.add<std::string>("outputFilename");
213  desc.add<std::string>("outputFileExtension", "txt");
214  desc.add<std::string>("patternFormat", "EMPv2");
215  desc.ifValue(edm::ParameterDescription<std::string>("platform", "VU9P", true),
216  edm::allowedValues<std::string>("VU9P", "VU13P"));
217 
218  descriptions.addWithDefaultLabel(desc);
219 }
220 
221 template <typename T>
222 std::vector<std::unique_ptr<L1TGT_BaseInterface>> L1GTOutputObjectWriter::fillCollection(
224  std::vector<std::unique_ptr<L1TGT_BaseInterface>> outputCollection;
225 
226  for (const P2GTCandidate& object : event.get(token)) {
227  outputCollection.push_back(std::make_unique<T>(T::from_GTObject(object)));
228  }
229 
230  return outputCollection;
231 }
232 
233 template <typename... Args>
234 static std::vector<ap_uint<64>> vpack(const Args&... vobjects) {
235  std::vector<ap_uint<64>> vpacked;
236 
237  (
238  [&vpacked](const std::vector<std::unique_ptr<l1t::L1TGT_BaseInterface>>& objects) {
239  std::optional<ap_uint<64>> next_packed;
240  for (const auto& object : objects) {
241  if (object->packed_width() == 64) {
242  const l1t::L1TGT_Interface<64>& interface_obj = dynamic_cast<const l1t::L1TGT_Interface<64>&>(*object);
243  vpacked.emplace_back(interface_obj.pack());
244  } else if (object->packed_width() == 96) {
245  const l1t::L1TGT_Interface<96>& interface_obj = dynamic_cast<const l1t::L1TGT_Interface<96>&>(*object);
246  ap_uint<96> packed = interface_obj.pack();
247  if (next_packed.has_value()) {
248  vpacked.emplace_back(packed(95, 64) << 32 | next_packed.value());
249  next_packed.reset();
250  } else {
251  next_packed = packed(95, 64);
252  }
253 
254  vpacked.emplace_back(packed(63, 0));
255 
256  } else if (object->packed_width() == 128) {
257  const l1t::L1TGT_Interface<128>& interface_obj = dynamic_cast<const l1t::L1TGT_Interface<128>&>(*object);
258  ap_uint<128> packed = interface_obj.pack();
259  vpacked.emplace_back(packed(63, 0));
260  vpacked.emplace_back(packed(127, 64));
261  }
262  }
263  }(vobjects),
264  ...);
265 
266  return vpacked;
267 }
268 
270  std::map<std::string, std::vector<std::unique_ptr<L1TGT_BaseInterface>>> outputObjects;
271 
272  outputObjects.emplace("GCTNonIsoEg", fillCollection<L1TGT_Common3Vector<64>>(event, gctNonIsoEgToken_));
273  outputObjects.emplace("GCTIsoEg", fillCollection<L1TGT_Common3Vector<64>>(event, gctIsoEgToken_));
274  outputObjects.emplace("GCTJets", fillCollection<L1TGT_Common3Vector<64>>(event, gctJetsToken_));
275  outputObjects.emplace("GCTTaus", fillCollection<L1TGT_GCT_tau6p6>(event, gctTausToken_));
276  outputObjects.emplace("GCTHtSum", fillCollection<L1TGT_CommonSum>(event, gctHtSumToken_));
277  outputObjects.emplace("GCTEtSum", fillCollection<L1TGT_CommonSum>(event, gctEtSumToken_));
278  outputObjects.emplace("GMTSaPromptMuons",
279  fillCollection<L1TGT_GMT_PromptDisplacedMuon>(event, gmtSaPromptMuonsToken_));
280  outputObjects.emplace("GMTSaDisplacedMuons",
281  fillCollection<L1TGT_GMT_PromptDisplacedMuon>(event, gmtSaDisplacedMuonsToken_));
282  outputObjects.emplace("GMTTkMuons", fillCollection<L1TGT_GMT_TrackMatchedmuon>(event, gmtTkMuonsToken_));
283  outputObjects.emplace("GMTTopo", fillCollection<L1TGT_GMT_TopoObject>(event, gmtTopoToken_));
284  outputObjects.emplace("GTTPromptJets", fillCollection<L1TGT_GTT_PromptJet>(event, gttPromptJetsToken_));
285  outputObjects.emplace("GTTDisplacedJets", fillCollection<L1TGT_GTT_DisplacedJet>(event, gttDisplacedJetsToken_));
286  outputObjects.emplace("GTTPhiCandidates", fillCollection<L1TGT_GTT_LightMeson>(event, gttPhiCandidatesToken_));
287  outputObjects.emplace("GTTRhoCandidates", fillCollection<L1TGT_GTT_LightMeson>(event, gttRhoCandidatesToken_));
288  outputObjects.emplace("GTTBsCandidates", fillCollection<L1TGT_GTT_LightMeson>(event, gttBsCandidatesToken_));
289  outputObjects.emplace("GTTHadronicTaus", fillCollection<L1TGT_GTT_HadronicTau>(event, gttHadronicTausToken_));
290  outputObjects.emplace("GTTPrimaryVert", fillCollection<L1TGT_GTT_PrimaryVert>(event, gttPrimaryVertToken_));
291  outputObjects.emplace("GTTPromptHtSum", fillCollection<L1TGT_CommonSum>(event, gttPromptHtSumToken_));
292  outputObjects.emplace("GTTDisplacedHtSum", fillCollection<L1TGT_CommonSum>(event, gttDisplacedHtSumToken_));
293  outputObjects.emplace("GTTEtSum", fillCollection<L1TGT_CommonSum>(event, gttEtSumToken_));
294  outputObjects.emplace("CL2JetsSC4", fillCollection<L1TGT_CL2_Jet>(event, cl2JetsSc4Token_));
295  outputObjects.emplace("CL2JetsSC8", fillCollection<L1TGT_CL2_Jet>(event, cl2JetsSc8Token_));
296  outputObjects.emplace("CL2Taus", fillCollection<L1TGT_CL2_Tau>(event, cl2TausToken_));
297  outputObjects.emplace("CL2Electrons", fillCollection<L1TGT_CL2_Electron>(event, cl2ElectronsToken_));
298  outputObjects.emplace("CL2Photons", fillCollection<L1TGT_CL2_Photon>(event, cl2PhotonsToken_));
299  outputObjects.emplace("CL2HtSum", fillCollection<L1TGT_CommonSum>(event, cl2HtSumToken_));
300  outputObjects.emplace("CL2EtSum", fillCollection<L1TGT_CommonSum>(event, cl2EtSumToken_));
301 
302  std::map<demo::LinkId, std::vector<ap_uint<64>>> eventData;
303 
304  for (const auto& [name, start, end] : outputChannelDef_) {
305  std::vector<ap_uint<64>> data = vpack(outputObjects[name]);
306  std::size_t numChannels = end - start;
307  for (std::size_t i = start; i < end; i++) {
308  for (std::size_t j = i - start; j < data.size(); j += numChannels) {
309  eventData[{name, i - start}].push_back(data[j]);
310  }
311 
312  while (eventData[{name, i - start}].size() < 9) {
313  eventData[{name, i - start}].push_back(0);
314  }
315  }
316  }
317 
318  boardDataWriter_.addEvent(eventData);
319 }
320 
322 
Definition: start.py:1
const edm::EDGetTokenT< P2GTCandidateCollection > gttPromptHtSumToken_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
static constexpr std::array< std::tuple< const char *, std::size_t, std::size_t >, 27 > OUTPUT_CHANNELS_VU13P
const edm::EDGetTokenT< P2GTCandidateCollection > gttEtSumToken_
const edm::EDGetTokenT< P2GTCandidateCollection > cl2HtSumToken_
static std::vector< ap_uint< 64 > > vpack(const Args &... vobjects)
const edm::EDGetTokenT< P2GTCandidateCollection > gctEtSumToken_
std::vector< P2GTCandidate > P2GTCandidateCollection
Definition: P2GTCandidate.h:16
const edm::EDGetTokenT< P2GTCandidateCollection > gmtSaDisplacedMuonsToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gttBsCandidatesToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gttDisplacedJetsToken_
const edm::EDGetTokenT< P2GTCandidateCollection > cl2TausToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< P2GTCandidateCollection > gttDisplacedHtSumToken_
const edm::EDGetTokenT< P2GTCandidateCollection > cl2EtSumToken_
l1t::demo::BoardDataWriter boardDataWriter_
void addEvent(const EventData &data)
const edm::EDGetTokenT< P2GTCandidateCollection > gmtTkMuonsToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gctTausToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gctNonIsoEgToken_
FileFormat parseFileFormat(const std::string &)
Definition: utilities.cc:73
delete x;
Definition: CaloConfig.h:22
Definition: config.py:1
const edm::EDGetTokenT< P2GTCandidateCollection > cl2ElectronsToken_
const edm::EDGetTokenT< P2GTCandidateCollection > cl2JetsSc4Token_
const edm::EDGetTokenT< P2GTCandidateCollection > cl2JetsSc8Token_
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< P2GTCandidateCollection > gctIsoEgToken_
std::vector< std::unique_ptr< L1TGT_BaseInterface > > fillCollection(const edm::Event &event, const edm::EDGetTokenT< P2GTCandidateCollection > &token) const
const edm::EDGetTokenT< P2GTCandidateCollection > gttPromptJetsToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gctHtSumToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gttPhiCandidatesToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gctJetsToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gttHadronicTausToken_
const edm::EDGetTokenT< P2GTCandidateCollection > gmtSaPromptMuonsToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1GTOutputObjectWriter(const edm::ParameterSet &)
const edm::EDGetTokenT< P2GTCandidateCollection > cl2PhotonsToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
std::map< LinkId, std::pair< ChannelSpec, std::vector< size_t > > > ChannelMap_t
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< P2GTCandidateCollection > gmtTopoToken_
const std::array< std::tuple< const char *, std::size_t, std::size_t >, 27 > outputChannelDef_
virtual ap_uint< N > pack() const =0
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
const edm::EDGetTokenT< P2GTCandidateCollection > gttRhoCandidatesToken_
static constexpr std::array< std::tuple< const char *, std::size_t, std::size_t >, 27 > OUTPUT_CHANNELS_VU9P
const edm::EDGetTokenT< P2GTCandidateCollection > gttPrimaryVertToken_
Definition: event.py:1