CMS 3D CMS Logo

L1GTFinOrBoardWriter.cc
Go to the documentation of this file.
1 
7 
10 
14 
17 
19 
21 
22 #include "ap_int.h"
23 
24 #include <vector>
25 #include <algorithm>
26 #include <string>
27 
28 using namespace l1t;
29 
31 public:
32  explicit L1GTFinOrBoardWriter(const edm::ParameterSet&);
33 
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
35 
36 private:
37  void analyze(const edm::Event&, const edm::EventSetup&) override;
38  void endJob() override;
39 
40  const std::array<unsigned int, 3> channelsLow_;
41  const std::array<unsigned int, 3> channelsMid_;
42  const std::array<unsigned int, 3> channelsHigh_;
43  const unsigned int channelFinOr_;
46 
47  std::map<l1t::demo::LinkId, std::vector<ap_uint<64>>> linkData_;
48  std::size_t tmuxCounter_;
49 };
50 
52  : channelsLow_(config.getParameter<std::array<unsigned int, 3>>("channelsLow")),
53  channelsMid_(config.getParameter<std::array<unsigned int, 3>>("channelsMid")),
54  channelsHigh_(config.getParameter<std::array<unsigned int, 3>>("channelsHigh")),
55  channelFinOr_(config.getParameter<unsigned int>("channelFinOr")),
56  algoBlocksToken_(consumes<P2GTAlgoBlockMap>(config.getParameter<edm::InputTag>("algoBlocksTag"))),
57  boardDataWriter_(l1t::demo::parseFileFormat(config.getParameter<std::string>("patternFormat")),
58  config.getParameter<std::string>("outputFilename"),
59  config.getParameter<std::string>("outputFileExtension"),
60  9,
61  2,
62  config.getParameter<unsigned int>("maxLines"),
63  [&]() {
65  channelMap.insert({l1t::demo::LinkId{"BeforeBxMaskAndPrescaleLow", channelsLow_[0]},
66  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsLow_[0]}}});
67  channelMap.insert({l1t::demo::LinkId{"BeforePrescaleLow", channelsLow_[1]},
68  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsLow_[1]}}});
69  channelMap.insert({l1t::demo::LinkId{"FinalLow", channelsLow_[2]},
70  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsLow_[2]}}});
71 
72  channelMap.insert({l1t::demo::LinkId{"BeforeBxMaskAndPrescaleMid", channelsMid_[0]},
73  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsMid_[0]}}});
74  channelMap.insert({l1t::demo::LinkId{"BeforePrescaleMid", channelsMid_[1]},
75  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsMid_[1]}}});
76  channelMap.insert({l1t::demo::LinkId{"FinalMid", channelsMid_[2]},
77  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsMid_[2]}}});
78 
79  channelMap.insert({l1t::demo::LinkId{"BeforeBxMaskAndPrescaleHigh", channelsHigh_[0]},
80  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsHigh_[0]}}});
81  channelMap.insert({l1t::demo::LinkId{"BeforePrescaleHigh", channelsHigh_[1]},
82  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsHigh_[1]}}});
83  channelMap.insert({l1t::demo::LinkId{"FinalHigh", channelsHigh_[2]},
84  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsHigh_[2]}}});
85 
86  channelMap.insert({l1t::demo::LinkId{"FinOr", channelFinOr_},
87  {l1t::demo::ChannelSpec{2, 0, 0}, {channelFinOr_}}});
88 
89  return channelMap;
90  }()),
91  linkData_(),
92  tmuxCounter_(0) {}
93 
95  const P2GTAlgoBlockMap& algoBlocks = event.get(algoBlocksToken_);
96 
97  auto algoBlockIt = algoBlocks.begin();
98 
99  if (tmuxCounter_ == 0) {
100  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleLow", channelsLow_[0]}] = std::vector<ap_uint<64>>(18, 0);
101  linkData_[l1t::demo::LinkId{"BeforePrescaleLow", channelsLow_[1]}] = std::vector<ap_uint<64>>(18, 0);
102  linkData_[l1t::demo::LinkId{"FinalLow", channelsLow_[2]}] = std::vector<ap_uint<64>>(18, 0);
103  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleMid", channelsMid_[0]}] = std::vector<ap_uint<64>>(18, 0);
104  linkData_[l1t::demo::LinkId{"BeforePrescaleMid", channelsMid_[1]}] = std::vector<ap_uint<64>>(18, 0);
105  linkData_[l1t::demo::LinkId{"FinalMid", channelsMid_[2]}] = std::vector<ap_uint<64>>(18, 0);
106  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleHigh", channelsHigh_[0]}] = std::vector<ap_uint<64>>(18, 0);
107  linkData_[l1t::demo::LinkId{"BeforePrescaleHigh", channelsHigh_[1]}] = std::vector<ap_uint<64>>(18, 0);
108  linkData_[l1t::demo::LinkId{"FinalHigh", channelsHigh_[2]}] = std::vector<ap_uint<64>>(18, 0);
109  linkData_[l1t::demo::LinkId{"FinOr", channelFinOr_}] = std::vector<ap_uint<64>>(18, 0);
110  }
111 
112  for (std::size_t word = 0; word < 9; word++) {
113  for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
114  auto& [alogName, algoBlock] = *algoBlockIt;
115  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleLow", channelsLow_[0]}][word + tmuxCounter_ * 9].set(
116  idx, algoBlock.decisionBeforeBxMaskAndPrescale());
117  linkData_[l1t::demo::LinkId{"BeforePrescaleLow", channelsLow_[1]}][word + tmuxCounter_ * 9].set(
118  idx, algoBlock.decisionBeforePrescale());
119  linkData_[l1t::demo::LinkId{"FinalLow", channelsLow_[2]}][word + tmuxCounter_ * 9].set(idx,
120  algoBlock.decisionFinal());
121  }
122  }
123 
124  for (std::size_t word = 0; word < 9; word++) {
125  for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
126  auto& [alogName, algoBlock] = *algoBlockIt;
127  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleMid", channelsMid_[0]}][word + tmuxCounter_ * 9].set(
128  idx, algoBlock.decisionBeforeBxMaskAndPrescale());
129  linkData_[l1t::demo::LinkId{"BeforePrescaleMid", channelsMid_[1]}][word + tmuxCounter_ * 9].set(
130  idx, algoBlock.decisionBeforePrescale());
131  linkData_[l1t::demo::LinkId{"FinalMid", channelsMid_[2]}][word + tmuxCounter_ * 9].set(idx,
132  algoBlock.decisionFinal());
133  }
134  }
135 
136  for (std::size_t word = 0; word < 9; word++) {
137  for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
138  auto& [algoName, algoBlock] = *algoBlockIt;
139  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleHigh", channelsHigh_[0]}][word + tmuxCounter_ * 9].set(
140  idx, algoBlock.decisionBeforeBxMaskAndPrescale());
141  linkData_[l1t::demo::LinkId{"BeforePrescaleHigh", channelsHigh_[1]}][word + tmuxCounter_ * 9].set(
142  idx, algoBlock.decisionBeforePrescale());
143  linkData_[l1t::demo::LinkId{"FinalHigh", channelsHigh_[2]}][word + tmuxCounter_ * 9].set(
144  idx, algoBlock.decisionFinal());
145  }
146  }
147 
148  bool vetoed = false, vetoedPreview = false;
149  int finOrByTypes = 0, finOrPreviewByTypes = 0;
150  for (auto algoBlockIt = algoBlocks.begin(); algoBlockIt != algoBlocks.end(); algoBlockIt++) {
151  auto& [alogName, algoBlock] = *algoBlockIt;
152  vetoed |= (algoBlock.isVeto() && algoBlock.decisionFinal());
153  vetoedPreview |= (algoBlock.isVeto() && algoBlock.decisionFinalPreview());
154  finOrByTypes |= algoBlock.decisionFinal() ? algoBlock.triggerTypes() : 0;
155  finOrPreviewByTypes |= algoBlock.decisionFinalPreview() ? algoBlock.triggerTypes() : 0;
156  }
157 
158  // Add FinOrTrigger bits per https://gitlab.cern.ch/cms-cactus/phase2/firmware/gt-final-or#output-finor-bits
159  ap_uint<64> finOrBits(0);
160  finOrBits(7, 0) = finOrByTypes;
161  finOrBits(15, 8) = finOrPreviewByTypes;
162  finOrBits(23, 16) = vetoed ? 0 : finOrByTypes;
163  finOrBits(31, 24) = vetoedPreview ? 0 : finOrPreviewByTypes;
164 
165  linkData_[l1t::demo::LinkId{"FinOr", channelFinOr_}][0 + tmuxCounter_ * 9] = finOrBits;
166 
167  if (tmuxCounter_ == 1) {
169  }
170 
171  tmuxCounter_ = (tmuxCounter_ + 1) % 2;
172 }
173 
175  if (tmuxCounter_ == 1) {
177  }
178 
180 }
181 
184  desc.add<std::string>("outputFilename");
185  desc.add<std::string>("outputFileExtension", "txt");
186  desc.add<edm::InputTag>("algoBlocksTag");
187  desc.add<std::vector<unsigned int>>("channelsLow");
188  desc.add<std::vector<unsigned int>>("channelsMid");
189  desc.add<std::vector<unsigned int>>("channelsHigh");
190  desc.add<unsigned int>("channelFinOr");
191  desc.add<unsigned int>("maxLines", 1024);
192  desc.add<std::string>("patternFormat", "EMPv2");
193 
194  descriptions.addDefault(desc);
195 }
196 
std::map< l1t::demo::LinkId, std::vector< ap_uint< 64 > > > linkData_
Logical ID for link within any given time slice (e.g. ["tracks", 0] -> ["tracks", 17] for links from ...
Definition: LinkId.h:10
L1GTFinOrBoardWriter(const edm::ParameterSet &)
void addEvent(const EventData &data)
std::map< std::string, P2GTAlgoBlock > P2GTAlgoBlockMap
Definition: P2GTAlgoBlock.h:11
FileFormat parseFileFormat(const std::string &)
Definition: utilities.cc:73
delete x;
Definition: CaloConfig.h:22
Definition: config.py:1
const std::array< unsigned int, 3 > channelsMid_
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void analyze(const edm::Event &, const edm::EventSetup &) override
uint64_t word
const edm::EDGetTokenT< P2GTAlgoBlockMap > algoBlocksToken_
void addDefault(ParameterSetDescription const &psetDescription)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< LinkId, std::pair< ChannelSpec, std::vector< size_t > > > ChannelMap_t
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const unsigned int channelFinOr_
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 std::array< unsigned int, 3 > channelsHigh_
const std::array< unsigned int, 3 > channelsLow_
Definition: event.py:1
l1t::demo::BoardDataWriter boardDataWriter_