CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripFEDMonitor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DQM/SiStripMonitorHardware
4 // Class: SiStripFEDMonitorPlugin
5 //
10 //
11 // Original Author: Nicholas Cripps
12 // Created: 2008/09/16
13 // $Id: SiStripFEDMonitor.cc,v 1.37 2010/04/02 15:41:32 amagnan Exp $
14 //
15 //Modified : Anne-Marie Magnan
16 // ---- 2009/04/21 : histogram management put in separate class
17 // struct helper to simplify arguments of functions
18 // ---- 2009/04/22 : add TkHistoMap with % of bad channels per module
19 // ---- 2009/04/27 : create FEDErrors class
20 
21 #include <sstream>
22 #include <memory>
23 #include <list>
24 #include <algorithm>
25 #include <cassert>
26 
38 
43 
46 
48 
49 #include "DQM/SiStripMonitorHardware/interface/FEDHistograms.hh"
50 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh"
51 
52 
53 //
54 // Class declaration
55 //
56 
58 {
59  public:
62  private:
63  virtual void beginJob();
64  virtual void analyze(const edm::Event&, const edm::EventSetup&);
65  virtual void endJob();
66  virtual void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
67  const edm::EventSetup& context);
68  virtual void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
69  const edm::EventSetup& context);
70 
71  //update the cabling if necessary
72  void updateCabling(const edm::EventSetup& eventSetup);
73 
74 
75  //tag of FEDRawData collection
77  //histogram helper class
78  FEDHistograms fedHists_;
79  //folder name for histograms in DQMStore
80  std::string folderName_;
81  //book detailed histograms even if they will be empty (for merging)
83  //do histos vs time with time=event number. Default time = orbit number (s)
85  //print debug messages when problems are found: 1=error debug, 2=light debug, 3=full debug
86  unsigned int printDebug_;
87  //bool printDebug_;
88  //write the DQMStore to a root file at the end of the job
90  std::string dqmStoreFileName_;
91  //the DQMStore
93  //FED cabling
94  uint32_t cablingCacheId_;
96 
97  //add parameter to save computing time if TkHistoMap are not filled
100 
101  unsigned int nEvt_;
102 
103  //FED errors
104  //need class member for lumi histograms
105  FEDErrors fedErrors_;
106 
107 };
108 
109 
110 //
111 // Constructors and destructor
112 //
113 
115  : rawDataTag_(iConfig.getUntrackedParameter<edm::InputTag>("RawDataTag",edm::InputTag("source",""))),
116  folderName_(iConfig.getUntrackedParameter<std::string>("HistogramFolderName","SiStrip/ReadoutView/FedMonitoringSummary")),
117  fillAllDetailedHistograms_(iConfig.getUntrackedParameter<bool>("FillAllDetailedHistograms",false)),
118  fillWithEvtNum_(iConfig.getUntrackedParameter<bool>("FillWithEventNumber",false)),
119  printDebug_(iConfig.getUntrackedParameter<unsigned int>("PrintDebugMessages",1)),
120  //printDebug_(iConfig.getUntrackedParameter<bool>("PrintDebugMessages",false)),
121  writeDQMStore_(iConfig.getUntrackedParameter<bool>("WriteDQMStore",false)),
122  dqmStoreFileName_(iConfig.getUntrackedParameter<std::string>("DQMStoreFileName","DQMStore.root")),
123  dqm_(0),
124  cablingCacheId_(0)
125 {
126  //print config to debug log
127  std::ostringstream debugStream;
128  if (printDebug_>1) {
129  debugStream << "[SiStripFEDMonitorPlugin]Configuration for SiStripFEDMonitorPlugin: " << std::endl
130  << "[SiStripFEDMonitorPlugin]\tRawDataTag: " << rawDataTag_ << std::endl
131  << "[SiStripFEDMonitorPlugin]\tHistogramFolderName: " << folderName_ << std::endl
132  << "[SiStripFEDMonitorPlugin]\tFillAllDetailedHistograms? " << (fillAllDetailedHistograms_ ? "yes" : "no") << std::endl
133  << "[SiStripFEDMonitorPlugin]\tFillWithEventNumber?" << (fillWithEvtNum_ ? "yes" : "no") << std::endl
134  << "[SiStripFEDMonitorPlugin]\tPrintDebugMessages? " << (printDebug_ ? "yes" : "no") << std::endl
135  << "[SiStripFEDMonitorPlugin]\tWriteDQMStore? " << (writeDQMStore_ ? "yes" : "no") << std::endl;
136  if (writeDQMStore_) debugStream << "[SiStripFEDMonitorPlugin]\tDQMStoreFileName: " << dqmStoreFileName_ << std::endl;
137  }
138 
139  //don;t generate debug mesages if debug is disabled
140  std::ostringstream* pDebugStream = (printDebug_>1 ? &debugStream : NULL);
141 
142  fedHists_.initialise(iConfig,pDebugStream);
143 
144  doTkHistoMap_ = fedHists_.tkHistoMapEnabled();
145 
146  doMedHists_ = fedHists_.cmHistosEnabled();
147 
148  if (printDebug_) {
149  LogTrace("SiStripMonitorHardware") << debugStream.str();
150 
151  //debugStream.str("");
152 
153  //debugStream << " -- Quelle est la difference entre un canard ? " << std::endl
154  // << " -- Reponse: c'est qu'il a les deux pattes de la meme longueur, surtout la gauche." << std::endl;
155 
156  //edm::LogError("SiStripMonitorHardware") << debugStream.str();
157  }
158 
159  nEvt_ = 0;
160 
161 }
162 
164 {
165 }
166 
167 
168 //
169 // Member functions
170 //
171 
172 // ------------ method called to for each event ------------
173 void
175  const edm::EventSetup& iSetup)
176 {
177  //update cabling
178  updateCabling(iSetup);
179 
180  //get raw data
181  edm::Handle<FEDRawDataCollection> rawDataCollectionHandle;
182  iEvent.getByLabel(rawDataTag_,rawDataCollectionHandle);
183  const FEDRawDataCollection& rawDataCollection = *rawDataCollectionHandle;
184 
185  fedErrors_.initialiseEvent();
186 
187  //initialise map of fedId/bad channel number
188  std::map<unsigned int,std::pair<unsigned short,unsigned short> > badChannelFraction;
189 
190  unsigned int lNFEDMonitoring = 0;
191  unsigned int lNFEDUnpacker = 0;
192  unsigned int lNChannelMonitoring = 0;
193  unsigned int lNChannelUnpacker = 0;
194 
195  unsigned int lNTotBadFeds = 0;
196  unsigned int lNTotBadChannels = 0;
197  unsigned int lNTotBadActiveChannels = 0;
198 
199  //loop over siStrip FED IDs
200  for (unsigned int fedId = FEDNumbering::MINSiStripFEDID;
202  fedId++) {//loop over FED IDs
203  const FEDRawData& fedData = rawDataCollection.FEDData(fedId);
204 
205  //create an object to fill all errors
206  fedErrors_.initialiseFED(fedId,cabling_);
207  bool lFullDebug = false;
208 
209  //Do detailed check
210  //first check if data exists
211  bool lDataExist = fedErrors_.checkDataPresent(fedData);
212  if (!lDataExist) {
213  fedHists_.fillFEDHistograms(fedErrors_,lFullDebug);
214  continue;
215  }
216 
217 
218 
219  //check for problems and fill detailed histograms
220  fedErrors_.fillFEDErrors(fedData,
221  lFullDebug,
222  printDebug_,
223  lNChannelMonitoring,
224  lNChannelUnpacker,
225  doMedHists_,
226  fedHists_.cmHistPointer(false),
227  fedHists_.cmHistPointer(true)
228  );
229 
230  //check filled in previous method.
231  bool lFailUnpackerFEDcheck = fedErrors_.failUnpackerFEDCheck();
232 
233  fedErrors_.incrementFEDCounters();
234  fedHists_.fillFEDHistograms(fedErrors_,lFullDebug);
235 
236 
237  bool lFailMonitoringFEDcheck = fedErrors_.failMonitoringFEDCheck();
238  if (lFailMonitoringFEDcheck) lNTotBadFeds++;
239 
240 
241  //sanity check: if something changed in the unpacking code
242  //but wasn't propagated here
243  //print only the summary, and more info if printDebug>1
244  if (lFailMonitoringFEDcheck != lFailUnpackerFEDcheck) {
245  if (printDebug_>1) {
246  std::ostringstream debugStream;
247  debugStream << " --- WARNING: FED " << fedId << std::endl
248  << " ------ Monitoring FED check " ;
249  if (lFailMonitoringFEDcheck) debugStream << "failed." << std::endl;
250  else debugStream << "passed." << std::endl ;
251  debugStream << " ------ Unpacker FED check " ;
252  if (lFailUnpackerFEDcheck) debugStream << "failed." << std::endl;
253  else debugStream << "passed." << std::endl ;
254  edm::LogError("SiStripMonitorHardware") << debugStream.str();
255  }
256 
257  if (lFailMonitoringFEDcheck) lNFEDMonitoring++;
258  else if (lFailUnpackerFEDcheck) lNFEDUnpacker++;
259  }
260 
261 
262  //Fill TkHistoMap:
263  //add an entry for all channels (good = 0),
264  //so that tkHistoMap knows which channels should be there.
265  if (doTkHistoMap_ && !fedHists_.tkHistoMapPointer()) {
266  edm::LogWarning("SiStripMonitorHardware") << " -- Fedid " << fedId
267  << ", TkHistoMap enabled but pointer is null." << std::endl;
268  }
269 
270  fedErrors_.fillBadChannelList(doTkHistoMap_,
271  fedHists_.tkHistoMapPointer(),
272  lNTotBadChannels,
273  lNTotBadActiveChannels);
274  }//loop over FED IDs
275 
276  if ((lNTotBadFeds> 0 || lNTotBadChannels>0) && printDebug_>1) {
277  std::ostringstream debugStream;
278  debugStream << "[SiStripFEDMonitorPlugin] --- Total number of bad feds = "
279  << lNTotBadFeds << std::endl
280  << "[SiStripFEDMonitorPlugin] --- Total number of bad channels = "
281  << lNTotBadChannels << std::endl
282  << "[SiStripFEDMonitorPlugin] --- Total number of bad active channels = "
283  << lNTotBadActiveChannels << std::endl;
284  edm::LogInfo("SiStripMonitorHardware") << debugStream.str();
285  }
286 
287  if ((lNFEDMonitoring > 0 || lNFEDUnpacker > 0 || lNChannelMonitoring > 0 || lNChannelUnpacker > 0) && printDebug_) {
288  std::ostringstream debugStream;
289  debugStream
290  << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
291  << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
292  << "[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at FED level : " << std::endl
293  << "[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNFEDMonitoring << std::endl
294  << "[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNFEDUnpacker << std::endl
295  << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
296  << "[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at Channel level : " << std::endl
297  << "[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNChannelMonitoring << std::endl
298  << "[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNChannelUnpacker << std::endl
299  << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
300  << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl ;
301  edm::LogError("SiStripMonitorHardware") << debugStream.str();
302 
303  }
304 
305  FEDErrors::getFEDErrorsCounters().nTotalBadChannels = lNTotBadChannels;
306  FEDErrors::getFEDErrorsCounters().nTotalBadActiveChannels = lNTotBadActiveChannels;
307 
308  //fedHists_.fillCountersHistograms(FEDErrors::getFEDErrorsCounters(), nEvt_);
309  //time in seconds since beginning of the run or event number
310  if (fillWithEvtNum_) fedHists_.fillCountersHistograms(FEDErrors::getFEDErrorsCounters(),FEDErrors::getChannelErrorsCounters(),iEvent.id().event());
311  else fedHists_.fillCountersHistograms(FEDErrors::getFEDErrorsCounters(),FEDErrors::getChannelErrorsCounters(),iEvent.orbitNumber()/11223.);
312 
313 
314  nEvt_++;
315 
316 }//analyze method
317 
318 // ------------ method called once each job just before starting event loop ------------
319 void
321 {
322  //get DQM store
325 
326  //this propagates dqm_ to the histoclass, must be called !
327  fedHists_.bookTopLevelHistograms(dqm_);
328 
329  if (fillAllDetailedHistograms_) fedHists_.bookAllFEDHistograms();
330 
331  nEvt_ = 0;
332 
333  //const unsigned int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
334  //const unsigned int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
335 
336  //mark all channels as inactive until they have been 'locked' at least once
337  // activeChannels_.resize(siStripFedIdMax+1);
338  // for (unsigned int fedId = siStripFedIdMin;
339  // fedId <= siStripFedIdMax;
340  // fedId++) {
341  // activeChannels_[fedId].resize(sistrip::FEDCH_PER_FED,false);
342  // }
343 
344 
345 
346 
347 }
348 
349 // ------------ method called once each job just after ending the event loop ------------
350 void
352 {
354 }
355 
356 
357 
358 void
360  const edm::EventSetup& context)
361 {
362 
363  fedErrors_.initialiseLumiBlock();
364 
365 }
366 
367 
368 void
370  const edm::EventSetup& context)
371 {
372  fedHists_.fillLumiHistograms(fedErrors_.getLumiErrors());
373 }
374 
375 
376 
377 
379 {
380  uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
381  if (cablingCacheId_ != currentCacheId) {
382  edm::ESHandle<SiStripFedCabling> cablingHandle;
383  eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
384  cabling_ = cablingHandle.product();
385  cablingCacheId_ = currentCacheId;
386  }
387 }
388 
389 
390 //
391 // Define as a plug-in
392 //
393 
EventNumber_t event() const
Definition: EventID.h:44
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:1883
#define NULL
Definition: scimark2.h:8
virtual void analyze(const edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:243
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
SiStripFEDMonitorPlugin(const edm::ParameterSet &)
int orbitNumber() const
Definition: EventBase.h:63
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
#define LogTrace(id)
virtual void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
const T & get() const
Definition: EventSetup.h:55
virtual void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
T const * product() const
Definition: ESHandle.h:62
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
edm::EventID id() const
Definition: EventBase.h:56
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237
void updateCabling(const edm::EventSetup &eventSetup)