CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TMP7ZeroSupp.cc
Go to the documentation of this file.
2 
3 #include <sstream>
4 
5 
7  : fedDataToken_(consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("rawData"))),
8  zsEnabled_(ps.getUntrackedParameter<bool>("zsEnabled", true)),
9  fedIds_(ps.getParameter<std::vector<int>>("fedIds")),
10  slinkHeaderSize_(ps.getUntrackedParameter<int>("lenSlinkHeader", 8)),
11  slinkTrailerSize_(ps.getUntrackedParameter<int>("lenSlinkTrailer", 8)),
12  amc13HeaderSize_(ps.getUntrackedParameter<int>("lenAMC13Header", 8)),
13  amc13TrailerSize_(ps.getUntrackedParameter<int>("lenAMC13Trailer", 8)),
14  amcHeaderSize_(ps.getUntrackedParameter<int>("lenAMCHeader", 8)),
15  amcTrailerSize_(ps.getUntrackedParameter<int>("lenAMCTrailer", 0)),
16  zsFlagMask_(ps.getUntrackedParameter<int>("zsFlagMask", 0x1)),
17  maxFedReadoutSize_(ps.getUntrackedParameter<int>("maxFEDReadoutSize", 10000)),
18  monitorDir_(ps.getUntrackedParameter<std::string>("monitorDir", "")),
19  verbose_(ps.getUntrackedParameter<bool>("verbose", false)),
20  maxMasks_(16)
21 {
22  std::vector<int> zeroMask(6, 0);
23  masks_.reserve(maxMasks_);
24  std::stringstream ss;
25  for (unsigned int i = 0; i < maxMasks_; ++i) {
26  ss.str("");
27  ss << "maskCapId" << i;
28  masks_.push_back(ps.getUntrackedParameter<std::vector<int>>(ss.str().c_str(), zeroMask));
29  // which masks are defined?
30  if (ps.exists(ss.str().c_str())) {
31  definedMaskCapIds_.push_back(i);
32  }
33  }
34  if (verbose_) {
35  // check masks
36  std::cout << "masks" << std::endl;
37  for (unsigned int i = 0; i < maxMasks_; ++i) {
38  std::cout << "caption ID" << i << ":" << std::endl;
39  for (const auto& maskIt: masks_.at(i)) {
40  std::cout << std::hex << std::setw(8) << std::setfill('0') << maskIt << std::dec << std::endl;
41  }
42  }
43  std::cout << "----------" << std::endl;
44  }
45 }
46 
48 
50 
52 
54  // overall summary
57  capIds_ = ibooker.book1D("capIds", "Caption ids found in data", maxMasks_, 0, maxMasks_);
58  capIds_->setAxisTitle("caption id", 1);
59 
60  // per caption id subdirectories
61  std::stringstream ss;
62  for (const auto &id: definedMaskCapIds_) {
63  ss.str("");
64  ss << monitorDir_ << "/CapId" << id;
65  ibooker.setCurrentFolder(ss.str().c_str());
66  bookCapIdHistograms(ibooker, id);
67  }
68 }
69 
70 void L1TMP7ZeroSupp::bookCapIdHistograms(DQMStore::IBooker& ibooker, const unsigned int& id) {
71  std::string summaryTitleText = "Zero suppression validation summary";
72  std::string sizeTitleText;
73  if (id == maxMasks_) {
74  sizeTitleText = "FED readout ";
75  } else {
76  std::stringstream ss;
77  ss << summaryTitleText << ", caption id " << id;
78  summaryTitleText = ss.str();
79  ss.str("");
80  ss << "cumulated caption id " << id << " block ";
81  sizeTitleText = ss.str();
82  }
83 
84  zeroSuppValMap_[id] = ibooker.book1D("zeroSuppVal", summaryTitleText.c_str(), NBINLABELS, 0, NBINLABELS);
85  zeroSuppValMap_[id]->setAxisTitle("Block status", 1);
86  zeroSuppValMap_[id]->setBinLabel(EVTS+1, "events", 1);
87  zeroSuppValMap_[id]->setBinLabel(EVTSGOOD+1, "good events", 1);
88  zeroSuppValMap_[id]->setBinLabel(EVTSBAD+1, "bad events", 1);
89  zeroSuppValMap_[id]->setBinLabel(BLOCKS+1, "blocks", 1);
90  zeroSuppValMap_[id]->setBinLabel(ZSBLKSGOOD+1, "good blocks", 1);
91  zeroSuppValMap_[id]->setBinLabel(ZSBLKSBAD+1, "bad blocks", 1);
92  zeroSuppValMap_[id]->setBinLabel(ZSBLKSBADFALSEPOS+1, "false pos.", 1);
93  zeroSuppValMap_[id]->setBinLabel(ZSBLKSBADFALSENEG+1, "false neg.", 1);
94 
95  readoutSizeNoZSMap_[id] = ibooker.book1D("readoutSizeNoZS", (sizeTitleText + "size without zero suppression").c_str(), 100, 0, maxFedReadoutSize_);
96  readoutSizeNoZSMap_[id]->setAxisTitle("size (byte)", 1);
97  readoutSizeZSMap_[id] = ibooker.book1D("readoutSizeZS", (sizeTitleText + "size with zero suppression").c_str(), 100, 0, maxFedReadoutSize_);
98  readoutSizeZSMap_[id]->setAxisTitle("size (byte)", 1);
99  readoutSizeZSExpectedMap_[id] = ibooker.book1D("readoutSizeZSExpected", ("Expected " + sizeTitleText + "size with zero suppression").c_str(), 100, 0, maxFedReadoutSize_);
100  readoutSizeZSExpectedMap_[id]->setAxisTitle("size (byte)", 1);
101 }
102 
104 
105  if (verbose_) edm::LogInfo("L1TDQM") << "L1TMP7ZeroSupp: analyze..." << std::endl;
106 
108  e.getByToken(fedDataToken_, feds);
109 
110  if (!feds.isValid()) {
111  edm::LogError("L1TDQM") << "Cannot analyse: no FEDRawDataCollection found";
112  return;
113  }
114 
116  for (const auto &id: definedMaskCapIds_) {
117  zeroSuppValMap_[id]->Fill(EVTS);
118  }
119 
120  std::map<unsigned int, bool> evtGood;
121  evtGood[maxMasks_] = true;
122  for (const auto &id: definedMaskCapIds_) {
123  evtGood[id] = true;
124  }
125  unsigned valid_count = 0;
126  for (const auto& fedId: fedIds_) {
127  const FEDRawData& l1tRcd = feds->FEDData(fedId);
128 
129  unsigned int fedDataSize = l1tRcd.size();
130  std::map<unsigned int, unsigned int> readoutSizeNoZSMap;
131  std::map<unsigned int, unsigned int> readoutSizeZSMap;
132  std::map<unsigned int, unsigned int> readoutSizeZSExpectedMap;
133  readoutSizeNoZSMap[maxMasks_] = 0;
134  readoutSizeZSMap[maxMasks_] = 0;
135  readoutSizeZSExpectedMap[maxMasks_] = 0;
136  for (const auto &id: definedMaskCapIds_) {
137  readoutSizeNoZSMap[id] = 0;
138  readoutSizeZSMap[id] = 0;
139  readoutSizeZSExpectedMap[id] = 0;
140  }
141 
142  edm::LogInfo("L1TDQM") << "Found FEDRawDataCollection with ID " << fedId << " and size " << l1tRcd.size();
143 
145  if (l1tRcd.size() > 0) {
146  edm::LogError("L1TDQM") << "Cannot analyse: invalid L1T raw data (size = " << l1tRcd.size() << ") for ID " << fedId << ".";
147  }
148  continue;
149  } else {
150  valid_count++;
151  }
152 
153  const unsigned char *data = l1tRcd.data();
154  FEDHeader header(data);
155 
156  if (header.check()) {
157  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();
158  } else {
159  edm::LogWarning("L1TDQM") << "Did not find a SLink header!";
160  }
161 
162  FEDTrailer trailer(data + (l1tRcd.size() - slinkTrailerSize_));
163 
164  if (trailer.check()) {
165  edm::LogInfo("L1TDQM") << "Found SLink trailer:" << " Length " << trailer.lenght() << " CRC " << trailer.crc() << " Status " << trailer.evtStatus() << " Throttling bits " << trailer.ttsBits();
166  } else {
167  edm::LogWarning("L1TDQM") << "Did not find a SLink trailer!";
168  }
169 
170  amc13::Packet packet;
171  if (!packet.parse(
172  (const uint64_t*) data,
173  (const uint64_t*) (data + slinkHeaderSize_),
174  (l1tRcd.size() - slinkHeaderSize_ - slinkTrailerSize_) / 8,
175  header.lvl1ID(),
176  header.bxID())) {
177  edm::LogError("L1TDQM") << "Could not extract AMC13 Packet.";
178  return;
179  }
180 
181  for (auto& amc: packet.payload()) {
182  if (amc.size() == 0)
183  continue;
184 
185  auto payload64 = amc.data();
186  const uint32_t * start = (const uint32_t*) payload64.get();
187  // Want to have payload size in 32 bit words, but AMC measures
188  // it in 64 bit words -> factor 2.
189  const uint32_t * end = start + (amc.size() * 2);
190 
191  std::unique_ptr<l1t::Payload> payload;
192  payload.reset(new l1t::MP7Payload(start, end, false));
193 
194  // getBlock() returns a non-null unique_ptr on success
195  std::unique_ptr<l1t::Block> block;
196  while ((block = payload->getBlock()).get()) {
197  if (verbose_) {
198  std::cout << ">>> check zero suppression for block <<<" << std::endl
199  << "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw() << std::dec
200  << " (ID " << block->header().getID() << ", size " << block->header().getSize()
201  << ", CapID 0x" << std::hex << std::setw(2) << std::setfill('0') << block->header().getCapID()
202  << ")" << std::dec << std::endl;
203  for (const auto& word: block->payload()) {
204  if (verbose_) std::cout << "data: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec << std::endl;
205  }
206  }
207 
208  unsigned int blockCapId = block->header().getCapID();
209  unsigned int blockSize = block->header().getSize() * 4;
210  unsigned int blockHeaderSize = sizeof(block->header().raw());
211  bool zsFlagSet = ((block->header().raw() & zsFlagMask_) != 0);
212  bool toSuppress = false;
213 
214  capIds_->Fill(blockCapId);
215 
216  bool capIdDefined = false;
218  if (zeroSuppValMap_.find(blockCapId) != zeroSuppValMap_.end()) {
219  capIdDefined = true;
220  zeroSuppValMap_[blockCapId]->Fill(BLOCKS);
221  }
222 
223  auto totalBlockSize = blockSize + blockHeaderSize;
224  readoutSizeNoZSMap[maxMasks_] += totalBlockSize;
225  if (capIdDefined) {
226  readoutSizeNoZSMap[blockCapId] += totalBlockSize;
227  }
228 
229  // check if this block should be suppressed
230  unsigned int wordcounter = 0;
231  unsigned int wordsum = 0;
232  for (const auto& word: block->payload()) {
233  wordsum += masks_[blockCapId].at(wordcounter%6) & word;
234  if (verbose_) {
235  std::cout << "word: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec
236  << ", maskword" << wordcounter%6 << ": " << std::hex << std::setw(8) << std::setfill('0')
237  << masks_[blockCapId].at(wordcounter%6) << std::dec << ", wordsum: " << wordsum << std::endl;
238  }
239  if (wordsum > 0) {
240  break;
241  }
242  ++wordcounter;
243  }
244  if (wordsum == 0 && zsEnabled_) {
245  toSuppress = true;
246  if (verbose_) {
247  std::cout << "wordsum == 0: this block should be zero suppressed" << std::endl;
248  }
249  }
250 
251  // check if zero suppression flag agrees
252  if (toSuppress && zsFlagSet) {
254  if (capIdDefined) {
255  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSGOOD);
256  }
257  } else if (!toSuppress && !zsFlagSet) {
259  readoutSizeZSMap[maxMasks_] += totalBlockSize;
260  readoutSizeZSExpectedMap[maxMasks_] += totalBlockSize;
261  if (capIdDefined) {
262  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSGOOD);
263  readoutSizeZSMap[blockCapId] += totalBlockSize;
264  readoutSizeZSExpectedMap[blockCapId] += totalBlockSize;
265  }
266  } else if (!toSuppress && zsFlagSet) {
269  readoutSizeZSExpectedMap[maxMasks_] += totalBlockSize;
270  evtGood[maxMasks_] = false;
271  if (capIdDefined) {
272  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSBAD);
273  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSBADFALSEPOS);
274  readoutSizeZSExpectedMap[blockCapId] += totalBlockSize;
275  evtGood[blockCapId] = false;
276  }
277  } else {
280  readoutSizeZSMap[maxMasks_] += totalBlockSize;
281  evtGood[maxMasks_] = false;
282  if (capIdDefined) {
283  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSBAD);
284  zeroSuppValMap_[blockCapId]->Fill(ZSBLKSBADFALSENEG);
285  readoutSizeZSMap[blockCapId] += totalBlockSize;
286  evtGood[blockCapId] = false;
287  }
288  }
289  }
290  }
291  readoutSizeNoZSMap_[maxMasks_]->Fill(fedDataSize);
292  readoutSizeZSMap_[maxMasks_]->Fill(readoutSizeZSMap[maxMasks_] + fedDataSize - readoutSizeNoZSMap[maxMasks_]);
293  readoutSizeZSExpectedMap_[maxMasks_]->Fill(readoutSizeZSExpectedMap[maxMasks_] + fedDataSize - readoutSizeNoZSMap[maxMasks_]);
294  for (const auto &id: definedMaskCapIds_) {
295  readoutSizeNoZSMap_[id]->Fill(readoutSizeNoZSMap[id]);
296  readoutSizeZSMap_[id]->Fill(readoutSizeZSMap[id]);
297  readoutSizeZSExpectedMap_[id]->Fill(readoutSizeZSExpectedMap[id]);
298  }
299  }
300 
301  if (evtGood[maxMasks_]) {
303  } else {
305  }
306  for (const auto &id: definedMaskCapIds_) {
307  if (evtGood[id]) {
308  zeroSuppValMap_[id]->Fill(EVTSGOOD);
309  } else {
310  zeroSuppValMap_[id]->Fill(EVTSBAD);
311  }
312  }
313 }
314 
std::vector< amc::Packet > payload() const
Definition: AMC13Spec.h:80
std::map< unsigned int, MonitorElement * > readoutSizeZSExpectedMap_
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
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
unsigned int maxMasks_
edm::EDGetTokenT< FEDRawDataCollection > fedDataToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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)
void bookCapIdHistograms(DQMStore::IBooker &, const unsigned int &)
std::vector< unsigned int > definedMaskCapIds_
int sourceID()
Identifier of the FED.
Definition: FEDHeader.cc:28
MonitorElement * capIds_
double amc
Definition: hdecay.h:20
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
std::vector< std::vector< int > > masks_
#define end
Definition: vmac.h:37
bool isValid() const
Definition: HandleBase.h:75
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
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
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_
tuple cout
Definition: gather_cfg.py:145
virtual void bookHistograms(DQMStore::IBooker &, const edm::Run &, const edm::EventSetup &) override
volatile std::atomic< bool > shutdown_flag false
int lvl1ID()
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:20
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