CMS 3D CMS Logo

SiStripFEDDataCheck.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DQM/SiStripMonitorHardware
4 // Class: SiStripFEDCheckPlugin
5 //
10 //
11 // Original Author: Nicholas Cripps
12 // Created: 2008/09/16
13 //
14 //
15 #include <memory>
16 
30 
37 
40 
43 
45 
46 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh"
47 
49 
50 //
51 // Class declaration
52 //
53 
55 {
56  public:
58  ~SiStripFEDCheckPlugin() override;
59  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
60 
61  private:
62  void analyze(const edm::Event&, const edm::EventSetup&) override;
63  void endRun(edm::Run const&, edm::EventSetup const&) override;
64 
65  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
66 
67  bool hasFatalError(const FEDRawData& fedData, unsigned int fedId) const;
68  bool hasNonFatalError(const FEDRawData& fedData, unsigned int fedId) const;
69  void updateCabling(const edm::EventSetup& eventSetup);
70 
71  inline void fillPresent(unsigned int fedId, bool present);
72  inline void fillFatalError(unsigned int fedId, bool fatalError);
73  inline void fillNonFatalError(unsigned int fedId, float nonFatalError);
74 
75  void doUpdateIfNeeded();
76  void updateHistograms();
77 
78 
83 
84  //Histograms
90 
93 
94  //For histogram cache
95  unsigned int updateFrequency_;//Update histograms with cached values every n events. If zero then fill normally every event
96  //cache values
97  std::vector<unsigned int> fedsPresentBinContents_;
98  std::vector<unsigned int> fedFatalErrorBinContents_;
99  std::vector<unsigned int> fedNonFatalErrorBinContents_;
100  unsigned int eventCount_;//incremented by doUpdateIfNeeded()
101 
102  //Fine grained control of tests
104 
105  //Cabling
106  uint32_t cablingCacheId_;
108 
109  unsigned int siStripFedIdMin_;
110  unsigned int siStripFedIdMax_;
111 
113 };
114 
115 
116 //
117 // Constructors and destructor
118 //
119 
121  : rawDataTag_ (iConfig.getParameter<edm::InputTag>("RawDataTag"))
122  , dirName_ (iConfig.getUntrackedParameter<std::string>("DirName","SiStrip/FEDIntegrity/"))
123  , printDebug_ (iConfig.getUntrackedParameter<bool>("PrintDebugMessages",false))
124  , doPLOTfedsPresent_ (iConfig.getParameter<bool>("doPLOTfedsPresent") )
125  , doPLOTfedFatalErrors_ (iConfig.getParameter<bool>("doPLOTfedFatalErrors") )
126  , doPLOTfedNonFatalErrors_ (iConfig.getParameter<bool>("doPLOTfedNonFatalErrors"))
127  , doPLOTnFEDinVsLS_ (iConfig.getParameter<bool>("doPLOTnFEDinVsLS") )
128  , doPLOTnFEDinWdataVsLS_ (iConfig.getParameter<bool>("doPLOTnFEDinWdataVsLS") )
132  , nFEDinVsLS_ (nullptr)
134  , updateFrequency_(iConfig.getUntrackedParameter<unsigned int>("HistogramUpdateFrequency",0))
135  , fedsPresentBinContents_ (FEDNumbering::MAXSiStripFEDID+1,0)
136  , fedFatalErrorBinContents_ (FEDNumbering::MAXSiStripFEDID+1,0)
137  , fedNonFatalErrorBinContents_(FEDNumbering::MAXSiStripFEDID+1,0)
138  , eventCount_(0)
139  , doPayloadChecks_ (iConfig.getUntrackedParameter<bool>("DoPayloadChecks", true))
140  , checkChannelLengths_ (iConfig.getUntrackedParameter<bool>("CheckChannelLengths", true))
141  , checkPacketCodes_ (iConfig.getUntrackedParameter<bool>("CheckChannelPacketCodes",true))
142  , checkFELengths_ (iConfig.getUntrackedParameter<bool>("CheckFELengths", true))
143  , checkChannelStatusBits_(iConfig.getUntrackedParameter<bool>("CheckChannelStatus", true))
144  , verbose_ (iConfig.getUntrackedParameter<bool>("verbose", false))
145  , cablingCacheId_(0)
146 {
147  rawDataToken_ = consumes<FEDRawDataCollection>(rawDataTag_);
149  std::stringstream ss;
150  ss << "Payload checks are disabled but individual payload checks have been enabled. The following payload checks will be skipped: ";
151  if (checkChannelLengths_) ss << "Channel length check, ";
152  if (checkPacketCodes_) ss << "Channel packet code check, ";
153  if (checkChannelStatusBits_) ss << "Cabled channel status bits checks, ";
154  if (checkFELengths_) ss << "FE Unit legnth check";
155  edm::LogWarning("SiStripFEDCheck") << ss.str();
156  }
157 
160 
161  conf_ = iConfig;
162 }
163 
165 {
166 }
167 
168 
169 //
170 // Member functions
171 //
172 
173 // ------------ method called to for each event ------------
174 void
176 {
177  //Retrieve tracker topology from geometry
178  edm::ESHandle<TrackerTopology> tTopoHandle;
179  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
180  const TrackerTopology* const tTopo = tTopoHandle.product();
181 
182  //update cabling
183  updateCabling(iSetup);
184 
185  //get raw data
186  edm::Handle<FEDRawDataCollection> rawDataCollectionHandle;
187  const bool gotData = iEvent.getByToken(rawDataToken_,rawDataCollectionHandle);
188  if (verbose_) std::cout << "[SiStripFEDCheckPlugin::analyze] gotData ? " << (gotData ? "YES" : "NOPE") << std::endl;
189  if (!gotData) {
190  //module is required to silently do nothing when data is not present
191  return;
192  }
193  const FEDRawDataCollection& rawDataCollection = *rawDataCollectionHandle;
194 
195  //FED errors
196  FEDErrors lFedErrors;
197 
198  //loop over siStrip FED IDs
199  size_t nFEDin = 0;
200  size_t nFEDinWdata = 0;
201  for (unsigned int fedId = siStripFedIdMin_; fedId <= siStripFedIdMax_; fedId++) {
202  const FEDRawData& fedData = rawDataCollection.FEDData(fedId);
203 
204  //create an object to fill all errors
205  //third param to false:save time by not initialising anything not used here
206  lFedErrors.initialiseFED(fedId,cabling_,tTopo,false);
207 
208  //check data exists
209  if (!fedData.size() || !fedData.data()) {
210  fillPresent(fedId,false);
211  continue;
212  }
213  if (verbose_) std::cout << "FED " << fedId;
214  if (verbose_) std::cout << " fedData.size(): " << fedData.size();
215  if (verbose_) std::cout << " fedData.data(): " << fedData.data() << std::endl;
216  if (fedData.size()) nFEDin++;
217  if (fedData.size() && fedData.data()) nFEDinWdata++;
218 
219  //fill buffer present histogram
220  fillPresent(fedId,true);
221 
222  //check for fatal errors
223  //no need for debug output
224  bool hasFatalErrors = false;
225  float rateNonFatal = 0;
226 
227  std::auto_ptr<const sistrip::FEDBuffer> buffer;
228 
229  if (!lFedErrors.fillFatalFEDErrors(fedData,0)) {
230  hasFatalErrors = true;
231  }
232  else {
233  //need to construct full object to go any further
235 
236  buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
237  if (doPayloadChecks_) {
238 
239  bool channelLengthsOK = checkChannelLengths_ ? buffer->checkChannelLengthsMatchBufferLength() : true;
240  bool channelPacketCodesOK = checkPacketCodes_ ? buffer->checkChannelPacketCodes() : true;
241  bool feLengthsOK = checkFELengths_ ? buffer->checkFEUnitLengths() : true;
242  if ( !channelLengthsOK ||
243  !channelPacketCodesOK ||
244  !feLengthsOK ) {
245  hasFatalErrors = true;
246  }
247  }
248  if (checkChannelStatusBits_) rateNonFatal = lFedErrors.fillNonFatalFEDErrors(buffer.get(),cabling_);
249  }
250  }
251 
252  if (hasFatalErrors) {
253  fillFatalError(fedId,true);
254  if (printDebug_) {
255  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
256  edm::LogInfo("SiStripFEDCheck") << "Fatal error with FED ID " << fedId << ". Check summary: "
257  << std::endl << buffer->checkSummary() << std::endl;
258  std::stringstream ss;
259  buffer->dump(ss);
260  edm::LogInfo("SiStripFEDCheck") << ss.str();
261  }
262  }
263  else {
264  fillFatalError(fedId,false);
265  //fill non-fatal errors histogram if there were no fatal errors
266  fillNonFatalError(fedId,rateNonFatal);
267  if (printDebug_ && rateNonFatal > 0) {
268  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
269  edm::LogInfo("SiStripFEDCheck") << "Non-fatal error with FED ID " << fedId
270  << " for " << rateNonFatal << " of the channels. Check summary: "
271  << std::endl << buffer->checkSummary() << std::endl;
272  std::stringstream ss;
273  buffer->dump(ss);
274  edm::LogInfo("SiStripFEDCheck") << ss.str();
275  }
276 
277  }
278  }//loop over FED IDs
279  if (verbose_) std::cout << "nFEDin: " << nFEDin << " nFEDinWdata: " << nFEDinWdata << std::endl;
280  if (doPLOTnFEDinVsLS_) nFEDinVsLS_ -> Fill(static_cast<double>(iEvent.id().luminosityBlock()),nFEDin);
281  if (doPLOTnFEDinWdataVsLS_) nFEDinWdataVsLS_ -> Fill(static_cast<double>(iEvent.id().luminosityBlock()),nFEDinWdata);
282 
283  //update histograms if needed
285 }
286 
287 // ------------ method called once each job just before starting event loop ------------
289 {
290  size_t nFED = siStripFedIdMax_-siStripFedIdMin_+1;
291  double xFEDmin = siStripFedIdMin_-0.5;
292  double xFEDmax = siStripFedIdMax_+0.5;
293 
294  //get DQM store
295  ibooker.setCurrentFolder(dirName_);
296  //book histograms
297  if (doPLOTfedsPresent_) {
298  fedsPresent_ = ibooker.book1D("FEDEntries",
299  "Number of times FED buffer is present in data",
300  nFED, xFEDmin, xFEDmax);
301  fedsPresent_->setAxisTitle("FED-ID",1);
302  }
303 
304  if (doPLOTfedFatalErrors_) {
305  fedFatalErrors_ = ibooker.book1D("FEDFatal",
306  "Number of fatal errors in FED buffer",
307  nFED, xFEDmin, xFEDmax);
308  fedFatalErrors_->setAxisTitle("FED-ID",1);
309  }
310 
312  fedNonFatalErrors_ = ibooker.book1D("FEDNonFatal",
313  "Number of non fatal errors in FED buffer",
314  nFED, xFEDmin, xFEDmax);
315  fedNonFatalErrors_->setAxisTitle("FED-ID",1);
316  }
317 
318  int LSBin = conf_.getParameter<int> ("LSBin");
319  double LSMin = conf_.getParameter<double>("LSMin");
320  double LSMax = conf_.getParameter<double>("LSMax");
321 
322  if (doPLOTnFEDinVsLS_) {
323  nFEDinVsLS_ = ibooker.bookProfile("nFEDinVsLS",
324  "number of FED in Vs LS",
325  LSBin, LSMin, LSMax,
326  nFED, xFEDmin, xFEDmax);
327  nFEDinVsLS_->setAxisTitle("LS",1);
328  nFEDinVsLS_->setAxisTitle("FED-ID",2);
329  }
330 
332  nFEDinWdataVsLS_ = ibooker.bookProfile("nFEDinWdataVsLS",
333  "number of FED in (with data) Vs LS",
334  LSBin, LSMin, LSMax,
335  nFED, xFEDmin, xFEDmax);
337  nFEDinWdataVsLS_->setAxisTitle("FED-ID",2);
338  }
339 }
340 
341 // ------------ method called once each run just after ending the event loop ------------
342 void
344 {
346 }
347 
349 {
350  uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
351  if (cablingCacheId_ != currentCacheId) {
352  edm::ESHandle<SiStripFedCabling> cablingHandle;
353  eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
354  cabling_ = cablingHandle.product();
355  cablingCacheId_ = currentCacheId;
356  }
357 }
358 
359 void SiStripFEDCheckPlugin::fillPresent(unsigned int fedId, bool present)
360 {
361  if (present) {
363  else
364  if (doPLOTfedsPresent_) fedsPresent_->Fill(fedId);
365  }
366 }
367 
368 void SiStripFEDCheckPlugin::fillFatalError(unsigned int fedId, bool fatalError)
369 {
370  if (updateFrequency_) {
371  if (fatalError) fedFatalErrorBinContents_[fedId]++;
372  } else {
373  //fedFatalErrors_->Fill( fatalError ? 1 : 0 );
374  if (fatalError)
376  }
377 }
378 
379 void SiStripFEDCheckPlugin::fillNonFatalError(unsigned int fedId, float nonFatalError)
380 {
381  if (updateFrequency_) {
382  if (nonFatalError>0) fedNonFatalErrorBinContents_[fedId]++;//nonFatalError;
383  } else {
384  if (nonFatalError>0)
386  }
387 }
388 
390 {
391  eventCount_++;
394  }
395 }
396 
398 {
399  //if the cache is not being used then do nothing
400  if (!updateFrequency_) return;
401  unsigned int entriesFedsPresent = 0;
402  unsigned int entriesFatalErrors = 0;
403  unsigned int entriesNonFatalErrors = 0;
404  for (unsigned int fedId = siStripFedIdMin_, bin = 1; fedId < siStripFedIdMax_+1; fedId++, bin++) {
405  unsigned int fedsPresentBin = fedsPresentBinContents_[fedId];
406  if (doPLOTfedsPresent_) fedsPresent_->getTH1()->SetBinContent(bin,fedsPresentBin);
407  entriesFedsPresent += fedsPresentBin;
408  unsigned int fedFatalErrorsBin = fedFatalErrorBinContents_[fedId];
409  if (doPLOTfedFatalErrors_) fedFatalErrors_->getTH1()->SetBinContent(bin,fedFatalErrorsBin);
410  entriesFatalErrors += fedFatalErrorsBin;
411  unsigned int fedNonFatalErrorsBin = fedNonFatalErrorBinContents_[fedId];
412  if (doPLOTfedNonFatalErrors_) fedNonFatalErrors_->getTH1()->SetBinContent(bin,fedNonFatalErrorsBin);
413  entriesNonFatalErrors += fedNonFatalErrorsBin;
414  }
415  if (doPLOTfedsPresent_) fedsPresent_->getTH1()->SetEntries(entriesFedsPresent);
416  if (doPLOTfedFatalErrors_) fedFatalErrors_->getTH1()->SetEntries(entriesFatalErrors);
417  if (doPLOTfedNonFatalErrors_) fedNonFatalErrors_->getTH1()->SetEntries(entriesNonFatalErrors);
418 }
419 void
421 
423 
424  // Directory to book histograms in
425  desc.addUntracked<std::string>("DirName","SiStrip/FEDIntegrity/");
426  // Raw data collection
427  desc.add<edm::InputTag>("RawDataTag",edm::InputTag("source"));
428  // Number of events to cache info before updating histograms
429  // (set to zero to disable cache)
430  // HistogramUpdateFrequency = cms.untracked.uint32(0),
431  desc.addUntracked<unsigned int>("HistogramUpdateFrequency",1000);
432  // Print info about errors buffer dumps to LogInfo(SiStripFEDCheck)
433  desc.addUntracked<bool>("PrintDebugMessages",false);
434  desc.add<bool>("doPLOTfedsPresent", true);
435  desc.add<bool>("doPLOTfedFatalErrors", true);
436  desc.add<bool>("doPLOTfedNonFatalErrors",true);
437  desc.add<bool>("doPLOTnFEDinVsLS", false);
438  desc.add<bool>("doPLOTnFEDinWdataVsLS", false);
439  // Write the DQM store to a file (DQMStore.root) at the end of the run
440  desc.addUntracked<bool>("WriteDQMStore",false);
441  // Use to disable all payload (non-fatal) checks
442  desc.addUntracked<bool>("DoPayloadChecks",true);
443  // Use to disable check on channel lengths
444  desc.addUntracked<bool>("CheckChannelLengths",true);
445  // Use to disable check on channel packet codes
446  desc.addUntracked<bool>("CheckChannelPacketCodes",true);
447  // Use to disable check on FE unit lengths in full debug header
448  desc.addUntracked<bool>("CheckFELengths",true);
449  // Use to disable check on channel status bits
450  desc.addUntracked<bool>("CheckChannelStatus",true);
451  desc.add<int> ("LSBin",5000);
452  desc.add<double> ("LSMin", 0.5);
453  desc.add<double> ("LSMax",5000.5);
454 
455  descriptions.addDefault(desc);
456 
457 
458 }
459 
460 
461 //
462 // Define as a plug-in
463 //
464 
T getParameter(std::string const &) const
MonitorElement * nFEDinWdataVsLS_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void fillFatalError(unsigned int fedId, bool fatalError)
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:160
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
const SiStripFedCabling * cabling_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TH1 * getTH1() const
bool hasNonFatalError(const FEDRawData &fedData, unsigned int fedId) const
MonitorElement * fedNonFatalErrors_
#define nullptr
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void endRun(edm::Run const &, edm::EventSetup const &) override
void Fill(long long x)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void addDefault(ParameterSetDescription const &psetDescription)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void analyze(const edm::Event &, const edm::EventSetup &) override
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bin
set the eta bin as selection string.
std::vector< unsigned int > fedFatalErrorBinContents_
std::vector< unsigned int > fedsPresentBinContents_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
Constants and enumerated types for FED/FEC systems.
const T & get() const
Definition: EventSetup.h:59
MonitorElement * nFEDinVsLS_
bool hasFatalError(const FEDRawData &fedData, unsigned int fedId) const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
edm::EventID id() const
Definition: EventBase.h:60
SiStripFEDCheckPlugin(const edm::ParameterSet &)
HLT enums.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void updateCabling(const edm::EventSetup &eventSetup)
MonitorElement * fedFatalErrors_
MonitorElement * fedsPresent_
void fillNonFatalError(unsigned int fedId, float nonFatalError)
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
T const * product() const
Definition: ESHandle.h:86
std::vector< unsigned int > fedNonFatalErrorBinContents_
Definition: Run.h:43
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void fillPresent(unsigned int fedId, bool present)