CMS 3D CMS Logo

L1GTFinOrBoardWriter.cc
Go to the documentation of this file.
1 
7 
10 
14 
17 
20 
22 
23 #include "ap_int.h"
24 
25 #include <vector>
26 #include <algorithm>
27 #include <string>
28 #include <array>
29 
30 using namespace l1t;
31 
33 public:
34  explicit L1GTFinOrBoardWriter(const edm::ParameterSet&);
35 
36  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
37 
38 private:
39  void analyze(const edm::Event&, const edm::EventSetup&) override;
40  void endJob() override;
41 
42  unsigned int eventCounter_;
43  const unsigned int maxEvents_;
44  const std::array<unsigned int, 3> channelsLow_;
45  const std::array<unsigned int, 3> channelsMid_;
46  const std::array<unsigned int, 3> channelsHigh_;
47  const unsigned int channelFinOr_;
50 
51  std::map<l1t::demo::LinkId, std::vector<ap_uint<64>>> linkData_;
52  std::size_t tmuxCounter_;
53 };
54 
55 template <typename T, std::size_t N>
56 static std::array<T, N> convert(std::vector<T> vec, const char* name) {
57  if (vec.size() != N) {
59  << "The parameter '" << name << "' should have " << N << " elements, but has " << vec.size()
60  << " elements in the configuration.\n";
61  }
62  std::array<T, N> a;
63  std::copy_n(std::make_move_iterator(vec.begin()), N, a.begin());
64  return a;
65 }
66 
68  : eventCounter_(0),
69  maxEvents_(config.getUntrackedParameter<unsigned int>("maxEvents")),
70  channelsLow_(convert<unsigned int, 3>(config.getUntrackedParameter<std::vector<unsigned int>>("channelsLow"),
71  "channelsLow")),
72  channelsMid_(convert<unsigned int, 3>(config.getUntrackedParameter<std::vector<unsigned int>>("channelsMid"),
73  "channelsMid")),
74  channelsHigh_(convert<unsigned int, 3>(config.getUntrackedParameter<std::vector<unsigned int>>("channelsHigh"),
75  "channelsHigh")),
76  channelFinOr_(config.getUntrackedParameter<unsigned int>("channelFinOr")),
77  algoBlocksToken_(consumes<P2GTAlgoBlockMap>(config.getUntrackedParameter<edm::InputTag>("algoBlocksTag"))),
78  boardDataWriter_(l1t::demo::parseFileFormat(config.getUntrackedParameter<std::string>("patternFormat")),
79  config.getUntrackedParameter<std::string>("filename"),
80  config.getUntrackedParameter<std::string>("fileExtension"),
81  9,
82  2,
83  config.getUntrackedParameter<unsigned int>("maxFrames"),
84  [&]() {
86  channelMap.insert({l1t::demo::LinkId{"BeforeBxMaskAndPrescaleLow", channelsLow_[0]},
87  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsLow_[0]}}});
88  channelMap.insert({l1t::demo::LinkId{"BeforePrescaleLow", channelsLow_[1]},
89  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsLow_[1]}}});
90  channelMap.insert({l1t::demo::LinkId{"FinalLow", channelsLow_[2]},
91  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsLow_[2]}}});
92 
93  channelMap.insert({l1t::demo::LinkId{"BeforeBxMaskAndPrescaleMid", channelsMid_[0]},
94  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsMid_[0]}}});
95  channelMap.insert({l1t::demo::LinkId{"BeforePrescaleMid", channelsMid_[1]},
96  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsMid_[1]}}});
97  channelMap.insert({l1t::demo::LinkId{"FinalMid", channelsMid_[2]},
98  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsMid_[2]}}});
99 
100  channelMap.insert({l1t::demo::LinkId{"BeforeBxMaskAndPrescaleHigh", channelsHigh_[0]},
101  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsHigh_[0]}}});
102  channelMap.insert({l1t::demo::LinkId{"BeforePrescaleHigh", channelsHigh_[1]},
103  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsHigh_[1]}}});
104  channelMap.insert({l1t::demo::LinkId{"FinalHigh", channelsHigh_[2]},
105  {l1t::demo::ChannelSpec{2, 0, 0}, {channelsHigh_[2]}}});
106 
107  channelMap.insert({l1t::demo::LinkId{"FinOr", channelFinOr_},
108  {l1t::demo::ChannelSpec{2, 0, 0}, {channelFinOr_}}});
109 
110  return channelMap;
111  }()),
112  linkData_(),
113  tmuxCounter_(0) {}
114 
116  const P2GTAlgoBlockMap& algoBlocks = event.get(algoBlocksToken_);
117 
118  auto algoBlockIt = algoBlocks.begin();
119 
120  if (tmuxCounter_ == 0) {
121  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleLow", channelsLow_[0]}] = std::vector<ap_uint<64>>(18, 0);
122  linkData_[l1t::demo::LinkId{"BeforePrescaleLow", channelsLow_[1]}] = std::vector<ap_uint<64>>(18, 0);
123  linkData_[l1t::demo::LinkId{"FinalLow", channelsLow_[2]}] = std::vector<ap_uint<64>>(18, 0);
124  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleMid", channelsMid_[0]}] = std::vector<ap_uint<64>>(18, 0);
125  linkData_[l1t::demo::LinkId{"BeforePrescaleMid", channelsMid_[1]}] = std::vector<ap_uint<64>>(18, 0);
126  linkData_[l1t::demo::LinkId{"FinalMid", channelsMid_[2]}] = std::vector<ap_uint<64>>(18, 0);
127  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleHigh", channelsHigh_[0]}] = std::vector<ap_uint<64>>(18, 0);
128  linkData_[l1t::demo::LinkId{"BeforePrescaleHigh", channelsHigh_[1]}] = std::vector<ap_uint<64>>(18, 0);
129  linkData_[l1t::demo::LinkId{"FinalHigh", channelsHigh_[2]}] = std::vector<ap_uint<64>>(18, 0);
130  linkData_[l1t::demo::LinkId{"FinOr", channelFinOr_}] = std::vector<ap_uint<64>>(18, 0);
131  }
132 
133  for (std::size_t word = 0; word < 9; word++) {
134  for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
135  auto& [alogName, algoBlock] = *algoBlockIt;
136  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleLow", channelsLow_[0]}][word + tmuxCounter_ * 9].set(
137  idx, algoBlock.decisionBeforeBxMaskAndPrescale());
138  linkData_[l1t::demo::LinkId{"BeforePrescaleLow", channelsLow_[1]}][word + tmuxCounter_ * 9].set(
139  idx, algoBlock.decisionBeforePrescale());
140  linkData_[l1t::demo::LinkId{"FinalLow", channelsLow_[2]}][word + tmuxCounter_ * 9].set(idx,
141  algoBlock.decisionFinal());
142  }
143  }
144 
145  for (std::size_t word = 0; word < 9; word++) {
146  for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
147  auto& [alogName, algoBlock] = *algoBlockIt;
148  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleMid", channelsMid_[0]}][word + tmuxCounter_ * 9].set(
149  idx, algoBlock.decisionBeforeBxMaskAndPrescale());
150  linkData_[l1t::demo::LinkId{"BeforePrescaleMid", channelsMid_[1]}][word + tmuxCounter_ * 9].set(
151  idx, algoBlock.decisionBeforePrescale());
152  linkData_[l1t::demo::LinkId{"FinalMid", channelsMid_[2]}][word + tmuxCounter_ * 9].set(idx,
153  algoBlock.decisionFinal());
154  }
155  }
156 
157  for (std::size_t word = 0; word < 9; word++) {
158  for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
159  auto& [algoName, algoBlock] = *algoBlockIt;
160  linkData_[l1t::demo::LinkId{"BeforeBxMaskAndPrescaleHigh", channelsHigh_[0]}][word + tmuxCounter_ * 9].set(
161  idx, algoBlock.decisionBeforeBxMaskAndPrescale());
162  linkData_[l1t::demo::LinkId{"BeforePrescaleHigh", channelsHigh_[1]}][word + tmuxCounter_ * 9].set(
163  idx, algoBlock.decisionBeforePrescale());
164  linkData_[l1t::demo::LinkId{"FinalHigh", channelsHigh_[2]}][word + tmuxCounter_ * 9].set(
165  idx, algoBlock.decisionFinal());
166  }
167  }
168 
169  bool vetoed = false, vetoedPreview = false;
170  int finOrByTypes = 0, finOrPreviewByTypes = 0;
171  for (auto algoBlockIt = algoBlocks.begin(); algoBlockIt != algoBlocks.end(); algoBlockIt++) {
172  auto& [alogName, algoBlock] = *algoBlockIt;
173  vetoed |= (algoBlock.isVeto() && algoBlock.decisionFinal());
174  vetoedPreview |= (algoBlock.isVeto() && algoBlock.decisionFinalPreview());
175  finOrByTypes |= algoBlock.decisionFinal() ? algoBlock.triggerTypes() : 0;
176  finOrPreviewByTypes |= algoBlock.decisionFinalPreview() ? algoBlock.triggerTypes() : 0;
177  }
178 
179  // Add FinOrTrigger bits per https://gitlab.cern.ch/cms-cactus/phase2/firmware/gt-final-or#output-finor-bits
180  ap_uint<64> finOrBits(0);
181  finOrBits(7, 0) = finOrByTypes;
182  finOrBits(15, 8) = finOrPreviewByTypes;
183  finOrBits(23, 16) = vetoed ? 0 : finOrByTypes;
184  finOrBits(31, 24) = vetoedPreview ? 0 : finOrPreviewByTypes;
185 
186  linkData_[l1t::demo::LinkId{"FinOr", channelFinOr_}][0 + tmuxCounter_ * 9] = finOrBits;
187 
188  if (tmuxCounter_ == 1) {
190  }
191 
192  tmuxCounter_ = (tmuxCounter_ + 1) % 2;
193 
194  eventCounter_++;
195 
196  if (maxEvents_ != 0 && eventCounter_ == maxEvents_) {
198  eventCounter_ = 0;
199  }
200 }
201 
203  if (tmuxCounter_ == 1) {
205  }
206 
208 }
209 
212  desc.addUntracked<std::string>("filename");
213  desc.addUntracked<std::string>("fileExtension", "txt");
214  desc.addUntracked<edm::InputTag>("algoBlocksTag");
215  desc.addUntracked<std::vector<unsigned int>>("channelsLow");
216  desc.addUntracked<std::vector<unsigned int>>("channelsMid");
217  desc.addUntracked<std::vector<unsigned int>>("channelsHigh");
218  desc.addUntracked<unsigned int>("channelFinOr");
219  desc.addUntracked<unsigned int>("maxFrames", 1024);
220  desc.addUntracked<unsigned int>("maxEvents", 0);
221  desc.addUntracked<std::string>("patternFormat", "EMPv2");
222 
223  descriptions.addDefault(desc);
224 }
225 
static std::array< T, N > convert(std::vector< T > vec, const char *name)
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_
const unsigned int maxEvents_
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)
#define N
Definition: blowfish.cc:9
HLT enums.
double a
Definition: hdecay.h:121
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_