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  iConfig.getParameter<std::string>("outputFileExtension"),
59  nFramesPerBX_,
60  ctl2BoardTMUX_,
61  maxLinesPerFile_,
62  channelSpecsOutputToGT_) {}
63 
65  using namespace edm;
66 
67  // 1) Encode jet information onto vectors containing link data
68  // TODO remove the sort here and sort the input collection where it's created
70  std::vector<l1t::PFJet> sortedJets;
71  sortedJets.reserve(jets.size());
72  std::copy(jets.begin(), jets.end(), std::back_inserter(sortedJets));
73 
74  std::stable_sort(
75  sortedJets.begin(), sortedJets.end(), [](l1t::PFJet i, l1t::PFJet j) { return (i.hwPt() > j.hwPt()); });
76  const auto outputJets(encodeJets(sortedJets));
77 
78  // 2) Pack jet information into 'event data' object, and pass that to file writer
79  l1t::demo::EventData eventDataJets;
80  eventDataJets.add({"jets", 0}, outputJets);
81  fileWriterOutputToGT_.addEvent(eventDataJets);
82 }
83 
84 // ------------ method called once each job just after ending the event loop ------------
86  // Writing pending events to file before exiting
88 }
89 
90 std::vector<ap_uint<64>> L1CTJetFileWriter::encodeJets(const std::vector<l1t::PFJet> jets) {
91  std::vector<ap_uint<64>> jet_words;
92  for (unsigned i = 0; i < nJets_; i++) {
93  l1t::PFJet j;
94  if (i < jets.size()) {
95  j = jets.at(i);
96  } else { // pad up to nJets_ with null jets
97  l1t::PFJet j(0, 0, 0, 0, 0, 0);
98  }
99  jet_words.push_back(j.encodedJet()[0]);
100  jet_words.push_back(j.encodedJet()[1]);
101  }
102  return jet_words;
103 }
104 
105 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
107  //The following says we do not know what parameters are allowed so do no validation
108  // Please change this to state exactly what you do use, even if it is no parameters
110  desc.add<edm::InputTag>("jets");
111  desc.add<std::string>("outputFilename");
112  desc.add<std::string>("outputFileExtension", "txt");
113  desc.add<uint32_t>("nJets", 12);
114  desc.add<uint32_t>("nFramesPerBX", 9);
115  desc.add<uint32_t>("TMUX", 6);
116  desc.add<uint32_t>("maxLinesPerFile", 1024);
117  desc.add<std::string>("format", "EMP");
118  descriptions.addDefault(desc);
119 }
120 
121 //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:73
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