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.getByToken(rawDataToken_,rawDataCollectionHandle);
160  if (!gotData) {
161  //module is required to silently do nothing when data is not present
162  return;
163  }
164  const FEDRawDataCollection& rawDataCollection = *rawDataCollectionHandle;
165 
166  //get FED IDs
167  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
168  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
169 
170  //FED errors
171  FEDErrors lFedErrors;
172 
173  //loop over siStrip FED IDs
174  for (unsigned int fedId = siStripFedIdMin; fedId <= siStripFedIdMax; fedId++) {
175  const FEDRawData& fedData = rawDataCollection.FEDData(fedId);
176 
177  //create an object to fill all errors
178  //third param to false:save time by not initialising anything not used here
179  lFedErrors.initialiseFED(fedId,cabling_,tTopo,false);
180 
181 
182  //check data exists
183  if (!fedData.size() || !fedData.data()) {
184  fillPresent(fedId,0);
185  continue;
186  }
187  //fill buffer present histogram
188  fillPresent(fedId,1);
189 
190  //check for fatal errors
191  //no need for debug output
192  bool hasFatalErrors = false;
193  float rateNonFatal = 0;
194 
195  std::auto_ptr<const sistrip::FEDBuffer> buffer;
196 
197  if (!lFedErrors.fillFatalFEDErrors(fedData,0)) {
198  hasFatalErrors = true;
199  }
200  else {
201  //need to construct full object to go any further
203 
204  buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
205  if (doPayloadChecks_) {
206 
207  bool channelLengthsOK = checkChannelLengths_ ? buffer->checkChannelLengthsMatchBufferLength() : true;
208  bool channelPacketCodesOK = checkPacketCodes_ ? buffer->checkChannelPacketCodes() : true;
209  bool feLengthsOK = checkFELengths_ ? buffer->checkFEUnitLengths() : true;
210  if ( !channelLengthsOK ||
211  !channelPacketCodesOK ||
212  !feLengthsOK ) {
213  hasFatalErrors = true;
214  }
215  }
216  if (checkChannelStatusBits_) rateNonFatal = lFedErrors.fillNonFatalFEDErrors(buffer.get(),cabling_);
217  }
218  }
219 
220  if (hasFatalErrors) {
221  fillFatalError(fedId,1);
222  if (printDebug_) {
223  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
224  edm::LogInfo("SiStripFEDCheck") << "Fatal error with FED ID " << fedId << ". Check summary: "
225  << std::endl << buffer->checkSummary() << std::endl;
226  std::stringstream ss;
227  buffer->dump(ss);
228  edm::LogInfo("SiStripFEDCheck") << ss.str();
229  }
230  }
231  else {
232  fillFatalError(fedId,0);
233  //fill non-fatal errors histogram if there were no fatal errors
234  fillNonFatalError(fedId,rateNonFatal);
235  if (printDebug_ && rateNonFatal > 0) {
236  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
237  edm::LogInfo("SiStripFEDCheck") << "Non-fatal error with FED ID " << fedId
238  << " for " << rateNonFatal << " of the channels. Check summary: "
239  << std::endl << buffer->checkSummary() << std::endl;
240  std::stringstream ss;
241  buffer->dump(ss);
242  edm::LogInfo("SiStripFEDCheck") << ss.str();
243  }
244 
245  }
246  }//loop over FED IDs
247 
248  //update histograms if needed
250 }
251 
252 // ------------ method called once each job just before starting event loop ------------
253 void
255 {
256  //get FED IDs
257  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
258  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
259  //get DQM store
262  //book histograms
263  fedsPresent_ = dqm_->book1D("FEDEntries",
264  "Number of times FED buffer is present in data",
265  siStripFedIdMax-siStripFedIdMin+1,
266  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
267  fedsPresent_->setAxisTitle("FED-ID",1);
268  fedFatalErrors_ = dqm_->book1D("FEDFatal",
269  "Number of fatal errors in FED buffer",
270  siStripFedIdMax-siStripFedIdMin+1,
271  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
272  fedFatalErrors_->setAxisTitle("FED-ID",1);
273  fedNonFatalErrors_ = dqm_->book1D("FEDNonFatal",
274  "Number of non fatal errors in FED buffer",
275  siStripFedIdMax-siStripFedIdMin+1,
276  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
277  fedNonFatalErrors_->setAxisTitle("FED-ID",1);
278 }
279 
280 // ------------ method called once each run just after ending the event loop ------------
281 void
283 {
285 }
286 
287 // ------------ method called once each job just after ending the event loop ------------
288 void
290 {
291  if (writeDQMStore_) dqm_->save("DQMStore.root");
292 }
293 
294 
296 {
297  uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
298  if (cablingCacheId_ != currentCacheId) {
299  edm::ESHandle<SiStripFedCabling> cablingHandle;
300  eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
301  cabling_ = cablingHandle.product();
302  cablingCacheId_ = currentCacheId;
303  }
304 }
305 
306 void SiStripFEDCheckPlugin::fillPresent(unsigned int fedId, bool present)
307 {
308  if (present) {
310  else fedsPresent_->Fill(fedId);
311  }
312 }
313 
314 void SiStripFEDCheckPlugin::fillFatalError(unsigned int fedId, bool fatalError)
315 {
316  if (updateFrequency_) {
317  if (fatalError) fedFatalErrorBinContents_[fedId]++;
318  } else {
319  //fedFatalErrors_->Fill( fatalError ? 1 : 0 );
320  if (fatalError) fedFatalErrors_->Fill(fedId);
321  }
322 }
323 
324 void SiStripFEDCheckPlugin::fillNonFatalError(unsigned int fedId, float nonFatalError)
325 {
326  if (updateFrequency_) {
327  if (nonFatalError>0) fedNonFatalErrorBinContents_[fedId]++;//nonFatalError;
328  } else {
329  if (nonFatalError>0) fedNonFatalErrors_->Fill(fedId);
330  }
331 }
332 
334 {
335  eventCount_++;
338  }
339 }
340 
342 {
343  //if the cache is not being used then do nothing
344  if (!updateFrequency_) return;
345  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
346  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
347  unsigned int entriesFedsPresent = 0;
348  unsigned int entriesFatalErrors = 0;
349  unsigned int entriesNonFatalErrors = 0;
350  for (unsigned int fedId = siStripFedIdMin, bin = 1; fedId < siStripFedIdMax+1; fedId++, bin++) {
351  unsigned int fedsPresentBin = fedsPresentBinContents_[fedId];
352  fedsPresent_->getTH1()->SetBinContent(bin,fedsPresentBin);
353  entriesFedsPresent += fedsPresentBin;
354  unsigned int fedFatalErrorsBin = fedFatalErrorBinContents_[fedId];
355  fedFatalErrors_->getTH1()->SetBinContent(bin,fedFatalErrorsBin);
356  entriesFatalErrors += fedFatalErrorsBin;
357  unsigned int fedNonFatalErrorsBin = fedNonFatalErrorBinContents_[fedId];
358  fedNonFatalErrors_->getTH1()->SetBinContent(bin,fedNonFatalErrorsBin);
359  entriesNonFatalErrors += fedNonFatalErrorsBin;
360  }
361  fedsPresent_->getTH1()->SetEntries(entriesFedsPresent);
362  fedFatalErrors_->getTH1()->SetEntries(entriesFatalErrors);
363  fedNonFatalErrors_->getTH1()->SetEntries(entriesNonFatalErrors);
364 }
365 
366 //
367 // Define as a plug-in
368 //
369 
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:928
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:230
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:2424
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:639
void fillPresent(unsigned int fedId, bool present)