Go to the documentation of this file.00001
00002
00003
00004
00005
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <sstream>
00022 #include <memory>
00023 #include <list>
00024 #include <algorithm>
00025 #include <cassert>
00026
00027 #include "FWCore/Framework/interface/Frameworkfwd.h"
00028 #include "FWCore/Framework/interface/EDAnalyzer.h"
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/EventSetup.h"
00031 #include "FWCore/Framework/interface/ESHandle.h"
00032 #include "FWCore/Framework/interface/LuminosityBlock.h"
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 #include "FWCore/Utilities/interface/InputTag.h"
00035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00036 #include "FWCore/ServiceRegistry/interface/Service.h"
00037 #include "FWCore/Utilities/interface/Exception.h"
00038
00039 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00040 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00041 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00042 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00043
00044 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
00045 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00046
00047 #include "DQMServices/Core/interface/DQMStore.h"
00048
00049 #include "DQM/SiStripMonitorHardware/interface/FEDHistograms.hh"
00050 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh"
00051
00052
00053
00054
00055
00056
00057 class SiStripFEDMonitorPlugin : public edm::EDAnalyzer
00058 {
00059 public:
00060 explicit SiStripFEDMonitorPlugin(const edm::ParameterSet&);
00061 ~SiStripFEDMonitorPlugin();
00062 private:
00063 virtual void beginJob();
00064 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00065 virtual void endJob();
00066 virtual void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00067 const edm::EventSetup& context);
00068 virtual void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00069 const edm::EventSetup& context);
00070
00071
00072 void updateCabling(const edm::EventSetup& eventSetup);
00073
00074
00075
00076 edm::InputTag rawDataTag_;
00077
00078 FEDHistograms fedHists_;
00079
00080 std::string folderName_;
00081
00082 bool fillAllDetailedHistograms_;
00083
00084 bool fillWithEvtNum_;
00085
00086 unsigned int printDebug_;
00087
00088
00089 bool writeDQMStore_;
00090 std::string dqmStoreFileName_;
00091
00092 DQMStore* dqm_;
00093
00094 uint32_t cablingCacheId_;
00095 const SiStripFedCabling* cabling_;
00096
00097
00098 bool doTkHistoMap_;
00099 bool doMedHists_;
00100
00101 unsigned int nEvt_;
00102
00103
00104
00105 FEDErrors fedErrors_;
00106
00107 };
00108
00109
00110
00111
00112
00113
00114 SiStripFEDMonitorPlugin::SiStripFEDMonitorPlugin(const edm::ParameterSet& iConfig)
00115 : rawDataTag_(iConfig.getUntrackedParameter<edm::InputTag>("RawDataTag",edm::InputTag("source",""))),
00116 folderName_(iConfig.getUntrackedParameter<std::string>("HistogramFolderName","SiStrip/ReadoutView/FedMonitoringSummary")),
00117 fillAllDetailedHistograms_(iConfig.getUntrackedParameter<bool>("FillAllDetailedHistograms",false)),
00118 fillWithEvtNum_(iConfig.getUntrackedParameter<bool>("FillWithEventNumber",false)),
00119 printDebug_(iConfig.getUntrackedParameter<unsigned int>("PrintDebugMessages",1)),
00120
00121 writeDQMStore_(iConfig.getUntrackedParameter<bool>("WriteDQMStore",false)),
00122 dqmStoreFileName_(iConfig.getUntrackedParameter<std::string>("DQMStoreFileName","DQMStore.root")),
00123 dqm_(0),
00124 cablingCacheId_(0)
00125 {
00126
00127 std::ostringstream debugStream;
00128 if (printDebug_>1) {
00129 debugStream << "[SiStripFEDMonitorPlugin]Configuration for SiStripFEDMonitorPlugin: " << std::endl
00130 << "[SiStripFEDMonitorPlugin]\tRawDataTag: " << rawDataTag_ << std::endl
00131 << "[SiStripFEDMonitorPlugin]\tHistogramFolderName: " << folderName_ << std::endl
00132 << "[SiStripFEDMonitorPlugin]\tFillAllDetailedHistograms? " << (fillAllDetailedHistograms_ ? "yes" : "no") << std::endl
00133 << "[SiStripFEDMonitorPlugin]\tFillWithEventNumber?" << (fillWithEvtNum_ ? "yes" : "no") << std::endl
00134 << "[SiStripFEDMonitorPlugin]\tPrintDebugMessages? " << (printDebug_ ? "yes" : "no") << std::endl
00135 << "[SiStripFEDMonitorPlugin]\tWriteDQMStore? " << (writeDQMStore_ ? "yes" : "no") << std::endl;
00136 if (writeDQMStore_) debugStream << "[SiStripFEDMonitorPlugin]\tDQMStoreFileName: " << dqmStoreFileName_ << std::endl;
00137 }
00138
00139
00140 std::ostringstream* pDebugStream = (printDebug_>1 ? &debugStream : NULL);
00141
00142 fedHists_.initialise(iConfig,pDebugStream);
00143
00144 doTkHistoMap_ = fedHists_.tkHistoMapEnabled();
00145
00146 doMedHists_ = fedHists_.cmHistosEnabled();
00147
00148 if (printDebug_) {
00149 LogTrace("SiStripMonitorHardware") << debugStream.str();
00150
00151
00152
00153
00154
00155
00156
00157 }
00158
00159 nEvt_ = 0;
00160
00161 }
00162
00163 SiStripFEDMonitorPlugin::~SiStripFEDMonitorPlugin()
00164 {
00165 }
00166
00167
00168
00169
00170
00171
00172
00173 void
00174 SiStripFEDMonitorPlugin::analyze(const edm::Event& iEvent,
00175 const edm::EventSetup& iSetup)
00176 {
00177
00178 updateCabling(iSetup);
00179
00180
00181 edm::Handle<FEDRawDataCollection> rawDataCollectionHandle;
00182 iEvent.getByLabel(rawDataTag_,rawDataCollectionHandle);
00183 const FEDRawDataCollection& rawDataCollection = *rawDataCollectionHandle;
00184
00185 fedErrors_.initialiseEvent();
00186
00187
00188 std::map<unsigned int,std::pair<unsigned short,unsigned short> > badChannelFraction;
00189
00190 unsigned int lNFEDMonitoring = 0;
00191 unsigned int lNFEDUnpacker = 0;
00192 unsigned int lNChannelMonitoring = 0;
00193 unsigned int lNChannelUnpacker = 0;
00194
00195 unsigned int lNTotBadFeds = 0;
00196 unsigned int lNTotBadChannels = 0;
00197 unsigned int lNTotBadActiveChannels = 0;
00198
00199
00200 for (unsigned int fedId = FEDNumbering::MINSiStripFEDID;
00201 fedId <= FEDNumbering::MAXSiStripFEDID;
00202 fedId++) {
00203 const FEDRawData& fedData = rawDataCollection.FEDData(fedId);
00204
00205
00206 fedErrors_.initialiseFED(fedId,cabling_);
00207 bool lFullDebug = false;
00208
00209
00210
00211 bool lDataExist = fedErrors_.checkDataPresent(fedData);
00212 if (!lDataExist) {
00213 fedHists_.fillFEDHistograms(fedErrors_,lFullDebug);
00214 continue;
00215 }
00216
00217
00218
00219
00220 fedErrors_.fillFEDErrors(fedData,
00221 lFullDebug,
00222 printDebug_,
00223 lNChannelMonitoring,
00224 lNChannelUnpacker,
00225 doMedHists_,
00226 fedHists_.cmHistPointer(false),
00227 fedHists_.cmHistPointer(true)
00228 );
00229
00230
00231 bool lFailUnpackerFEDcheck = fedErrors_.failUnpackerFEDCheck();
00232
00233 fedErrors_.incrementFEDCounters();
00234 fedHists_.fillFEDHistograms(fedErrors_,lFullDebug);
00235
00236
00237 bool lFailMonitoringFEDcheck = fedErrors_.failMonitoringFEDCheck();
00238 if (lFailMonitoringFEDcheck) lNTotBadFeds++;
00239
00240
00241
00242
00243
00244 if (lFailMonitoringFEDcheck != lFailUnpackerFEDcheck) {
00245 if (printDebug_>1) {
00246 std::ostringstream debugStream;
00247 debugStream << " --- WARNING: FED " << fedId << std::endl
00248 << " ------ Monitoring FED check " ;
00249 if (lFailMonitoringFEDcheck) debugStream << "failed." << std::endl;
00250 else debugStream << "passed." << std::endl ;
00251 debugStream << " ------ Unpacker FED check " ;
00252 if (lFailUnpackerFEDcheck) debugStream << "failed." << std::endl;
00253 else debugStream << "passed." << std::endl ;
00254 edm::LogError("SiStripMonitorHardware") << debugStream.str();
00255 }
00256
00257 if (lFailMonitoringFEDcheck) lNFEDMonitoring++;
00258 else if (lFailUnpackerFEDcheck) lNFEDUnpacker++;
00259 }
00260
00261
00262
00263
00264
00265 if (doTkHistoMap_ && !fedHists_.tkHistoMapPointer()) {
00266 edm::LogWarning("SiStripMonitorHardware") << " -- Fedid " << fedId
00267 << ", TkHistoMap enabled but pointer is null." << std::endl;
00268 }
00269
00270 fedErrors_.fillBadChannelList(doTkHistoMap_,
00271 fedHists_.tkHistoMapPointer(),
00272 lNTotBadChannels,
00273 lNTotBadActiveChannels);
00274 }
00275
00276 if ((lNTotBadFeds> 0 || lNTotBadChannels>0) && printDebug_>1) {
00277 std::ostringstream debugStream;
00278 debugStream << "[SiStripFEDMonitorPlugin] --- Total number of bad feds = "
00279 << lNTotBadFeds << std::endl
00280 << "[SiStripFEDMonitorPlugin] --- Total number of bad channels = "
00281 << lNTotBadChannels << std::endl
00282 << "[SiStripFEDMonitorPlugin] --- Total number of bad active channels = "
00283 << lNTotBadActiveChannels << std::endl;
00284 edm::LogInfo("SiStripMonitorHardware") << debugStream.str();
00285 }
00286
00287 if ((lNFEDMonitoring > 0 || lNFEDUnpacker > 0 || lNChannelMonitoring > 0 || lNChannelUnpacker > 0) && printDebug_) {
00288 std::ostringstream debugStream;
00289 debugStream
00290 << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
00291 << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
00292 << "[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at FED level : " << std::endl
00293 << "[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNFEDMonitoring << std::endl
00294 << "[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNFEDUnpacker << std::endl
00295 << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
00296 << "[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at Channel level : " << std::endl
00297 << "[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNChannelMonitoring << std::endl
00298 << "[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNChannelUnpacker << std::endl
00299 << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
00300 << "[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl ;
00301 edm::LogError("SiStripMonitorHardware") << debugStream.str();
00302
00303 }
00304
00305 FEDErrors::getFEDErrorsCounters().nTotalBadChannels = lNTotBadChannels;
00306 FEDErrors::getFEDErrorsCounters().nTotalBadActiveChannels = lNTotBadActiveChannels;
00307
00308
00309
00310 if (fillWithEvtNum_) fedHists_.fillCountersHistograms(FEDErrors::getFEDErrorsCounters(),FEDErrors::getChannelErrorsCounters(),iEvent.id().event());
00311 else fedHists_.fillCountersHistograms(FEDErrors::getFEDErrorsCounters(),FEDErrors::getChannelErrorsCounters(),iEvent.orbitNumber()/11223.);
00312
00313
00314 nEvt_++;
00315
00316 }
00317
00318
00319 void
00320 SiStripFEDMonitorPlugin::beginJob()
00321 {
00322
00323 dqm_ = &(*edm::Service<DQMStore>());
00324 dqm_->setCurrentFolder(folderName_);
00325
00326
00327 fedHists_.bookTopLevelHistograms(dqm_);
00328
00329 if (fillAllDetailedHistograms_) fedHists_.bookAllFEDHistograms();
00330
00331 nEvt_ = 0;
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 }
00348
00349
00350 void
00351 SiStripFEDMonitorPlugin::endJob()
00352 {
00353 if (writeDQMStore_) dqm_->save(dqmStoreFileName_);
00354 }
00355
00356
00357
00358 void
00359 SiStripFEDMonitorPlugin::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00360 const edm::EventSetup& context)
00361 {
00362
00363 fedErrors_.initialiseLumiBlock();
00364
00365 }
00366
00367
00368 void
00369 SiStripFEDMonitorPlugin::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00370 const edm::EventSetup& context)
00371 {
00372 fedHists_.fillLumiHistograms(fedErrors_.getLumiErrors());
00373 }
00374
00375
00376
00377
00378 void SiStripFEDMonitorPlugin::updateCabling(const edm::EventSetup& eventSetup)
00379 {
00380 uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
00381 if (cablingCacheId_ != currentCacheId) {
00382 edm::ESHandle<SiStripFedCabling> cablingHandle;
00383 eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
00384 cabling_ = cablingHandle.product();
00385 cablingCacheId_ = currentCacheId;
00386 }
00387 }
00388
00389
00390
00391
00392
00393
00394 #include "FWCore/Framework/interface/MakerMacros.h"
00395 DEFINE_FWK_MODULE(SiStripFEDMonitorPlugin);