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.18 2010/09/30 15:37:19 amagnan Exp $
14 //
15 //
16 #include <memory>
17 
28 
33 
36 
39 
41 
42 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh"
43 
44 //
45 // Class declaration
46 //
47 
49 {
50  public:
53  private:
54  virtual void beginJob();
55  virtual void analyze(const edm::Event&, const edm::EventSetup&);
56  virtual void endJob();
57  virtual void endRun();
58 
59  bool hasFatalError(const FEDRawData& fedData, unsigned int fedId) const;
60  bool hasNonFatalError(const FEDRawData& fedData, unsigned int fedId) const;
61  void updateCabling(const edm::EventSetup& eventSetup);
62 
63  inline void fillPresent(unsigned int fedId, bool present);
64  inline void fillFatalError(unsigned int fedId, bool fatalError);
65  inline void fillNonFatalError(unsigned int fedId, float nonFatalError);
66 
67  void doUpdateIfNeeded();
68  void updateHistograms();
69 
70 
72  std::string dirName_;
75 
76  //Histograms
81 
82  //For histogram cache
83  unsigned int updateFrequency_;//Update histograms with cached values every n events. If zero then fill normally every event
84  //cache values
85  std::vector<unsigned int> fedsPresentBinContents_;
86  std::vector<unsigned int> fedFatalErrorBinContents_;
87  std::vector<unsigned int> fedNonFatalErrorBinContents_;
88  unsigned int eventCount_;//incremented by doUpdateIfNeeded()
89 
90  //Fine grained control of tests
92 
93  //Cabling
94  uint32_t cablingCacheId_;
96 };
97 
98 
99 //
100 // Constructors and destructor
101 //
102 
104  : rawDataTag_(iConfig.getParameter<edm::InputTag>("RawDataTag")),
105  dirName_(iConfig.getUntrackedParameter<std::string>("DirName","SiStrip/FEDIntegrity/")),
106  printDebug_(iConfig.getUntrackedParameter<bool>("PrintDebugMessages",false)),
107  writeDQMStore_(iConfig.getUntrackedParameter<bool>("WriteDQMStore",false)),
108  updateFrequency_(iConfig.getUntrackedParameter<unsigned int>("HistogramUpdateFrequency",0)),
109  fedsPresentBinContents_(FEDNumbering::MAXSiStripFEDID+1,0),
110  fedFatalErrorBinContents_(FEDNumbering::MAXSiStripFEDID+1,0),
111  fedNonFatalErrorBinContents_(FEDNumbering::MAXSiStripFEDID+1,0),
112  eventCount_(0),
113  doPayloadChecks_(iConfig.getUntrackedParameter<bool>("DoPayloadChecks",true)),
114  checkChannelLengths_(iConfig.getUntrackedParameter<bool>("CheckChannelLengths",true)),
115  checkPacketCodes_(iConfig.getUntrackedParameter<bool>("CheckChannelPacketCodes",true)),
116  checkFELengths_(iConfig.getUntrackedParameter<bool>("CheckFELengths",true)),
117  checkChannelStatusBits_(iConfig.getUntrackedParameter<bool>("CheckChannelStatus",true)),
118  cablingCacheId_(0)
119 {
121  std::stringstream ss;
122  ss << "Payload checks are disabled but individual payload checks have been enabled. The following payload checks will be skipped: ";
123  if (checkChannelLengths_) ss << "Channel length check, ";
124  if (checkPacketCodes_) ss << "Channel packet code check, ";
125  if (checkChannelStatusBits_) ss << "Cabled channel status bits checks, ";
126  if (checkFELengths_) ss << "FE Unit legnth check";
127  edm::LogWarning("SiStripFEDCheck") << ss.str();
128  }
129 }
130 
132 {
133 }
134 
135 
136 //
137 // Member functions
138 //
139 
140 // ------------ method called to for each event ------------
141 void
143 {
144  //update cabling
145  updateCabling(iSetup);
146 
147  //get raw data
148  edm::Handle<FEDRawDataCollection> rawDataCollectionHandle;
149  const bool gotData = iEvent.getByLabel(rawDataTag_,rawDataCollectionHandle);
150  if (!gotData) {
151  //module is required to silently do nothing when data is not present
152  return;
153  }
154  const FEDRawDataCollection& rawDataCollection = *rawDataCollectionHandle;
155 
156  //get FED IDs
157  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
158  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
159 
160  //FED errors
161  FEDErrors lFedErrors;
162 
163  //loop over siStrip FED IDs
164  for (unsigned int fedId = siStripFedIdMin; fedId <= siStripFedIdMax; fedId++) {
165  const FEDRawData& fedData = rawDataCollection.FEDData(fedId);
166 
167  //create an object to fill all errors
168  //third param to false:save time by not initialising anything not used here
169  lFedErrors.initialiseFED(fedId,cabling_,false);
170 
171 
172  //check data exists
173  if (!fedData.size() || !fedData.data()) {
174  fillPresent(fedId,0);
175  continue;
176  }
177  //fill buffer present histogram
178  fillPresent(fedId,1);
179 
180  //check for fatal errors
181  //no need for debug output
182  bool hasFatalErrors = false;
183  float rateNonFatal = 0;
184 
185  std::auto_ptr<const sistrip::FEDBuffer> buffer;
186 
187  if (!lFedErrors.fillFatalFEDErrors(fedData,0)) {
188  hasFatalErrors = true;
189  }
190  else {
191  //need to construct full object to go any further
193 
194  buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
195  if (doPayloadChecks_) {
196 
197  bool channelLengthsOK = checkChannelLengths_ ? buffer->checkChannelLengthsMatchBufferLength() : true;
198  bool channelPacketCodesOK = checkPacketCodes_ ? buffer->checkChannelPacketCodes() : true;
199  bool feLengthsOK = checkFELengths_ ? buffer->checkFEUnitLengths() : true;
200  if ( !channelLengthsOK ||
201  !channelPacketCodesOK ||
202  !feLengthsOK ) {
203  hasFatalErrors = true;
204  }
205  }
206  if (checkChannelStatusBits_) rateNonFatal = lFedErrors.fillNonFatalFEDErrors(buffer.get(),cabling_);
207  }
208  }
209 
210  if (hasFatalErrors) {
211  fillFatalError(fedId,1);
212  if (printDebug_) {
213  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
214  edm::LogInfo("SiStripFEDCheck") << "Fatal error with FED ID " << fedId << ". Check summary: "
215  << std::endl << buffer->checkSummary() << std::endl;
216  std::stringstream ss;
217  buffer->dump(ss);
218  edm::LogInfo("SiStripFEDCheck") << ss.str();
219  }
220  }
221  else {
222  fillFatalError(fedId,0);
223  //fill non-fatal errors histogram if there were no fatal errors
224  fillNonFatalError(fedId,rateNonFatal);
225  if (printDebug_ && rateNonFatal > 0) {
226  if (!buffer.get()) buffer.reset(new sistrip::FEDBuffer(fedData.data(),fedData.size(),true));
227  edm::LogInfo("SiStripFEDCheck") << "Non-fatal error with FED ID " << fedId
228  << " for " << rateNonFatal << " of the channels. Check summary: "
229  << std::endl << buffer->checkSummary() << std::endl;
230  std::stringstream ss;
231  buffer->dump(ss);
232  edm::LogInfo("SiStripFEDCheck") << ss.str();
233  }
234 
235  }
236  }//loop over FED IDs
237 
238  //update histograms if needed
240 }
241 
242 // ------------ method called once each job just before starting event loop ------------
243 void
245 {
246  //get FED IDs
247  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
248  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
249  //get DQM store
252  //book histograms
253  fedsPresent_ = dqm_->book1D("FEDEntries",
254  "Number of times FED buffer is present in data",
255  siStripFedIdMax-siStripFedIdMin+1,
256  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
257  fedsPresent_->setAxisTitle("FED-ID",1);
258  fedFatalErrors_ = dqm_->book1D("FEDFatal",
259  "Number of fatal errors in FED buffer",
260  siStripFedIdMax-siStripFedIdMin+1,
261  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
262  fedFatalErrors_->setAxisTitle("FED-ID",1);
263  fedNonFatalErrors_ = dqm_->book1D("FEDNonFatal",
264  "Number of non fatal errors in FED buffer",
265  siStripFedIdMax-siStripFedIdMin+1,
266  siStripFedIdMin-0.5,siStripFedIdMax+0.5);
267  fedNonFatalErrors_->setAxisTitle("FED-ID",1);
268 }
269 
270 // ------------ method called once each run just after ending the event loop ------------
271 void
273 {
275 }
276 
277 // ------------ method called once each job just after ending the event loop ------------
278 void
280 {
281  if (writeDQMStore_) dqm_->save("DQMStore.root");
282 }
283 
284 
286 {
287  uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
288  if (cablingCacheId_ != currentCacheId) {
289  edm::ESHandle<SiStripFedCabling> cablingHandle;
290  eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
291  cabling_ = cablingHandle.product();
292  cablingCacheId_ = currentCacheId;
293  }
294 }
295 
296 void SiStripFEDCheckPlugin::fillPresent(unsigned int fedId, bool present)
297 {
298  if (present) {
300  else fedsPresent_->Fill(fedId);
301  }
302 }
303 
304 void SiStripFEDCheckPlugin::fillFatalError(unsigned int fedId, bool fatalError)
305 {
306  if (updateFrequency_) {
307  if (fatalError) fedFatalErrorBinContents_[fedId]++;
308  } else {
309  //fedFatalErrors_->Fill( fatalError ? 1 : 0 );
310  if (fatalError) fedFatalErrors_->Fill(fedId);
311  }
312 }
313 
314 void SiStripFEDCheckPlugin::fillNonFatalError(unsigned int fedId, float nonFatalError)
315 {
316  if (updateFrequency_) {
317  if (nonFatalError>0) fedNonFatalErrorBinContents_[fedId]++;//nonFatalError;
318  } else {
319  if (nonFatalError>0) fedNonFatalErrors_->Fill(fedId);
320  }
321 }
322 
324 {
325  eventCount_++;
328  }
329 }
330 
332 {
333  //if the cache is not being used then do nothing
334  if (!updateFrequency_) return;
335  const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
336  const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
337  unsigned int entriesFedsPresent = 0;
338  unsigned int entriesFatalErrors = 0;
339  unsigned int entriesNonFatalErrors = 0;
340  for (unsigned int fedId = siStripFedIdMin, bin = 1; fedId < siStripFedIdMax+1; fedId++, bin++) {
341  unsigned int fedsPresentBin = fedsPresentBinContents_[fedId];
342  fedsPresent_->getTH1()->SetBinContent(bin,fedsPresentBin);
343  entriesFedsPresent += fedsPresentBin;
344  unsigned int fedFatalErrorsBin = fedFatalErrorBinContents_[fedId];
345  fedFatalErrors_->getTH1()->SetBinContent(bin,fedFatalErrorsBin);
346  entriesFatalErrors += fedFatalErrorsBin;
347  unsigned int fedNonFatalErrorsBin = fedNonFatalErrorBinContents_[fedId];
348  fedNonFatalErrors_->getTH1()->SetBinContent(bin,fedNonFatalErrorsBin);
349  entriesNonFatalErrors += fedNonFatalErrorsBin;
350  }
351  fedsPresent_->getTH1()->SetEntries(entriesFedsPresent);
352  fedFatalErrors_->getTH1()->SetEntries(entriesFatalErrors);
353  fedNonFatalErrors_->getTH1()->SetEntries(entriesNonFatalErrors);
354 }
355 
356 //
357 // Define as a plug-in
358 //
359 
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:717
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:2113
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:356
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:429
void fillPresent(unsigned int fedId, bool present)