CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
28 
35 
38 
41 
43 
44 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh"
45 
46 
47 //
48 // Class declaration
49 //
50 
52 {
53  public:
56  private:
57  virtual void beginJob() override;
58  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
59  virtual void endJob() override;
60  virtual void endRun();
61 
62  bool hasFatalError(const FEDRawData& fedData, unsigned int fedId) const;
63  bool hasNonFatalError(const FEDRawData& fedData, unsigned int fedId) const;
64  void updateCabling(const edm::EventSetup& eventSetup);
65 
66  inline void fillPresent(unsigned int fedId, bool present);
67  inline void fillFatalError(unsigned int fedId, bool fatalError);
68  inline void fillNonFatalError(unsigned int fedId, float nonFatalError);
69 
70  void doUpdateIfNeeded();
71  void updateHistograms();
72 
73 
79 
80  //Histograms
85 
86  //For histogram cache
87  unsigned int updateFrequency_;//Update histograms with cached values every n events. If zero then fill normally every event
88  //cache values
89  std::vector<unsigned int> fedsPresentBinContents_;
90  std::vector<unsigned int> fedFatalErrorBinContents_;
91  std::vector<unsigned int> fedNonFatalErrorBinContents_;
92  unsigned int eventCount_;//incremented by doUpdateIfNeeded()
93 
94  //Fine grained control of tests
96 
97  //Cabling
98  uint32_t cablingCacheId_;
100 };
101 
102 
103 //
104 // Constructors and destructor
105 //
106 
108  : rawDataTag_(iConfig.getParameter<edm::InputTag>("RawDataTag")),
109  dirName_(iConfig.getUntrackedParameter<std::string>("DirName","SiStrip/FEDIntegrity/")),
110  printDebug_(iConfig.getUntrackedParameter<bool>("PrintDebugMessages",false)),
111  writeDQMStore_(iConfig.getUntrackedParameter<bool>("WriteDQMStore",false)),
112  updateFrequency_(iConfig.getUntrackedParameter<unsigned int>("HistogramUpdateFrequency",0)),
113  fedsPresentBinContents_(FEDNumbering::MAXSiStripFEDID+1,0),
114  fedFatalErrorBinContents_(FEDNumbering::MAXSiStripFEDID+1,0),
115  fedNonFatalErrorBinContents_(FEDNumbering::MAXSiStripFEDID+1,0),
116  eventCount_(0),
117  doPayloadChecks_(iConfig.getUntrackedParameter<bool>("DoPayloadChecks",true)),
118  checkChannelLengths_(iConfig.getUntrackedParameter<bool>("CheckChannelLengths",true)),
119  checkPacketCodes_(iConfig.getUntrackedParameter<bool>("CheckChannelPacketCodes",true)),
120  checkFELengths_(iConfig.getUntrackedParameter<bool>("CheckFELengths",true)),
121  checkChannelStatusBits_(iConfig.getUntrackedParameter<bool>("CheckChannelStatus",true)),
122  cablingCacheId_(0)
123 {
124  rawDataToken_ = consumes<FEDRawDataCollection>(rawDataTag_);
126  std::stringstream ss;
127  ss << "Payload checks are disabled but individual payload checks have been enabled. The following payload checks will be skipped: ";
128  if (checkChannelLengths_) ss << "Channel length check, ";
129  if (checkPacketCodes_) ss << "Channel packet code check, ";
130  if (checkChannelStatusBits_) ss << "Cabled channel status bits checks, ";
131  if (checkFELengths_) ss << "FE Unit legnth check";
132  edm::LogWarning("SiStripFEDCheck") << ss.str();
133  }
134 }
135 
137 {
138 }
139 
140 
141 //
142 // Member functions
143 //
144 
145 // ------------ method called to for each event ------------
146 void
148 {
149  //Retrieve tracker topology from geometry
150  edm::ESHandle<TrackerTopology> tTopoHandle;
151  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
152  const TrackerTopology* const tTopo = tTopoHandle.product();
153 
154  //update cabling
155  updateCabling(iSetup);
156 
157  //get raw data
158  edm::Handle<FEDRawDataCollection> rawDataCollectionHandle;
159  // const bool gotData = iEvent.getByLabel(rawDataTag_,rawDataCollectionHandle);
160  const bool gotData = iEvent.getByToken(rawDataToken_,rawDataCollectionHandle);
161  if (!gotData) {
162  //module is required to silently do nothing when data is not present
163  return;
164  }
165  const FEDRawDataCollection& rawDataCollection = *rawDataCollectionHandle;
166 
167  //get FED IDs
168  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
169  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
170 
171  //FED errors
172  FEDErrors lFedErrors;
173 
174  //loop over siStrip FED IDs
175  for (unsigned int fedId = siStripFedIdMin; fedId <= siStripFedIdMax; fedId++) {
176  const FEDRawData& fedData = rawDataCollection.FEDData(fedId);
177 
178  //create an object to fill all errors
179  //third param to false:save time by not initialising anything not used here
180  lFedErrors.initialiseFED(fedId,cabling_,tTopo,false);
181 
182 
183  //check data exists
184  if (!fedData.size() || !fedData.data()) {
185  fillPresent(fedId,0);
186  continue;
187  }
188  //fill buffer present histogram
189  fillPresent(fedId,1);
190 
191  //check for fatal errors
192  //no need for debug output
193  bool hasFatalErrors = false;
194  float rateNonFatal = 0;
195 
196  std::auto_ptr<const sistrip::FEDBuffer> buffer;
197 
198  if (!lFedErrors.fillFatalFEDErrors(fedData,0)) {
199  hasFatalErrors = true;
200  }
201  else {
202  //need to construct full object to go any further
204 
205  buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
206  if (doPayloadChecks_) {
207 
208  bool channelLengthsOK = checkChannelLengths_ ? buffer->checkChannelLengthsMatchBufferLength() : true;
209  bool channelPacketCodesOK = checkPacketCodes_ ? buffer->checkChannelPacketCodes() : true;
210  bool feLengthsOK = checkFELengths_ ? buffer->checkFEUnitLengths() : true;
211  if ( !channelLengthsOK ||
212  !channelPacketCodesOK ||
213  !feLengthsOK ) {
214  hasFatalErrors = true;
215  }
216  }
217  if (checkChannelStatusBits_) rateNonFatal = lFedErrors.fillNonFatalFEDErrors(buffer.get(),cabling_);
218  }
219  }
220 
221  if (hasFatalErrors) {
222  fillFatalError(fedId,1);
223  if (printDebug_) {
224  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
225  edm::LogInfo("SiStripFEDCheck") << "Fatal error with FED ID " << fedId << ". Check summary: "
226  << std::endl << buffer->checkSummary() << std::endl;
227  std::stringstream ss;
228  buffer->dump(ss);
229  edm::LogInfo("SiStripFEDCheck") << ss.str();
230  }
231  }
232  else {
233  fillFatalError(fedId,0);
234  //fill non-fatal errors histogram if there were no fatal errors
235  fillNonFatalError(fedId,rateNonFatal);
236  if (printDebug_ && rateNonFatal > 0) {
237  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
238  edm::LogInfo("SiStripFEDCheck") << "Non-fatal error with FED ID " << fedId
239  << " for " << rateNonFatal << " of the channels. Check summary: "
240  << std::endl << buffer->checkSummary() << std::endl;
241  std::stringstream ss;
242  buffer->dump(ss);
243  edm::LogInfo("SiStripFEDCheck") << ss.str();
244  }
245 
246  }
247  }//loop over FED IDs
248 
249  //update histograms if needed
251 }
252 
253 // ------------ method called once each job just before starting event loop ------------
254 void
256 {
257  //get FED IDs
258  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
259  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
260  //get DQM store
263  //book histograms
264  fedsPresent_ = dqm_->book1D("FEDEntries",
265  "Number of times FED buffer is present in data",
266  siStripFedIdMax-siStripFedIdMin+1,
267  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
268  fedsPresent_->setAxisTitle("FED-ID",1);
269  fedFatalErrors_ = dqm_->book1D("FEDFatal",
270  "Number of fatal errors in FED buffer",
271  siStripFedIdMax-siStripFedIdMin+1,
272  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
273  fedFatalErrors_->setAxisTitle("FED-ID",1);
274  fedNonFatalErrors_ = dqm_->book1D("FEDNonFatal",
275  "Number of non fatal errors in FED buffer",
276  siStripFedIdMax-siStripFedIdMin+1,
277  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
278  fedNonFatalErrors_->setAxisTitle("FED-ID",1);
279 }
280 
281 // ------------ method called once each run just after ending the event loop ------------
282 void
284 {
286 }
287 
288 // ------------ method called once each job just after ending the event loop ------------
289 void
291 {
292  if (writeDQMStore_) dqm_->save("DQMStore.root");
293 }
294 
295 
297 {
298  uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
299  if (cablingCacheId_ != currentCacheId) {
300  edm::ESHandle<SiStripFedCabling> cablingHandle;
301  eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
302  cabling_ = cablingHandle.product();
303  cablingCacheId_ = currentCacheId;
304  }
305 }
306 
307 void SiStripFEDCheckPlugin::fillPresent(unsigned int fedId, bool present)
308 {
309  if (present) {
311  else fedsPresent_->Fill(fedId);
312  }
313 }
314 
315 void SiStripFEDCheckPlugin::fillFatalError(unsigned int fedId, bool fatalError)
316 {
317  if (updateFrequency_) {
318  if (fatalError) fedFatalErrorBinContents_[fedId]++;
319  } else {
320  //fedFatalErrors_->Fill( fatalError ? 1 : 0 );
321  if (fatalError) fedFatalErrors_->Fill(fedId);
322  }
323 }
324 
325 void SiStripFEDCheckPlugin::fillNonFatalError(unsigned int fedId, float nonFatalError)
326 {
327  if (updateFrequency_) {
328  if (nonFatalError>0) fedNonFatalErrorBinContents_[fedId]++;//nonFatalError;
329  } else {
330  if (nonFatalError>0) fedNonFatalErrors_->Fill(fedId);
331  }
332 }
333 
335 {
336  eventCount_++;
339  }
340 }
341 
343 {
344  //if the cache is not being used then do nothing
345  if (!updateFrequency_) return;
346  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
347  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
348  unsigned int entriesFedsPresent = 0;
349  unsigned int entriesFatalErrors = 0;
350  unsigned int entriesNonFatalErrors = 0;
351  for (unsigned int fedId = siStripFedIdMin, bin = 1; fedId < siStripFedIdMax+1; fedId++, bin++) {
352  unsigned int fedsPresentBin = fedsPresentBinContents_[fedId];
353  fedsPresent_->getTH1()->SetBinContent(bin,fedsPresentBin);
354  entriesFedsPresent += fedsPresentBin;
355  unsigned int fedFatalErrorsBin = fedFatalErrorBinContents_[fedId];
356  fedFatalErrors_->getTH1()->SetBinContent(bin,fedFatalErrorsBin);
357  entriesFatalErrors += fedFatalErrorsBin;
358  unsigned int fedNonFatalErrorsBin = fedNonFatalErrorBinContents_[fedId];
359  fedNonFatalErrors_->getTH1()->SetBinContent(bin,fedNonFatalErrorsBin);
360  entriesNonFatalErrors += fedNonFatalErrorsBin;
361  }
362  fedsPresent_->getTH1()->SetEntries(entriesFedsPresent);
363  fedFatalErrors_->getTH1()->SetEntries(entriesFatalErrors);
364  fedNonFatalErrors_->getTH1()->SetEntries(entriesNonFatalErrors);
365 }
366 
367 //
368 // Define as a plug-in
369 //
370 
void fillFatalError(unsigned int fedId, bool fatalError)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
const SiStripFedCabling * cabling_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool hasNonFatalError(const FEDRawData &fedData, unsigned int fedId) const
MonitorElement * fedNonFatalErrors_
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
virtual void beginJob() override
virtual void endJob() override
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:243
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
TH1 * getTH1(void) const
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2296
std::vector< unsigned int > fedFatalErrorBinContents_
std::vector< unsigned int > fedsPresentBinContents_
Constants and enumerated types for FED/FEC systems.
const T & get() const
Definition: EventSetup.h:55
bool hasFatalError(const FEDRawData &fedData, unsigned int fedId) const
T const * product() const
Definition: ESHandle.h:62
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
SiStripFEDCheckPlugin(const edm::ParameterSet &)
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_
volatile std::atomic< bool > shutdown_flag false
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)
std::vector< unsigned int > fedNonFatalErrorBinContents_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
void fillPresent(unsigned int fedId, bool present)