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 // $Id: SiStripFEDDataCheck.cc,v 1.3 2013/01/03 18:59:36 wmtan Exp $
14 //
15 //
16 #include <memory>
17 
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();
58  virtual void analyze(const edm::Event&, const edm::EventSetup&);
59  virtual void endJob();
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 
78 
79  //Histograms
84 
85  //For histogram cache
86  unsigned int updateFrequency_;//Update histograms with cached values every n events. If zero then fill normally every event
87  //cache values
88  std::vector<unsigned int> fedsPresentBinContents_;
89  std::vector<unsigned int> fedFatalErrorBinContents_;
90  std::vector<unsigned int> fedNonFatalErrorBinContents_;
91  unsigned int eventCount_;//incremented by doUpdateIfNeeded()
92 
93  //Fine grained control of tests
95 
96  //Cabling
97  uint32_t cablingCacheId_;
99 };
100 
101 
102 //
103 // Constructors and destructor
104 //
105 
107  : rawDataTag_(iConfig.getParameter<edm::InputTag>("RawDataTag")),
108  dirName_(iConfig.getUntrackedParameter<std::string>("DirName","SiStrip/FEDIntegrity/")),
109  printDebug_(iConfig.getUntrackedParameter<bool>("PrintDebugMessages",false)),
110  writeDQMStore_(iConfig.getUntrackedParameter<bool>("WriteDQMStore",false)),
111  updateFrequency_(iConfig.getUntrackedParameter<unsigned int>("HistogramUpdateFrequency",0)),
112  fedsPresentBinContents_(FEDNumbering::MAXSiStripFEDID+1,0),
113  fedFatalErrorBinContents_(FEDNumbering::MAXSiStripFEDID+1,0),
114  fedNonFatalErrorBinContents_(FEDNumbering::MAXSiStripFEDID+1,0),
115  eventCount_(0),
116  doPayloadChecks_(iConfig.getUntrackedParameter<bool>("DoPayloadChecks",true)),
117  checkChannelLengths_(iConfig.getUntrackedParameter<bool>("CheckChannelLengths",true)),
118  checkPacketCodes_(iConfig.getUntrackedParameter<bool>("CheckChannelPacketCodes",true)),
119  checkFELengths_(iConfig.getUntrackedParameter<bool>("CheckFELengths",true)),
120  checkChannelStatusBits_(iConfig.getUntrackedParameter<bool>("CheckChannelStatus",true)),
121  cablingCacheId_(0)
122 {
124  std::stringstream ss;
125  ss << "Payload checks are disabled but individual payload checks have been enabled. The following payload checks will be skipped: ";
126  if (checkChannelLengths_) ss << "Channel length check, ";
127  if (checkPacketCodes_) ss << "Channel packet code check, ";
128  if (checkChannelStatusBits_) ss << "Cabled channel status bits checks, ";
129  if (checkFELengths_) ss << "FE Unit legnth check";
130  edm::LogWarning("SiStripFEDCheck") << ss.str();
131  }
132 }
133 
135 {
136 }
137 
138 
139 //
140 // Member functions
141 //
142 
143 // ------------ method called to for each event ------------
144 void
146 {
147  //Retrieve tracker topology from geometry
148  edm::ESHandle<TrackerTopology> tTopoHandle;
149  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
150  const TrackerTopology* const tTopo = tTopoHandle.product();
151 
152  //update cabling
153  updateCabling(iSetup);
154 
155  //get raw data
156  edm::Handle<FEDRawDataCollection> rawDataCollectionHandle;
157  const bool gotData = iEvent.getByLabel(rawDataTag_,rawDataCollectionHandle);
158  if (!gotData) {
159  //module is required to silently do nothing when data is not present
160  return;
161  }
162  const FEDRawDataCollection& rawDataCollection = *rawDataCollectionHandle;
163 
164  //get FED IDs
165  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
166  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
167 
168  //FED errors
169  FEDErrors lFedErrors;
170 
171  //loop over siStrip FED IDs
172  for (unsigned int fedId = siStripFedIdMin; fedId <= siStripFedIdMax; fedId++) {
173  const FEDRawData& fedData = rawDataCollection.FEDData(fedId);
174 
175  //create an object to fill all errors
176  //third param to false:save time by not initialising anything not used here
177  lFedErrors.initialiseFED(fedId,cabling_,tTopo,false);
178 
179 
180  //check data exists
181  if (!fedData.size() || !fedData.data()) {
182  fillPresent(fedId,0);
183  continue;
184  }
185  //fill buffer present histogram
186  fillPresent(fedId,1);
187 
188  //check for fatal errors
189  //no need for debug output
190  bool hasFatalErrors = false;
191  float rateNonFatal = 0;
192 
193  std::auto_ptr<const sistrip::FEDBuffer> buffer;
194 
195  if (!lFedErrors.fillFatalFEDErrors(fedData,0)) {
196  hasFatalErrors = true;
197  }
198  else {
199  //need to construct full object to go any further
201 
202  buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
203  if (doPayloadChecks_) {
204 
205  bool channelLengthsOK = checkChannelLengths_ ? buffer->checkChannelLengthsMatchBufferLength() : true;
206  bool channelPacketCodesOK = checkPacketCodes_ ? buffer->checkChannelPacketCodes() : true;
207  bool feLengthsOK = checkFELengths_ ? buffer->checkFEUnitLengths() : true;
208  if ( !channelLengthsOK ||
209  !channelPacketCodesOK ||
210  !feLengthsOK ) {
211  hasFatalErrors = true;
212  }
213  }
214  if (checkChannelStatusBits_) rateNonFatal = lFedErrors.fillNonFatalFEDErrors(buffer.get(),cabling_);
215  }
216  }
217 
218  if (hasFatalErrors) {
219  fillFatalError(fedId,1);
220  if (printDebug_) {
221  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
222  edm::LogInfo("SiStripFEDCheck") << "Fatal error with FED ID " << fedId << ". Check summary: "
223  << std::endl << buffer->checkSummary() << std::endl;
224  std::stringstream ss;
225  buffer->dump(ss);
226  edm::LogInfo("SiStripFEDCheck") << ss.str();
227  }
228  }
229  else {
230  fillFatalError(fedId,0);
231  //fill non-fatal errors histogram if there were no fatal errors
232  fillNonFatalError(fedId,rateNonFatal);
233  if (printDebug_ && rateNonFatal > 0) {
234  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
235  edm::LogInfo("SiStripFEDCheck") << "Non-fatal error with FED ID " << fedId
236  << " for " << rateNonFatal << " of the channels. Check summary: "
237  << std::endl << buffer->checkSummary() << std::endl;
238  std::stringstream ss;
239  buffer->dump(ss);
240  edm::LogInfo("SiStripFEDCheck") << ss.str();
241  }
242 
243  }
244  }//loop over FED IDs
245 
246  //update histograms if needed
248 }
249 
250 // ------------ method called once each job just before starting event loop ------------
251 void
253 {
254  //get FED IDs
255  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
256  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
257  //get DQM store
260  //book histograms
261  fedsPresent_ = dqm_->book1D("FEDEntries",
262  "Number of times FED buffer is present in data",
263  siStripFedIdMax-siStripFedIdMin+1,
264  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
265  fedsPresent_->setAxisTitle("FED-ID",1);
266  fedFatalErrors_ = dqm_->book1D("FEDFatal",
267  "Number of fatal errors in FED buffer",
268  siStripFedIdMax-siStripFedIdMin+1,
269  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
270  fedFatalErrors_->setAxisTitle("FED-ID",1);
271  fedNonFatalErrors_ = dqm_->book1D("FEDNonFatal",
272  "Number of non fatal errors in FED buffer",
273  siStripFedIdMax-siStripFedIdMin+1,
274  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
275  fedNonFatalErrors_->setAxisTitle("FED-ID",1);
276 }
277 
278 // ------------ method called once each run just after ending the event loop ------------
279 void
281 {
283 }
284 
285 // ------------ method called once each job just after ending the event loop ------------
286 void
288 {
289  if (writeDQMStore_) dqm_->save("DQMStore.root");
290 }
291 
292 
294 {
295  uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
296  if (cablingCacheId_ != currentCacheId) {
297  edm::ESHandle<SiStripFedCabling> cablingHandle;
298  eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
299  cabling_ = cablingHandle.product();
300  cablingCacheId_ = currentCacheId;
301  }
302 }
303 
304 void SiStripFEDCheckPlugin::fillPresent(unsigned int fedId, bool present)
305 {
306  if (present) {
308  else fedsPresent_->Fill(fedId);
309  }
310 }
311 
312 void SiStripFEDCheckPlugin::fillFatalError(unsigned int fedId, bool fatalError)
313 {
314  if (updateFrequency_) {
315  if (fatalError) fedFatalErrorBinContents_[fedId]++;
316  } else {
317  //fedFatalErrors_->Fill( fatalError ? 1 : 0 );
318  if (fatalError) fedFatalErrors_->Fill(fedId);
319  }
320 }
321 
322 void SiStripFEDCheckPlugin::fillNonFatalError(unsigned int fedId, float nonFatalError)
323 {
324  if (updateFrequency_) {
325  if (nonFatalError>0) fedNonFatalErrorBinContents_[fedId]++;//nonFatalError;
326  } else {
327  if (nonFatalError>0) fedNonFatalErrors_->Fill(fedId);
328  }
329 }
330 
332 {
333  eventCount_++;
336  }
337 }
338 
340 {
341  //if the cache is not being used then do nothing
342  if (!updateFrequency_) return;
343  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
344  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
345  unsigned int entriesFedsPresent = 0;
346  unsigned int entriesFatalErrors = 0;
347  unsigned int entriesNonFatalErrors = 0;
348  for (unsigned int fedId = siStripFedIdMin, bin = 1; fedId < siStripFedIdMax+1; fedId++, bin++) {
349  unsigned int fedsPresentBin = fedsPresentBinContents_[fedId];
350  fedsPresent_->getTH1()->SetBinContent(bin,fedsPresentBin);
351  entriesFedsPresent += fedsPresentBin;
352  unsigned int fedFatalErrorsBin = fedFatalErrorBinContents_[fedId];
353  fedFatalErrors_->getTH1()->SetBinContent(bin,fedFatalErrorsBin);
354  entriesFatalErrors += fedFatalErrorsBin;
355  unsigned int fedNonFatalErrorsBin = fedNonFatalErrorBinContents_[fedId];
356  fedNonFatalErrors_->getTH1()->SetBinContent(bin,fedNonFatalErrorsBin);
357  entriesNonFatalErrors += fedNonFatalErrorsBin;
358  }
359  fedsPresent_->getTH1()->SetEntries(entriesFedsPresent);
360  fedFatalErrors_->getTH1()->SetEntries(entriesFatalErrors);
361  fedNonFatalErrors_->getTH1()->SetEntries(entriesNonFatalErrors);
362 }
363 
364 //
365 // Define as a plug-in
366 //
367 
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:722
const SiStripFedCabling * cabling_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2118
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:49
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:243
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
TH1 * getTH1(void) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
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...
virtual void analyze(const edm::Event &, const edm::EventSetup &)
SiStripFEDCheckPlugin(const edm::ParameterSet &)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
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)
std::vector< unsigned int > fedNonFatalErrorBinContents_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
void fillPresent(unsigned int fedId, bool present)