CMS 3D CMS Logo

L1TMP7ZeroSupp.cc
Go to the documentation of this file.
2 
3 #include <sstream>
4 
5 const unsigned int L1TMP7ZeroSupp::maxMasks_ = 16;
6 
8  : fedDataToken_(consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("rawData"))),
9  zsEnabled_(ps.getUntrackedParameter<bool>("zsEnabled")),
10  fedIds_(ps.getParameter<std::vector<int>>("fedIds")),
11  slinkHeaderSize_(ps.getUntrackedParameter<int>("lenSlinkHeader")),
12  slinkTrailerSize_(ps.getUntrackedParameter<int>("lenSlinkTrailer")),
13  amc13HeaderSize_(ps.getUntrackedParameter<int>("lenAMC13Header")),
14  amc13TrailerSize_(ps.getUntrackedParameter<int>("lenAMC13Trailer")),
15  amcHeaderSize_(ps.getUntrackedParameter<int>("lenAMCHeader")),
16  amcTrailerSize_(ps.getUntrackedParameter<int>("lenAMCTrailer")),
17  zsFlagMask_(ps.getUntrackedParameter<int>("zsFlagMask")),
18  maxFedReadoutSize_(ps.getUntrackedParameter<int>("maxFEDReadoutSize")),
19  monitorDir_(ps.getUntrackedParameter<std::string>("monitorDir")),
20  verbose_(ps.getUntrackedParameter<bool>("verbose"))
21 {
22  std::vector<int> zeroMask(6, 0);
23  masks_.reserve(maxMasks_);
24  for (unsigned int i = 0; i < maxMasks_; ++i) {
25  std::string maskCapIdStr{"maskCapId"+std::to_string(i)};
26  masks_.push_back(ps.getUntrackedParameter<std::vector<int>>(maskCapIdStr.c_str(), zeroMask));
27  // which masks are defined?
28  if (ps.exists(maskCapIdStr.c_str())) {
29  definedMaskCapIds_.push_back(i);
30  }
31  }
32  if (verbose_) {
33  // check masks
34  std::cout << "masks" << std::endl;
35  for (unsigned int i = 0; i < maxMasks_; ++i) {
36  std::cout << "caption ID" << i << ":" << std::endl;
37  for (const auto& maskIt: masks_.at(i)) {
38  std::cout << std::hex << std::setw(8) << std::setfill('0') << maskIt << std::dec << std::endl;
39  }
40  }
41  std::cout << "----------" << std::endl;
42  }
43 }
44 
46 
49  desc.add<edm::InputTag>("rawData");
50  desc.add<std::vector<int>>("fedIds")->setComment("FED ids to analyze.");
51  desc.addUntracked<bool>("zsEnabled", true)->setComment("MP7 zero suppression is enabled.");
52  desc.addUntracked<int>("lenSlinkHeader", 8)->setComment("Number of Slink header bytes.");
53  desc.addUntracked<int>("lenSlinkTrailer", 8)->setComment("Number of Slink trailer bytes.");
54  desc.addUntracked<int>("lenAMC13Header", 8)->setComment("Number of AMC13 header bytes.");
55  desc.addUntracked<int>("lenAMC13Trailer", 8)->setComment("Number of AMC13 trailer bytes.");
56  desc.addUntracked<int>("lenAMCHeader", 8)->setComment("Number of AMC header bytes.");
57  desc.addUntracked<int>("lenAMCTrailer", 0)->setComment("Number of AMC trailer bytes.");
58  desc.addUntracked<int>("zsFlagMask", 0x1)->setComment("Zero suppression flag mask.");
59  desc.addUntracked<int>("maxFEDReadoutSize", 10000)->setComment("Maximal FED readout size histogram x-axis value.");
60  for (unsigned int i = 0; i < maxMasks_; ++i) {
61  desc.addOptionalUntracked<std::vector<int>>(("maskCapId"+std::to_string(i)).c_str())->setComment(("ZS mask for caption id "+std::to_string(i)+".").c_str());
62  }
63  desc.addUntracked<std::string>("monitorDir", "")->setComment("Target directory in the DQM file. Will be created if not existing.");
64  desc.addUntracked<bool>("verbose", false);
65  descriptions.add("l1tMP7ZeroSupp", desc);
66 }
67 
69 
71 
73  // overall summary
76  capIds_ = ibooker.book1D("capIds", "Caption ids found in data", maxMasks_, 0, maxMasks_);
77  capIds_->setAxisTitle("caption id", 1);
78 
79  // per caption id subdirectories
80  std::stringstream ss;
81  for (const auto &id: definedMaskCapIds_) {
82  ss.str("");
83  ss << monitorDir_ << "/CapId" << id;
84  ibooker.setCurrentFolder(ss.str().c_str());
85  bookCapIdHistograms(ibooker, id);
86  }
87 }
88 
89 void L1TMP7ZeroSupp::bookCapIdHistograms(DQMStore::IBooker& ibooker, const unsigned int& id) {
90  std::string summaryTitleText = "Zero suppression validation summary";
91  std::string sizeTitleText;
92  if (id == maxMasks_) {
93  sizeTitleText = "FED readout ";
94  } else {
95  std::stringstream ss;
96  ss << summaryTitleText << ", caption id " << id;
97  summaryTitleText = ss.str();
98  ss.str("");
99  ss << "cumulated caption id " << id << " block ";
100  sizeTitleText = ss.str();
101  }
102 
103  zeroSuppValMap_[id] = ibooker.book1D("zeroSuppVal", summaryTitleText.c_str(), NBINLABELS, 0, NBINLABELS);
104  zeroSuppValMap_[id]->setAxisTitle("Block status", 1);
105  zeroSuppValMap_[id]->setBinLabel(EVTS+1, "events", 1);
106  zeroSuppValMap_[id]->setBinLabel(EVTSGOOD+1, "good events", 1);
107  zeroSuppValMap_[id]->setBinLabel(EVTSBAD+1, "bad events", 1);
108  zeroSuppValMap_[id]->setBinLabel(BLOCKS+1, "blocks", 1);
109  zeroSuppValMap_[id]->setBinLabel(ZSBLKSGOOD+1, "good blocks", 1);
110  zeroSuppValMap_[id]->setBinLabel(ZSBLKSBAD+1, "bad blocks", 1);
111  zeroSuppValMap_[id]->setBinLabel(ZSBLKSBADFALSEPOS+1, "false pos.", 1);
112  zeroSuppValMap_[id]->setBinLabel(ZSBLKSBADFALSENEG+1, "false neg.", 1);
113 
114  errorSummaryNumMap_[id] = ibooker.book1D("errorSummaryNum", summaryTitleText.c_str(), RNBINLABELS, 0, RNBINLABELS);
115  errorSummaryNumMap_[id]->setBinLabel(REVTS+1, "bad events", 1);
116  errorSummaryNumMap_[id]->setBinLabel(RBLKS+1, "bad blocks", 1);
117  errorSummaryNumMap_[id]->setBinLabel(RBLKSFALSEPOS+1, "false pos.", 1);
118  errorSummaryNumMap_[id]->setBinLabel(RBLKSFALSENEG+1, "false neg.", 1);
119 
120  errorSummaryDenMap_[id] = ibooker.book1D("errorSummaryDen", "denominators", RNBINLABELS, 0, RNBINLABELS);
121  errorSummaryDenMap_[id]->setBinLabel(REVTS+1, "# events", 1);
122  errorSummaryDenMap_[id]->setBinLabel(RBLKS+1, "# blocks", 1);
123  errorSummaryDenMap_[id]->setBinLabel(RBLKSFALSEPOS+1, "# blocks", 1);
124  errorSummaryDenMap_[id]->setBinLabel(RBLKSFALSENEG+1, "# blocks", 1);
125 
126  readoutSizeNoZSMap_[id] = ibooker.book1D("readoutSize", (sizeTitleText + "size").c_str(), 100, 0, maxFedReadoutSize_);
127  readoutSizeNoZSMap_[id]->setAxisTitle("size (byte)", 1);
128  readoutSizeZSMap_[id] = ibooker.book1D("readoutSizeZS", (sizeTitleText + "size with zero suppression").c_str(), 100, 0, maxFedReadoutSize_);
129  readoutSizeZSMap_[id]->setAxisTitle("size (byte)", 1);
130  readoutSizeZSExpectedMap_[id] = ibooker.book1D("readoutSizeZSExpected", ("Expected " + sizeTitleText + "size with zero suppression").c_str(), 100, 0, maxFedReadoutSize_);
131  readoutSizeZSExpectedMap_[id]->setAxisTitle("size (byte)", 1);
132 }
133 
135 
136  if (verbose_) edm::LogInfo("L1TDQM") << "L1TMP7ZeroSupp: analyze..." << std::endl;
137 
139  e.getByToken(fedDataToken_, feds);
140 
141  if (!feds.isValid()) {
142  edm::LogError("L1TDQM") << "Cannot analyse: no FEDRawDataCollection found";
143  return;
144  }
145 
148  for (const auto &id: definedMaskCapIds_) {
149  zeroSuppValMap_[id]->Fill(EVTS);
150  errorSummaryDenMap_[id]->Fill(REVTS);
151  }
152 
153  std::map<unsigned int, bool> evtGood;
154  evtGood[maxMasks_] = true;
155  for (const auto &id: definedMaskCapIds_) {
156  evtGood[id] = true;
157  }
158  unsigned valid_count = 0;
159  for (const auto& fedId: fedIds_) {
160  const FEDRawData& l1tRcd = feds->FEDData(fedId);
161 
162  unsigned int fedDataSize = l1tRcd.size();
163  std::map<unsigned int, unsigned int> readoutSizeNoZSMap;
164  std::map<unsigned int, unsigned int> readoutSizeZSMap;
165  std::map<unsigned int, unsigned int> readoutSizeZSExpectedMap;
166  readoutSizeNoZSMap[maxMasks_] = 0;
167  readoutSizeZSMap[maxMasks_] = 0;
168  readoutSizeZSExpectedMap[maxMasks_] = 0;
169  for (const auto &id: definedMaskCapIds_) {
170  readoutSizeNoZSMap[id] = 0;
171  readoutSizeZSMap[id] = 0;
172  readoutSizeZSExpectedMap[id] = 0;
173  }
174 
175  edm::LogInfo("L1TDQM") << "Found FEDRawDataCollection with ID " << fedId << " and size " << l1tRcd.size();
176 
178  if (l1tRcd.size() > 0) {
179  edm::LogError("L1TDQM") << "Cannot analyse: invalid L1T raw data (size = " << l1tRcd.size() << ") for ID " << fedId << ".";
180  }
181  continue;
182  } else {
183  valid_count++;
184  }
185 
186  const unsigned char *data = l1tRcd.data();
187  FEDHeader header(data);
188 
189  if (header.check()) {
190  edm::LogInfo("L1TDQM") << "Found SLink header:" << " Trigger type " << header.triggerType() << " L1 event ID " << header.lvl1ID() << " BX Number " << header.bxID() << " FED source " << header.sourceID() << " FED version " << header.version();
191  } else {
192  edm::LogWarning("L1TDQM") << "Did not find a SLink header!";
193  }
194 
195  FEDTrailer trailer(data + (l1tRcd.size() - slinkTrailerSize_));
196 
197  if (trailer.check()) {
198  edm::LogInfo("L1TDQM") << "Found SLink trailer:" << " Length " << trailer.lenght() << " CRC " << trailer.crc() << " Status " << trailer.evtStatus() << " Throttling bits " << trailer.ttsBits();
199  } else {
200  edm::LogWarning("L1TDQM") << "Did not find a SLink trailer!";
201  }
202 
203  amc13::Packet packet;
204  if (!packet.parse(
205  (const uint64_t*) data,
206  (const uint64_t*) (data + slinkHeaderSize_),
207  (l1tRcd.size() - slinkHeaderSize_ - slinkTrailerSize_) / 8,
208  header.lvl1ID(),
209  header.bxID())) {
210  edm::LogError("L1TDQM") << "Could not extract AMC13 Packet.";
211  return;
212  }
213 
214  for (auto& amc: packet.payload()) {
215  if (amc.size() == 0)
216  continue;
217 
218  auto payload64 = amc.data();
219  const uint32_t * start = (const uint32_t*) payload64.get();
220  // Want to have payload size in 32 bit words, but AMC measures
221  // it in 64 bit words -> factor 2.
222  const uint32_t * end = start + (amc.size() * 2);
223 
224  std::unique_ptr<l1t::Payload> payload;
225  payload.reset(new l1t::MP7Payload(start, end, false));
226 
227  // getBlock() returns a non-null unique_ptr on success
228  std::unique_ptr<l1t::Block> block;
229  while ((block = payload->getBlock()).get()) {
230  if (verbose_) {
231  std::cout << ">>> check zero suppression for block <<<" << std::endl
232  << "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw() << std::dec
233  << " (ID " << block->header().getID() << ", size " << block->header().getSize()
234  << ", CapID 0x" << std::hex << std::setw(2) << std::setfill('0') << block->header().getCapID()
235  << ", flags 0x" << std::hex << std::setw(2) << std::setfill('0') << block->header().getFlags()
236  << ")" << std::dec << std::endl;
237  for (const auto& word: block->payload()) {
238  std::cout << "data: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec << std::endl;
239  }
240  }
241 
242  unsigned int blockCapId = block->header().getCapID();
243  unsigned int blockSize = block->header().getSize() * 4;
244  unsigned int blockHeaderSize = sizeof(block->header().raw());
245  bool zsFlagSet = ((block->header().getFlags() & zsFlagMask_) != 0);
246  bool toSuppress = false;
247 
248  capIds_->Fill(blockCapId);
249 
250  bool capIdDefined = false;
255  if (zeroSuppValMap_.find(blockCapId) != zeroSuppValMap_.end()) {
256  capIdDefined = true;
257  zeroSuppValMap_[blockCapId]->Fill(BLOCKS);
258  errorSummaryDenMap_[blockCapId]->Fill(RBLKS);
259  errorSummaryDenMap_[blockCapId]->Fill(RBLKSFALSEPOS);
260  errorSummaryDenMap_[blockCapId]->Fill(RBLKSFALSENEG);
261  }
262 
263  auto totalBlockSize = blockSize + blockHeaderSize;
264  readoutSizeNoZSMap[maxMasks_] += totalBlockSize;
265  if (capIdDefined) {
266  readoutSizeNoZSMap[blockCapId] += totalBlockSize;
267  }
268 
269  // check if this block should be suppressed
270  unsigned int wordcounter = 0;
271  unsigned int wordsum = 0;
272  for (const auto& word: block->payload()) {
273  wordsum += masks_[blockCapId].at(wordcounter%6) & word;
274  if (verbose_) {
275  std::cout << "word: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec
276  << ", maskword" << wordcounter%6 << ": " << std::hex << std::setw(8) << std::setfill('0')
277  << masks_[blockCapId].at(wordcounter%6) << std::dec << ", wordsum: " << wordsum << std::endl;
278  }
279  if (wordsum > 0) {
280  break;
281  }
282  ++wordcounter;
283  }
284  if (wordsum == 0 && zsEnabled_) {
285  toSuppress = true;
286  if (verbose_) {
287  std::cout << "wordsum == 0: this block should be zero suppressed" << std::endl;
288  }
289  }
290 
291  // check if zero suppression flag agrees
292  if (toSuppress && zsFlagSet) {
293  if (verbose_) std::cout << "GOOD block with ZS flag true" << std::endl;
295  if (capIdDefined) {
296  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSGOOD);
297  }
298  } else if (!toSuppress && !zsFlagSet) {
299  if (verbose_) std::cout << "GOOD block with ZS flag false" << std::endl;
301  readoutSizeZSMap[maxMasks_] += totalBlockSize;
302  readoutSizeZSExpectedMap[maxMasks_] += totalBlockSize;
303  if (capIdDefined) {
304  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSGOOD);
305  readoutSizeZSMap[blockCapId] += totalBlockSize;
306  readoutSizeZSExpectedMap[blockCapId] += totalBlockSize;
307  }
308  } else if (!toSuppress && zsFlagSet) {
309  if (verbose_) std::cout << "BAD block with ZS flag true" << std::endl;
314  readoutSizeZSExpectedMap[maxMasks_] += totalBlockSize;
315  evtGood[maxMasks_] = false;
316  if (capIdDefined) {
317  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSBAD);
318  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSBADFALSEPOS);
319  errorSummaryNumMap_[blockCapId]->Fill(RBLKS);
320  errorSummaryNumMap_[blockCapId]->Fill(RBLKSFALSEPOS);
321  readoutSizeZSExpectedMap[blockCapId] += totalBlockSize;
322  evtGood[blockCapId] = false;
323  }
324  } else {
325  if (verbose_) std::cout << "BAD block with ZS flag false" << std::endl;
330  readoutSizeZSMap[maxMasks_] += totalBlockSize;
331  evtGood[maxMasks_] = false;
332  if (capIdDefined) {
333  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSBAD);
334  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSBADFALSENEG);
335  errorSummaryNumMap_[blockCapId]->Fill(RBLKS);
336  errorSummaryNumMap_[blockCapId]->Fill(RBLKSFALSENEG);
337  readoutSizeZSMap[blockCapId] += totalBlockSize;
338  evtGood[blockCapId] = false;
339  }
340  }
341  }
342  }
343  readoutSizeNoZSMap_[maxMasks_]->Fill(fedDataSize);
344  readoutSizeZSMap_[maxMasks_]->Fill(readoutSizeZSMap[maxMasks_] + fedDataSize - readoutSizeNoZSMap[maxMasks_]);
345  readoutSizeZSExpectedMap_[maxMasks_]->Fill(readoutSizeZSExpectedMap[maxMasks_] + fedDataSize - readoutSizeNoZSMap[maxMasks_]);
346  for (const auto &id: definedMaskCapIds_) {
347  readoutSizeNoZSMap_[id]->Fill(readoutSizeNoZSMap[id]);
348  readoutSizeZSMap_[id]->Fill(readoutSizeZSMap[id]);
349  readoutSizeZSExpectedMap_[id]->Fill(readoutSizeZSExpectedMap[id]);
350  }
351  }
352 
353  if (evtGood[maxMasks_]) {
355  } else {
358  }
359  for (const auto &id: definedMaskCapIds_) {
360  if (evtGood[id]) {
361  zeroSuppValMap_[id]->Fill(EVTSGOOD);
362  } else {
363  zeroSuppValMap_[id]->Fill(EVTSBAD);
364  errorSummaryNumMap_[id]->Fill(REVTS);
365  }
366  }
367 }
368 
Definition: start.py:1
std::vector< amc::Packet > payload() const
Definition: AMC13Spec.h:80
std::map< unsigned int, MonitorElement * > readoutSizeZSExpectedMap_
T getUntrackedParameter(std::string const &, T const &) const
bool check()
Definition: FEDTrailer.cc:64
std::map< unsigned int, MonitorElement * > zeroSuppValMap_
int version()
Version identifier of the FED data format.
Definition: FEDHeader.cc:32
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
edm::EDGetTokenT< FEDRawDataCollection > fedDataToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
virtual void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
std::map< unsigned int, MonitorElement * > readoutSizeNoZSMap_
int evtStatus()
Event fragment status information.
Definition: FEDTrailer.cc:27
L1TMP7ZeroSupp(const edm::ParameterSet &ps)
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string monitorDir_
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void Fill(long long x)
std::map< unsigned int, MonitorElement * > errorSummaryNumMap_
void bookCapIdHistograms(DQMStore::IBooker &, const unsigned int &)
std::vector< unsigned int > definedMaskCapIds_
int sourceID()
Identifier of the FED.
Definition: FEDHeader.cc:28
payload
payload postfix for testing
MonitorElement * capIds_
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
std::map< unsigned int, MonitorElement * > errorSummaryDenMap_
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
std::vector< std::vector< int > > masks_
#define end
Definition: vmac.h:37
static const unsigned int maxMasks_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
int ttsBits()
Current value of the Trigger Throttling System bitsAQ).
Definition: FEDTrailer.cc:32
bool check()
Check that the header is OK.
Definition: FEDHeader.cc:64
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
unsigned long long uint64_t
Definition: Time.h:15
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:17
bool parse(const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false)
Definition: AMC13Spec.cc:70
int bxID()
The bunch crossing number.
Definition: FEDHeader.cc:24
void add(std::string const &label, ParameterSetDescription const &psetDescription)
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
int crc()
Cyclic Redundancy Code of the event fragment including header and trailer.
Definition: FEDTrailer.cc:22
std::vector< int > fedIds_
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void bookHistograms(DQMStore::IBooker &, const edm::Run &, const edm::EventSetup &) override
int lvl1ID()
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:20
Definition: AMCSpec.h:8
std::map< unsigned int, MonitorElement * > readoutSizeZSMap_
int triggerType()
Event Trigger type identifier.
Definition: FEDHeader.cc:16
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
virtual ~L1TMP7ZeroSupp()
Definition: Run.h:42