CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DQM/TrackingMonitor/plugins/LogMessageMonitor.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    LogMessageMonitor
00004 // Class:      LogMessageMonitor
00005 // 
00013 //
00014 // Original Author:  Mia Tosi,40 3-B32,+41227671609,
00015 //         Created:  Thu Mar  8 14:34:13 CET 2012
00016 // $Id: LogMessageMonitor.cc,v 1.2 2012/03/29 17:20:14 tosi Exp $
00017 //
00018 //
00019 
00020 #include "DQM/TrackingMonitor/plugins/LogMessageMonitor.h"
00021 
00022 #include "DQMServices/Core/interface/DQMStore.h"
00023 #include "DQMServices/Core/interface/MonitorElement.h"
00024 #include "DataFormats/Common/interface/Handle.h"
00025 
00026 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
00027 #include "FWCore/MessageLogger/interface/ELstring.h"
00028 #include "FWCore/MessageLogger/interface/ErrorSummaryEntry.h"
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030 
00031 #include "DQM/TrackingMonitor/interface/GetLumi.h"
00032 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
00033 //
00034 // constants, enums and typedefs
00035 //
00036 
00037 //
00038 // static data member definitions
00039 //
00040 
00041 //
00042 // constructors and destructor
00043 //
00044 LogMessageMonitor::LogMessageMonitor(const edm::ParameterSet& iConfig)
00045   : dqmStore_( edm::Service<DQMStore>().operator->() )
00046   , conf_ ( iConfig )
00047   , modules_vector_  ( iConfig.getParameter<std::vector<std::string> >("modules")         )
00048   , doWarningsPlots_ ( iConfig.getParameter<bool>                     ("doWarningsPlots") )
00049 {
00050    //now do what ever initialization is needed
00051   lumiDetails_         = new GetLumi( iConfig.getParameter<edm::ParameterSet>("BXlumiSetup") ); 
00052   genTriggerEventFlag_ = new GenericTriggerEventFlag(iConfig);
00053 }
00054 
00055 
00056 LogMessageMonitor::~LogMessageMonitor()
00057 {
00058  
00059    // do anything here that needs to be done at desctruction time
00060    // (e.g. close files, deallocate resources etc.)
00061   //  if ( lumiDetails_         ) delete lumiDetails_;
00062   if ( genTriggerEventFlag_ ) delete genTriggerEventFlag_;
00063 
00064 }
00065 
00066 
00067 //
00068 // member functions
00069 //
00070 
00071 // ------------ method called for each event  ------------
00072 void
00073 LogMessageMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00074 {
00075 
00076   // Filter out events if Trigger Filtering is requested
00077   if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
00078 
00079   double BXlumi = lumiDetails_->getValue(iEvent);
00080   
00081   // Take the ErrorSummaryEntry container
00082   edm::Handle<std::vector<edm::ErrorSummaryEntry> >  errors;
00083   iEvent.getByLabel("logErrorHarvester",errors);
00084   // Check that errors is valid
00085   if(!errors.isValid()) return; 
00086   // Compare severity level of error with ELseveritylevel instance el : "-e" should be the lowest error
00087   edm::ELseverityLevel el("-e");
00088   
00089   // Find the total number of errors in iEvent
00090   if(errors->size()==0){
00091     for(size_t i = 0; i < modulesMap.size(); i++) {
00092       ModulesErrorsVsBXlumi[i] -> Fill(BXlumi,0.);
00093       if ( doWarningsPlots_ )
00094         ModulesWarningsVsBXlumi[i] -> Fill(BXlumi,0.);
00095     }
00096   } else {
00097     for( size_t i = 0, n = errors->size();
00098         i < n ; i++){    
00099       
00100       //      std::cout << "Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module  << std::endl;
00101       
00102       // remove the first part of the module string, what is before ":"
00103       std::string s = (*errors)[i].module;
00104       //      std::cout << "s: " << s << std::endl;
00105       size_t pos = s.find(':');
00106       std::string s_temp = s.substr(pos+1,s.size());
00107       std::map<std::string,int>::const_iterator it = modulesMap.find(s_temp);
00108       //      std::cout << "it: " << " --> " << s_temp << std::endl;
00109       if (it!=modulesMap.end()){
00110         // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
00111         if((*errors)[i].severity.getLevel() >= el.getLevel()){
00112           //      if (categoryECount.size()<=40)
00113           //        categoryECount[(*errors)[i].category]+=(*errors)[i].count;
00114           //       std::map<std::string,int>::const_iterator it = modulesMap.find((*errors)[i].category);
00115           //      std::cout << "it->second: " << it->second << std::endl;
00116           ModulesErrorsVsBXlumi[it->second]->Fill (BXlumi, (*errors)[i].count);
00117         } else {
00118           // IF ONLY WARNING, FILL WARNING HISTS
00119           if ( doWarningsPlots_ ) 
00120             ModulesWarningsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
00121         }
00122       }
00123     }
00124   }
00125 }
00126 
00127 
00128 // ------------ method called once each job just before starting event loop  ------------
00129 void 
00130 LogMessageMonitor::beginJob()
00131 {
00132    // MAKE MODULEMAP USING INPUT FROM CFG FILE
00133    for (size_t i = 0; i < modules_vector_.size(); i++){
00134      modulesMap.insert( std::pair<std::string,int>(modules_vector_[i],i) );
00135    }
00136 
00137    // BOOK THE HISTOGRAMS
00138    // get binning from the configuration
00139    edm::ParameterSet BXlumiParameters = conf_.getParameter<edm::ParameterSet>("BXlumiSetup");
00140    int    BXlumiBin   = BXlumiParameters.getParameter<int>("BXlumiBin");
00141    double BXlumiMin   = BXlumiParameters.getParameter<double>("BXlumiMin");
00142    double BXlumiMax   = BXlumiParameters.getParameter<double>("BXlumiMax");
00143 //   int    BXlumiBin   = conf_.getParameter<int>("BXlumiBin");
00144 //   double BXlumiMin   = conf_.getParameter<double>("BXlumiMin");
00145 //   double BXlumiMax   = conf_.getParameter<double>("BXlumiMax");
00146    
00147    std::string MEFolderName = conf_.getParameter<std::string>("LogFolderName"); 
00148 
00149    size_t i = 0;
00150    for(std::map<std::string,int>::const_iterator it = modulesMap.begin();
00151        it != modulesMap.end(); ++it, i++){ 
00152 
00153      dqmStore_->setCurrentFolder(MEFolderName + "/PUmonitoring/Errors");      
00154 
00155      histname = "errorsVsBXlumi_" + it->first;
00156      ModulesErrorsVsBXlumi.push_back( dynamic_cast<MonitorElement*>(dqmStore_->bookProfile( histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0.,100, "")) );
00157      ModulesErrorsVsBXlumi[i] -> setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
00158      ModulesErrorsVsBXlumi[i] -> setAxisTitle("Mean number of errors", 2);
00159      
00160      if ( doWarningsPlots_ ) {
00161        dqmStore_->setCurrentFolder(MEFolderName + "/PUmonitoring/Warnings");      
00162        
00163        histname = "warningVsBXlumi_" + it->first;
00164        ModulesWarningsVsBXlumi.push_back( dynamic_cast<MonitorElement*>(dqmStore_->bookProfile( histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0.,100, "")) );
00165        ModulesWarningsVsBXlumi[i] -> setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
00166        ModulesWarningsVsBXlumi[i] -> setAxisTitle("Mean number of warnings", 2);
00167      }
00168    }   
00169 }
00170 
00171 // ------------ method called once each job just after ending the event loop  ------------
00172 void 
00173 LogMessageMonitor::endJob() 
00174 {
00175     bool outputMEsInRootFile   = conf_.getParameter<bool>("OutputMEsInRootFile");
00176     std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00177     if(outputMEsInRootFile)
00178     {
00179         dqmStore_->showDirStructure();
00180         dqmStore_->save(outputFileName);
00181     }
00182 }
00183 
00184 // ------------ method called when starting to processes a run  ------------
00185 void 
00186 LogMessageMonitor::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00187 {
00188   if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( iRun, iSetup );
00189 }
00190 
00191 // ------------ method called when ending the processing of a run  ------------
00192 void 
00193 LogMessageMonitor::endRun(edm::Run const&, edm::EventSetup const&)
00194 {
00195 }
00196 
00197 // ------------ method called when starting to processes a luminosity block  ------------
00198 void 
00199 LogMessageMonitor::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00200 {
00201 }
00202 
00203 // ------------ method called when ending the processing of a luminosity block  ------------
00204 void 
00205 LogMessageMonitor::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00206 {
00207 }
00208 
00209 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00210 void
00211 LogMessageMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00212   //The following says we do not know what parameters are allowed so do no validation
00213   // Please change this to state exactly what you do use, even if it is no parameters
00214   edm::ParameterSetDescription desc;
00215   desc.setUnknown();
00216   descriptions.addDefault(desc);
00217 }
00218 
00219 //define this as a plug-in
00220 DEFINE_FWK_MODULE(LogMessageMonitor);