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
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
00047 categories_vector = parameters.getParameter< vector<string> >("Categories");
00048 directoryName = parameters.getParameter<string>("Directory");
00049
00050 }
00051
00052 DQMMessageLogger::~DQMMessageLogger() {
00053
00054 }
00055
00056
00057 void DQMMessageLogger::beginJob() {
00058
00059 metname = "errorAnalyzer";
00060
00061
00062
00063
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
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
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
00126 int nbins = 10;
00127 total_warnings = theDbe->book1D("total warnings","Total warnings per event",nbins,0,nbins);
00128 theDbe->setCurrentFolder(directoryName + "/Errors");
00129 total_errors = theDbe->book1D("total_errors", "Total errors per event", nbins, 0, nbins);
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
00148 Handle<std::vector<edm::ErrorSummaryEntry> > errors;
00149 iEvent.getByLabel("logErrorHarvester",errors);
00150
00151 if(!errors.isValid()){ return; }
00152
00153 ELseverityLevel el("-e");
00154
00155
00156
00157
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
00190
00191 if(errors->size()>0){
00192
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
00198 categories_errors->Fill((*it).second - 1, (*errors)[i].count);
00199 }
00200 }
00201
00202 if(modules_errors!=NULL){
00203
00204 string s = (*errors)[i].module;
00205 size_t pos = s.find(':');
00206 string s_temp = s.substr(pos+1,s.size());
00207 map<string,int>::const_iterator it = moduleMap.find(s_temp);
00208 if(it!=moduleMap.end()){
00209
00210 modules_errors->Fill((*it).second - 1, (*errors)[i].count);
00211 }
00212 }
00213
00214 }else{
00215 if(categories_warnings!=NULL){
00216 map<string,int>::const_iterator it = categoryMap.find((*errors)[i].category);
00217 if (it!=categoryMap.end()){
00218
00219 categories_warnings->Fill((*it).second - 1, (*errors)[i].count);
00220 }
00221 }
00222
00223 if(modules_warnings!=NULL){
00224
00225 string s = (*errors)[i].module;
00226 size_t pos = s.find(':');
00227 string s_temp = s.substr(pos+1,s.size());
00228 map<string,int>::const_iterator it = moduleMap.find(s_temp);
00229 if(it!=moduleMap.end()){
00230
00231 modules_warnings->Fill((*it).second - 1, (*errors)[i].count);
00232 }
00233 }
00234 }
00235 }
00236 }
00237 }
00238
00239
00240 void DQMMessageLogger::endJob(void) {
00241 LogTrace(metname)<<"[DQMMessageLogger] EndJob";
00242
00243 }
00244
00245
00246
00247