CMS 3D CMS Logo

L1CTJetFileWriter.cc
Go to the documentation of this file.
1 #include <memory>
2 
3 // user include files
6 
9 
12 
14 
19 
20 //
21 // class declaration
22 //
23 
24 class L1CTJetFileWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
25 public:
26  explicit L1CTJetFileWriter(const edm::ParameterSet&);
27 
28  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
29 
30 private:
31  // ----------constants, enums and typedefs ---------
32  unsigned nJets_;
33  size_t nFramesPerBX_;
37  std::map<l1t::demo::LinkId, std::pair<l1t::demo::ChannelSpec, std::vector<size_t>>> channelSpecsOutputToGT_;
38 
39  // ----------member functions ----------------------
40  void analyze(const edm::Event&, const edm::EventSetup&) override;
41  void endJob() override;
42  std::vector<ap_uint<64>> encodeJets(const std::vector<l1t::PFJet> jets);
43 
46 };
47 
49  : nJets_(iConfig.getParameter<unsigned>("nJets")),
50  nFramesPerBX_(iConfig.getParameter<unsigned>("nFramesPerBX")),
51  ctl2BoardTMUX_(iConfig.getParameter<unsigned>("TMUX")),
52  gapLengthOutput_(ctl2BoardTMUX_ * nFramesPerBX_ - 2 * nJets_),
53  maxLinesPerFile_(iConfig.getParameter<unsigned>("maxLinesPerFile")),
54  channelSpecsOutputToGT_{{{"jets", 0}, {{ctl2BoardTMUX_, gapLengthOutput_}, {0}}}},
55  jetsToken_(consumes<edm::View<l1t::PFJet>>(iConfig.getParameter<edm::InputTag>("jets"))),
56  fileWriterOutputToGT_(l1t::demo::parseFileFormat(iConfig.getParameter<std::string>("format")),
57  iConfig.getParameter<std::string>("outputFilename"),
58  nFramesPerBX_,
59  ctl2BoardTMUX_,
60  maxLinesPerFile_,
61  channelSpecsOutputToGT_) {}
62 
64  using namespace edm;
65 
66  // 1) Encode jet information onto vectors containing link data
67  // TODO remove the sort here and sort the input collection where it's created
69  std::vector<l1t::PFJet> sortedJets;
70  sortedJets.reserve(jets.size());
71  std::copy(jets.begin(), jets.end(), std::back_inserter(sortedJets));
72 
73  std::stable_sort(
74  sortedJets.begin(), sortedJets.end(), [](l1t::PFJet i, l1t::PFJet j) { return (i.hwPt() > j.hwPt()); });
75  const auto outputJets(encodeJets(sortedJets));
76 
77  // 2) Pack jet information into 'event data' object, and pass that to file writer
78  l1t::demo::EventData eventDataJets;
79  eventDataJets.add({"jets", 0}, outputJets);
80  fileWriterOutputToGT_.addEvent(eventDataJets);
81 }
82 
83 // ------------ method called once each job just after ending the event loop ------------
85  // Writing pending events to file before exiting
87 }
88 
89 std::vector<ap_uint<64>> L1CTJetFileWriter::encodeJets(const std::vector<l1t::PFJet> jets) {
90  std::vector<ap_uint<64>> jet_words;
91  for (unsigned i = 0; i < nJets_; i++) {
92  l1t::PFJet j;
93  if (i < jets.size()) {
94  j = jets.at(i);
95  } else { // pad up to nJets_ with null jets
96  l1t::PFJet j(0, 0, 0, 0, 0, 0);
97  }
98  jet_words.push_back(j.encodedJet()[0]);
99  jet_words.push_back(j.encodedJet()[1]);
100  }
101  return jet_words;
102 }
103 
104 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
106  //The following says we do not know what parameters are allowed so do no validation
107  // Please change this to state exactly what you do use, even if it is no parameters
109  desc.add<edm::InputTag>("jets");
110  desc.add<std::string>("outputFilename");
111  desc.add<uint32_t>("nJets", 12);
112  desc.add<uint32_t>("nFramesPerBX", 9);
113  desc.add<uint32_t>("TMUX", 6);
114  desc.add<uint32_t>("maxLinesPerFile", 1024);
115  desc.add<std::string>("format", "EMP");
116  descriptions.addDefault(desc);
117 }
118 
119 //define this as a plug-in
std::map< l1t::demo::LinkId, std::pair< l1t::demo::ChannelSpec, std::vector< size_t > > > channelSpecsOutputToGT_
void endJob() override
void addEvent(const EventData &data)
FileFormat parseFileFormat(const std::string &)
Definition: utilities.cc:70
void add(const LinkId &, const std::vector< ap_uint< 64 >> &)
Definition: EventData.cc:14
L1CTJetFileWriter(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
l1t::demo::BoardDataWriter fileWriterOutputToGT_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< ap_uint< 64 > > encodeJets(const std::vector< l1t::PFJet > jets)
HLT enums.
edm::EDGetTokenT< edm::View< l1t::PFJet > > jetsToken_
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