CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DQM/TrackingMonitor/src/LogMessageMonitor.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    LogMessageMonitor
00004 // Class:      LogMessageMonitor
00005 // 
00049 //
00050 // Original Author:  Mia Tosi,40 3-B32,+41227671609,
00051 //         Created:  Thu Mar  8 14:34:13 CET 2012
00052 // $Id: LogMessageMonitor.cc,v 1.4 2012/10/27 20:40:08 tosi Exp $
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 // constants, enums and typedefs
00071 //
00072 
00073 //
00074 // static data member definitions
00075 //
00076 
00077 //
00078 // constructors and destructor
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    //now do what ever initialization is needed
00090   lumiDetails_         = new GetLumi( iConfig.getParameter<edm::ParameterSet>("BXlumiSetup") ); 
00091   genTriggerEventFlag_ = new GenericTriggerEventFlag(iConfig);
00092 }
00093 
00094 
00095 LogMessageMonitor::~LogMessageMonitor()
00096 {
00097  
00098    // do anything here that needs to be done at desctruction time
00099    // (e.g. close files, deallocate resources etc.)
00100   //  if ( lumiDetails_         ) delete lumiDetails_;
00101   if ( genTriggerEventFlag_ ) delete genTriggerEventFlag_;
00102 
00103 }
00104 
00105 
00106 //
00107 // member functions
00108 //
00109 
00110 // ------------ method called for each event  ------------
00111 void
00112 LogMessageMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00113 {
00114 
00115   // Filter out events if Trigger Filtering is requested
00116   if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
00117 
00118   double BXlumi = -1.;
00119   if ( doPUmonitoring_ )
00120     lumiDetails_->getValue(iEvent);
00121   
00122     // Take the ErrorSummaryEntry container
00123   edm::Handle<std::vector<edm::ErrorSummaryEntry> >  errors;
00124   iEvent.getByLabel("logErrorHarvester",errors);
00125   // Check that errors is valid
00126   if(!errors.isValid()) return; 
00127   // Compare severity level of error with ELseveritylevel instance el : "-e" should be the lowest error
00128   edm::ELseverityLevel el("-e");
00129   
00130   // Find the total number of errors in iEvent
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       //      std::cout << "LogMessageMonitor::analyze] Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module  << std::endl;
00146       // remove the first part of the module string, what is before ":"
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         //      std::cout << "LogMessageMonitor::analyze] it: " << " --> " << s_module << std::endl;
00153 
00154         // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
00155         if((*errors)[i].severity.getLevel() >= edm::ELseverityLevel::ELsev_error) {
00156           if ( doPUmonitoring_ )
00157             ModulesErrorsVsBXlumi[it->second]->Fill (BXlumi, (*errors)[i].count);
00158 
00159           // loop over the different categories of errors
00160           // defined by configuration file
00161           // if the category is not in the given list
00162           // it fills the bin "others"
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           std::cout << "LogMessageMonitor::analyze] ibinX: " << ibinX << " it->second: " << it->second << " it->first: " << it->first << std::endl;
00169           std::cout << "LogMessageMonitor::analyze] ibinY: " << ibinY << " (*errors)[i].category: " << (*errors)[i].category << std::endl;
00170           size_t nbinsX = CategoriesVsModules->getTH1()->GetNbinsX();
00171           for (size_t bin = 1; bin<=nbinsX; bin++) {
00172             std::cout << "binX" << bin << ": " << CategoriesVsModules->getTH1()->GetXaxis()->GetBinLabel(bin) << std::endl;
00173           }
00174           size_t nbinsY = CategoriesVsModules->getTH1()->GetNbinsY();
00175           for (size_t bin = 1; bin<=nbinsY; bin++) {
00176             std::cout << "binY" << bin << ": " << CategoriesVsModules->getTH1()->GetYaxis()->GetBinLabel(bin) << std::endl;
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           // IF ONLY WARNING, FILL WARNING HISTS
00188           if ( doWarningsPlots_ ) 
00189             if ( doPUmonitoring_ )
00190               ModulesWarningsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
00191         }
00192       }
00193     }
00194   }
00195 }
00196 
00197 
00198 // ------------ method called once each job just before starting event loop  ------------
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    //   CategoriesVsModules->getTH1()->GetXaxis()->LabelsOption("v");
00217    for (size_t icategories = 0; icategories < nCategories; icategories++)
00218      CategoriesVsModules->setBinLabel(icategories+1,categories_vector_[icategories],2);
00219    
00220    // MAKE MODULEMAP USING INPUT FROM CFG FILE
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      // BOOK THE HISTOGRAMS
00227      // get binning from the configuration
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 // ------------ method called once each job just after ending the event loop  ------------
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 // ------------ method called when starting to processes a run  ------------
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 // ------------ method called when ending the processing of a run  ------------
00278 void 
00279 LogMessageMonitor::endRun(edm::Run const&, edm::EventSetup const&)
00280 {
00281 }
00282 
00283 // ------------ method called when starting to processes a luminosity block  ------------
00284 void 
00285 LogMessageMonitor::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00286 {
00287 }
00288 
00289 // ------------ method called when ending the processing of a luminosity block  ------------
00290 void 
00291 LogMessageMonitor::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00292 {
00293 }
00294 
00295 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00296 void
00297 LogMessageMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00298   //The following says we do not know what parameters are allowed so do no validation
00299   // Please change this to state exactly what you do use, even if it is no parameters
00300   edm::ParameterSetDescription desc;
00301   desc.setUnknown();
00302   descriptions.addDefault(desc);
00303 }
00304 
00305 DEFINE_FWK_MODULE(LogMessageMonitor);