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