00001
00002
00003
00004
00005
00049
00050
00051
00052
00053
00054
00055
00056 #include "DQM/TrackingMonitor/interface/LogMessageMonitor.h"
00057
00058 #include "DQMServices/Core/interface/DQMStore.h"
00059 #include "DQMServices/Core/interface/MonitorElement.h"
00060 #include "DataFormats/Common/interface/Handle.h"
00061
00062 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
00063 #include "FWCore/MessageLogger/interface/ELstring.h"
00064 #include "FWCore/MessageLogger/interface/ErrorSummaryEntry.h"
00065 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00066
00067 #include "DQM/TrackingMonitor/interface/GetLumi.h"
00068 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 LogMessageMonitor::LogMessageMonitor(const edm::ParameterSet& iConfig)
00081 : dqmStore_( edm::Service<DQMStore>().operator->() )
00082 , conf_ ( iConfig )
00083 , pluginsMonName_ ( iConfig.getParameter<std::string> ("pluginsMonName") )
00084 , modules_vector_ ( iConfig.getParameter<std::vector<std::string> >("modules") )
00085 , categories_vector_ ( iConfig.getParameter<std::vector<std::string> >("categories") )
00086 , doWarningsPlots_ ( iConfig.getParameter<bool> ("doWarningsPlots") )
00087 , doPUmonitoring_ ( iConfig.getParameter<bool> ("doPUmonitoring") )
00088 {
00089
00090 lumiDetails_ = new GetLumi( iConfig.getParameter<edm::ParameterSet>("BXlumiSetup") );
00091 genTriggerEventFlag_ = new GenericTriggerEventFlag(iConfig);
00092 }
00093
00094
00095 LogMessageMonitor::~LogMessageMonitor()
00096 {
00097
00098
00099
00100
00101 if ( genTriggerEventFlag_ ) delete genTriggerEventFlag_;
00102
00103 }
00104
00105
00106
00107
00108
00109
00110
00111 void
00112 LogMessageMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00113 {
00114
00115
00116 if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
00117
00118 double BXlumi = -1.;
00119 if ( doPUmonitoring_ )
00120 lumiDetails_->getValue(iEvent);
00121
00122
00123 edm::Handle<std::vector<edm::ErrorSummaryEntry> > errors;
00124 iEvent.getByLabel("logErrorHarvester",errors);
00125
00126 if(!errors.isValid()) return;
00127
00128 edm::ELseverityLevel el("-e");
00129
00130
00131 if(errors->size()==0){
00132 if ( doPUmonitoring_ ) {
00133 for(size_t i = 0; i < modulesMap.size(); i++) {
00134 ModulesErrorsVsBXlumi[i] -> Fill(BXlumi,0.);
00135 if ( doWarningsPlots_ )
00136 ModulesWarningsVsBXlumi[i] -> Fill(BXlumi,0.);
00137 }
00138 }
00139 } else {
00140
00141 size_t nCategories = categories_vector_.size();
00142
00143 for( size_t i = 0, n = errors->size(); i < n ; i++){
00144
00145
00146
00147 std::string s = (*errors)[i].module;
00148 size_t pos = s.find(':');
00149 std::string s_module = s.substr(pos+1,s.size());
00150 std::map<std::string,int>::const_iterator it = modulesMap.find(s_module);
00151 if (it!=modulesMap.end()){
00152
00153
00154
00155 if((*errors)[i].severity.getLevel() >= edm::ELseverityLevel::ELsev_error) {
00156 if ( doPUmonitoring_ )
00157 ModulesErrorsVsBXlumi[it->second]->Fill (BXlumi, (*errors)[i].count);
00158
00159
00160
00161
00162
00163 TString module = it->first;
00164 TString category = (*errors)[i].category;
00165 int ibinX = CategoriesVsModules->getTH1()->GetXaxis()->FindBin(module);
00166 int ibinY = CategoriesVsModules->getTH1()->GetYaxis()->FindBin(category);
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 if ( ibinY>0 ) {
00180 int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX,ibinY)+1;
00181 CategoriesVsModules->getTH1()->SetBinContent(ibinX,ibinY,ncount);
00182 } else {
00183 int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX,nCategories)+1;
00184 CategoriesVsModules->getTH1()->SetBinContent(ibinX,nCategories,ncount);
00185 }
00186 } else {
00187
00188 if ( doWarningsPlots_ )
00189 if ( doPUmonitoring_ )
00190 ModulesWarningsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
00191 }
00192 }
00193 }
00194 }
00195 }
00196
00197
00198
00199 void
00200 LogMessageMonitor::beginJob()
00201 {
00202 std::string MEFolderName = conf_.getParameter<std::string>("LogFolderName");
00203
00204 dqmStore_->setCurrentFolder(MEFolderName);
00205
00206 categories_vector_.push_back("others");
00207 size_t nModules = modules_vector_.size();
00208 size_t nCategories = categories_vector_.size();
00209
00210 histname = pluginsMonName_+"ErrorsVsModules";
00211 CategoriesVsModules = dqmStore_->book2D(histname, histname, nModules, 0., double(nModules), nCategories, 0., double(nCategories) );
00212 CategoriesVsModules->setAxisTitle("modules",1);
00213 for (size_t imodule = 0; imodule < nModules; imodule++)
00214 CategoriesVsModules->setBinLabel(imodule+1,modules_vector_[imodule],1);
00215 CategoriesVsModules->setAxisTitle("categories",2);
00216
00217 for (size_t icategories = 0; icategories < nCategories; icategories++)
00218 CategoriesVsModules->setBinLabel(icategories+1,categories_vector_[icategories],2);
00219
00220
00221 for (size_t i = 0; i < modules_vector_.size(); i++){
00222 modulesMap.insert( std::pair<std::string,int>(modules_vector_[i],i) );
00223 }
00224
00225 if ( doPUmonitoring_ ) {
00226
00227
00228 edm::ParameterSet BXlumiParameters = conf_.getParameter<edm::ParameterSet>("BXlumiSetup");
00229 int BXlumiBin = BXlumiParameters.getParameter<int>("BXlumiBin");
00230 double BXlumiMin = BXlumiParameters.getParameter<double>("BXlumiMin");
00231 double BXlumiMax = BXlumiParameters.getParameter<double>("BXlumiMax");
00232
00233 size_t i = 0;
00234 for(std::map<std::string,int>::const_iterator it = modulesMap.begin();
00235 it != modulesMap.end(); ++it, i++){
00236
00237 dqmStore_->setCurrentFolder(MEFolderName + "/PUmonitoring/Errors");
00238
00239 histname = "errorsVsBXlumi_" + it->first;
00240 ModulesErrorsVsBXlumi.push_back( dynamic_cast<MonitorElement*>(dqmStore_->bookProfile( histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0.,100, "")) );
00241 ModulesErrorsVsBXlumi[i] -> setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
00242 ModulesErrorsVsBXlumi[i] -> setAxisTitle("Mean number of errors", 2);
00243
00244 if ( doWarningsPlots_ ) {
00245 dqmStore_->setCurrentFolder(MEFolderName + "/PUmonitoring/Warnings");
00246
00247 histname = "warningVsBXlumi_" + it->first;
00248 ModulesWarningsVsBXlumi.push_back( dynamic_cast<MonitorElement*>(dqmStore_->bookProfile( histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0.,100, "")) );
00249 ModulesWarningsVsBXlumi[i] -> setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
00250 ModulesWarningsVsBXlumi[i] -> setAxisTitle("Mean number of warnings", 2);
00251 }
00252 }
00253 }
00254
00255 }
00256
00257
00258 void
00259 LogMessageMonitor::endJob()
00260 {
00261 bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
00262 std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00263 if(outputMEsInRootFile)
00264 {
00265 dqmStore_->showDirStructure();
00266 dqmStore_->save(outputFileName);
00267 }
00268 }
00269
00270
00271 void
00272 LogMessageMonitor::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00273 {
00274 if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( iRun, iSetup );
00275 }
00276
00277
00278 void
00279 LogMessageMonitor::endRun(edm::Run const&, edm::EventSetup const&)
00280 {
00281 }
00282
00283
00284 void
00285 LogMessageMonitor::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00286 {
00287 }
00288
00289
00290 void
00291 LogMessageMonitor::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00292 {
00293 }
00294
00295
00296 void
00297 LogMessageMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00298
00299
00300 edm::ParameterSetDescription desc;
00301 desc.setUnknown();
00302 descriptions.addDefault(desc);
00303 }
00304
00305 DEFINE_FWK_MODULE(LogMessageMonitor);