CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQMServices/Components/src/DQMMessageLogger.cc

Go to the documentation of this file.
00001 
00002 
00003 #include "DQMServices/Components/src/DQMMessageLogger.h"
00004 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
00005 #include "FWCore/MessageLogger/interface/ELstring.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "FWCore/MessageLogger/interface/ErrorSummaryEntry.h"
00014 #include "DataFormats/FWLite/interface/Event.h"
00015 #include "FWCore/Framework/interface/Frameworkfwd.h"
00016 #include "FWCore/Framework/interface/EDAnalyzer.h"
00017 #include "FWCore/Framework/interface/MakerMacros.h"
00018 #include "FWCore/Framework/interface/TriggerNamesService.h"
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "FWCore/ServiceRegistry/interface/Service.h"
00021 #include "FWCore/Utilities/interface/Algorithms.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/ParameterSet/interface/Registry.h"
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 #include "DataFormats/FWLite/interface/Handle.h"
00026 #include "TPad.h"
00027 #include <cmath>
00028 
00029 using namespace std;
00030 using namespace edm;
00031 
00032 
00033 
00034 DQMMessageLogger::DQMMessageLogger(const ParameterSet& parameters) {
00035 
00036   // the services
00037   theDbe = NULL;
00038   
00039   categories_errors = NULL;
00040   categories_warnings = NULL;
00041   modules_errors = NULL;
00042   modules_warnings = NULL;
00043   total_errors = NULL;  
00044   total_warnings = NULL;
00045 
00046   //Get from cfg file
00047   categories_vector = parameters.getParameter< vector<string> >("Categories");
00048   directoryName = parameters.getParameter<string>("Directory");
00049   
00050 }
00051 
00052 DQMMessageLogger::~DQMMessageLogger() { 
00053   // Should the pointers be deleted?
00054 }
00055 
00056 
00057 void DQMMessageLogger::beginJob() {
00058    
00059   metname = "errorAnalyzer";
00060 
00061 
00062 
00063   // MAKE CATEGORYMAP USING INPUT FROM CFG FILE
00064   for(unsigned int i=0; i<categories_vector.size(); i++){
00065     categoryMap.insert(pair<string,int>(categories_vector[i],i+1));
00066   }
00067   
00068  
00069   // MAKE MODULEMAP
00070   typedef Service<edm::service::TriggerNamesService>  TNS;
00071   typedef vector<std::string> stringvec;
00072   TNS tns;
00073   stringvec const& trigpaths = tns->getTrigPaths();
00074   
00075   
00076   for (stringvec::const_iterator i = trigpaths.begin(), e =trigpaths.end() ;  i != e;  ++i){
00077       stringvec strings =  tns->getTrigPathModules(*i);
00078 
00079       for(unsigned int k=0; k<strings.size(); ++k){      
00080         moduleMap.insert(pair<string,int>(strings[k],moduleMap.size()+1));
00081       }    
00082   }
00083 
00084   // BOOK THE HISTOGRAMS
00085   LogTrace(metname)<<"[DQMMessageLogger] Parameters initialization";
00086   theDbe = Service<DQMStore>().operator->();
00087   if(theDbe!=NULL){
00088     
00089     
00090 
00091     if(moduleMap.size()!=0){
00092       theDbe->setCurrentFolder(directoryName + "/Errors"); 
00093       modules_errors = theDbe->book1D("modules_errors", "Errors per module", moduleMap.size(), 0, moduleMap.size()); 
00094       theDbe->setCurrentFolder(directoryName + "/Warnings"); 
00095       
00096       modules_warnings = theDbe->book1D("modules_warnings","Warnings per module",moduleMap.size(),0,moduleMap.size());
00097       
00098       for(map<string,int>::const_iterator it = moduleMap.begin(); it!=moduleMap.end();++it){ 
00099         modules_errors->setBinLabel((*it).second,(*it).first);
00100         modules_warnings->setBinLabel((*it).second,(*it).first);
00101       }
00102       modules_errors->getTH1()->GetXaxis()->LabelsOption("v");
00103       modules_warnings->getTH1()->GetXaxis()->LabelsOption("v");
00104       
00105       
00106       
00107       
00108     }
00109     
00110     if(categoryMap.size()!=0){
00111       theDbe->setCurrentFolder(directoryName + "/Errors"); 
00112       categories_errors = theDbe->book1D("categories_errors", "Errors per category", categoryMap.size(), 0, categoryMap.size());
00113       theDbe->setCurrentFolder(directoryName +"/Warnings"); 
00114       categories_warnings = theDbe->book1D("categories_warnings", "Warnings per category", categoryMap.size(), 0, categoryMap.size());
00115       
00116       
00117       for(map<string,int>::const_iterator it = categoryMap.begin(); it!=categoryMap.end();++it){
00118         categories_errors->setBinLabel((*it).second,(*it).first);
00119         categories_warnings->setBinLabel((*it).second,(*it).first);
00120       }
00121       categories_warnings->getTH1()->GetXaxis()->LabelsOption("v");
00122       categories_errors->getTH1()->GetXaxis()->LabelsOption("v");
00123     }
00124 
00125     // HOW MANY BINS SHOULD THE ERROR HIST HAVE?
00126     int nbins = 11;
00127     total_warnings = theDbe->book1D("total_warnings","Total warnings per event",nbins,-0.5,nbins+0.5);
00128     theDbe->setCurrentFolder(directoryName + "/Errors"); 
00129     total_errors = theDbe->book1D("total_errors", "Total errors per event", nbins, -0.5, nbins+0.5);
00130     
00131     for(int i=0; i<nbins; ++i){
00132       stringstream out;
00133       out<< i;
00134       string s = out.str();
00135       total_errors->setBinLabel(i+1,s);
00136       total_warnings->setBinLabel(i+1,s);
00137     }
00138   }
00139 }
00140 
00141 
00142 void DQMMessageLogger::analyze(const Event& iEvent, const EventSetup& iSetup) {
00143 
00144   LogTrace(metname)<<"[DQMMessageLogger] Analysis of event # ";
00145 
00146   
00147   // Take the ErrorSummaryEntry container
00148   Handle<std::vector<edm::ErrorSummaryEntry> >  errors;
00149   iEvent.getByLabel("logErrorHarvester",errors);
00150   // Check that errors is valid
00151   if(!errors.isValid()){   return; }
00152   // Compare severity level of error with ELseveritylevel instance el : "-e" should be the lowest error
00153   ELseverityLevel el("-e");
00154 
00155   
00156 
00157   // Find the total number of errors in iEvent
00158   if(errors->size()==0){
00159     if(total_errors!=NULL){
00160       total_errors->Fill(0);
00161     }
00162     if(total_warnings!=NULL){
00163       total_warnings->Fill(0);
00164     }
00165   }else{
00166     
00167     int e = 0;
00168     int w = 0;
00169     for (int i=0, n=errors->size(); i<n; i++){
00170       if((*errors)[i].severity.getLevel() < el.getLevel()){
00171         w+= (*errors)[i].count;
00172       }else{
00173         e+= (*errors)[i].count;
00174       }
00175     }
00176     if(total_errors!=NULL){
00177       total_errors->Fill(e);
00178     }    
00179     if(total_warnings!=NULL){
00180       total_warnings->Fill(w);
00181     }
00182   }
00183 
00184   
00185   
00186   
00187   for(int i=0, n=errors->size(); i< n ; i++){    
00188     
00189     //cout << "Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module  << endl;
00190 
00191     if(errors->size()>0){
00192       // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
00193       if((*errors)[i].severity.getLevel() >= el.getLevel()){
00194         if(categories_errors!=NULL){
00195           map<string,int>::const_iterator it = categoryMap.find((*errors)[i].category);
00196           if (it!=categoryMap.end()){
00197             // FILL THE RIGHT BIN
00198             categories_errors->Fill((*it).second - 1, (*errors)[i].count);
00199           }
00200         }
00201         //      if (categoryECount.size()<=40)
00202         //        categoryECount[(*errors)[i].category]+=(*errors)[i].count;
00203 
00204         if(modules_errors!=NULL){
00205           // remove the first part of the module string, what is before ":"
00206           string s = (*errors)[i].module;
00207           size_t pos = s.find(':');
00208           string s_temp = s.substr(pos+1,s.size());
00209           map<string,int>::const_iterator it = moduleMap.find(s_temp);
00210           if(it!=moduleMap.end()){
00211             // FILL THE RIGHT BIN
00212             modules_errors->Fill((*it).second - 1, (*errors)[i].count);
00213           }
00214         }
00215         // IF ONLY WARNING, FILL WARNING HISTS
00216       }else{
00217         if(categories_warnings!=NULL){
00218           map<string,int>::const_iterator it = categoryMap.find((*errors)[i].category);
00219           if (it!=categoryMap.end()){
00220             // FILL THE RIGHT BIN
00221             categories_warnings->Fill((*it).second - 1, (*errors)[i].count);
00222           }
00223         }
00224 
00225         //      if (categoryWCount.size()<=40)
00226         //        categoryWCount[(*errors)[i].category]+=(*errors)[i].count;
00227         
00228         if(modules_warnings!=NULL){
00229           // remove the first part of the module string, what is before ":"
00230           string s = (*errors)[i].module;
00231           size_t pos = s.find(':');
00232           string s_temp = s.substr(pos+1,s.size());
00233           map<string,int>::const_iterator it = moduleMap.find(s_temp);
00234           if(it!=moduleMap.end()){
00235             // FILL THE RIGHT BIN
00236             modules_warnings->Fill((*it).second - 1, (*errors)[i].count);
00237           }
00238         }
00239       }
00240     }
00241   }
00242 }
00243 
00244 void DQMMessageLogger::endRun(const edm::Run & , const edm::EventSetup & ){
00245   /*
00246   theDbe = Service<DQMStore>().operator->();
00247   if(theDbe!=NULL){
00248     std::map<std::string,int>::iterator it;
00249     uint i=0;
00250     theDbe->setCurrentFolder(directoryName + "/Errors");
00251     if (categoryECount.empty()){
00252       MonitorElement * catECount = theDbe->book1D("categoryCount_errors","Errors per Category",1,0,1);
00253       catECount->setBinLabel(1,"No Errors");
00254     }else{
00255       MonitorElement * catECount = theDbe->book1D("categoryCount_errors","Errors per Category",categoryECount.size(),0,categoryECount.size());
00256       for (i=1,it=categoryECount.begin();it!=categoryECount.end();++it,++i){
00257         catECount->setBinLabel(i,it->first);
00258         catECount->setBinContent(i,it->second);
00259       }
00260     }
00261     theDbe->setCurrentFolder(directoryName + "/Warnings");
00262     if (categoryWCount.empty()){
00263       MonitorElement * catWCount = theDbe->book1D("categoryCount_warnings","Warnings per Category",categoryWCount.size(),0,categoryWCount.size());
00264       catWCount->setBinLabel(1,"No Warnings");
00265     }else{
00266       MonitorElement * catWCount = theDbe->book1D("categoryCount_warnings","Warnings per Category",categoryWCount.size(),0,categoryWCount.size());
00267       for (i=1,it=categoryWCount.begin();it!=categoryWCount.end();++it,++i){
00268         catWCount->setBinLabel(i,it->first);
00269         catWCount->setBinContent(i,it->second);
00270       }
00271     }
00272   }
00273   categoryWCount.clear();
00274   categoryECount.clear();
00275   */
00276 }
00277 
00278 void DQMMessageLogger::endJob(void) {
00279   LogTrace(metname)<<"[DQMMessageLogger] EndJob";
00280   
00281 }
00282 
00283 
00284 
00285