CMS 3D CMS Logo

L1GTAlgoBoardWriter.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 L1GTAlgoBoardWriter(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  unsigned int maxEvents_;
44 
45  const std::array<unsigned int, 2> channels_;
46  const std::array<unsigned long long, 9> algoBitMask_;
49 
50  std::map<l1t::demo::LinkId, std::vector<ap_uint<64>>> linkData_;
51  std::size_t tmuxCounter_;
52 };
53 
54 template <typename T, std::size_t N>
55 static std::array<T, N> convert(std::vector<T> vec, const char* name) {
56  if (vec.size() != N) {
58  << "The parameter '" << name << "' should have " << N << " elements, but has " << vec.size()
59  << " elements in the configuration.\n";
60  }
61  std::array<T, N> a;
62  std::copy_n(std::make_move_iterator(vec.begin()), N, a.begin());
63  return a;
64 }
65 
67  : eventCounter_(0),
68  maxEvents_(config.getUntrackedParameter<unsigned int>("maxEvents")),
69  channels_(
70  convert<unsigned int, 2>(config.getUntrackedParameter<std::vector<unsigned int>>("channels"), "channels")),
71  algoBitMask_(convert<unsigned long long, 9>(
72  config.getUntrackedParameter<std::vector<unsigned long long>>("algoBitMask"), "algoBitMask")),
73  algoBlocksToken_(consumes<P2GTAlgoBlockMap>(config.getUntrackedParameter<edm::InputTag>("algoBlocksTag"))),
74  boardDataWriter_(
75  l1t::demo::parseFileFormat(config.getUntrackedParameter<std::string>("patternFormat")),
76  config.getUntrackedParameter<std::string>("filename"),
77  config.getUntrackedParameter<std::string>("fileExtension"),
78  9,
79  2,
80  config.getUntrackedParameter<unsigned int>("maxFrames"),
81  [](const std::array<unsigned int, 2>& channels) {
83  for (unsigned int channel : channels) {
84  channelMap.insert({l1t::demo::LinkId{"Algos", channel}, {l1t::demo::ChannelSpec{2, 0, 0}, {channel}}});
85  }
86  return channelMap;
87  }(channels_)),
88  linkData_(),
89  tmuxCounter_(0) {}
90 
92  const P2GTAlgoBlockMap& algoBlocks = event.get(algoBlocksToken_);
93 
94  auto algoBlockIt = algoBlocks.begin();
95  auto algoMaskIt = algoBitMask_.begin();
96 
97  for (unsigned int channel : channels_) {
98  if (tmuxCounter_ == 0) {
99  linkData_[{"Algos", channel}] = std::vector<ap_uint<64>>(18, 0);
100  }
101 
102  for (std::size_t word = 0; word < 9; word++) {
103  ap_uint<64> mask = algoMaskIt != algoBitMask_.end() ? *algoMaskIt++ : ~static_cast<unsigned long long>(0);
104 
105  for (std::size_t idx = 0; idx < 64 && algoBlockIt != algoBlocks.end(); idx++, algoBlockIt++) {
106  auto& [algoName, algoBlock] = *algoBlockIt;
107  linkData_[{"Algos", channel}][word + tmuxCounter_ * 9].set(
108  idx, algoBlock.decisionBeforeBxMaskAndPrescale() && mask.bit(idx));
109  }
110  }
111  }
112 
113  if (tmuxCounter_ == 1) {
115  }
116 
117  tmuxCounter_ = (tmuxCounter_ + 1) % 2;
118  eventCounter_++;
119 
120  if (maxEvents_ != 0 && eventCounter_ == maxEvents_) {
122  eventCounter_ = 0;
123  }
124 }
125 
127  if (tmuxCounter_ == 1) {
129  }
130 
132 }
133 
136  desc.addUntracked<std::string>("filename");
137  desc.addUntracked<std::string>("fileExtension", "txt");
138  desc.addUntracked<edm::InputTag>("algoBlocksTag");
139  desc.addUntracked<unsigned int>("maxEvents", 0);
140  desc.addUntracked<std::vector<unsigned int>>("channels");
141  desc.addUntracked<std::vector<unsigned long long>>("algoBitMask",
142  {0xffffffffffffffffull,
143  0xffffffffffffffffull,
144  0xffffffffffffffffull,
145  0xffffffffffffffffull,
146  0xffffffffffffffffull,
147  0xffffffffffffffffull,
148  0xffffffffffffffffull,
149  0xffffffffffffffffull,
150  0xffffffffffffffffull});
151  desc.addUntracked<unsigned int>("maxFrames", 1024);
152  desc.addUntracked<std::string>("patternFormat", "EMPv2");
153 
154  descriptions.addDefault(desc);
155 }
156 
const std::array< unsigned long long, 9 > algoBitMask_
Logical ID for link within any given time slice (e.g. ["tracks", 0] -> ["tracks", 17] for links from ...
Definition: LinkId.h:10
static std::array< T, N > convert(std::vector< T > vec, const char *name)
const edm::EDGetTokenT< P2GTAlgoBlockMap > algoBlocksToken_
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
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void analyze(const edm::Event &, const edm::EventSetup &) override
uint64_t word
void addDefault(ParameterSetDescription const &psetDescription)
L1GTAlgoBoardWriter(const edm::ParameterSet &)
const std::array< unsigned int, 2 > channels_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::map< LinkId, std::pair< ChannelSpec, std::vector< size_t > > > ChannelMap_t
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define N
Definition: blowfish.cc:9
std::map< l1t::demo::LinkId, std::vector< ap_uint< 64 > > > linkData_
HLT enums.
double a
Definition: hdecay.h:121
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
l1t::demo::BoardDataWriter boardDataWriter_
Definition: event.py:1