CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/DQMServices/Components/src/DQMMessageLoggerClient.cc

Go to the documentation of this file.
00001 #include "DQMServices/Components/src/DQMMessageLoggerClient.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include <string>
00004 #include <vector>
00005 
00006 
00007 using namespace std;
00008 using namespace edm;
00009 
00010 
00011 // -----------------------------
00012 //  constructors and destructor
00013 // -----------------------------
00014 
00015 DQMMessageLoggerClient::DQMMessageLoggerClient( const edm::ParameterSet& ps ) {
00016 
00017   parameters = ps;
00018   theDbe = NULL;
00019   modulesErrorsFound = NULL;
00020   modulesWarningsFound = NULL;
00021   categoriesWarningsFound = NULL;
00022   categoriesErrorsFound = NULL;
00023   directoryName = parameters.getParameter<string>("Directory");
00024 
00025 }
00026 
00027 
00028 DQMMessageLoggerClient::~DQMMessageLoggerClient() {
00029 
00030 }
00031 
00032 
00033 
00034 void DQMMessageLoggerClient::beginJob() {
00035 
00036   //LogTrace(metname)<<"[DQMMessageLoggerClient] Parameters initialization";
00037   theDbe = Service<DQMStore>().operator->();
00038 
00039   if(theDbe!=NULL){   
00040     theDbe->setCurrentFolder(directoryName);
00041   }
00042 
00043 }
00044 
00045 void DQMMessageLoggerClient::beginRun(const edm::Run& r, const edm::EventSetup& es){
00046 }
00047 
00048 
00049 
00050 void DQMMessageLoggerClient::analyze(const edm::Event& e, const edm::EventSetup& context)  {
00051 }
00052 
00053 void DQMMessageLoggerClient::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const EventSetup& es){
00054 }
00055 
00056 void DQMMessageLoggerClient::endLuminosityBlock(const edm::LuminosityBlock&  lumiBlock, const  edm::EventSetup& context){
00057 }
00058 
00059 void DQMMessageLoggerClient::fillHistograms(){
00060 
00061 
00062   // directoryName should be the same as for DQMMessageLogger
00063   //theDbe->setCurrentFolder(directoryName);
00064   /*
00065   cout << theDbe->pwd() << endl;
00066   vector<string> vec = theDbe->getSubdirs();
00067   for(int i=0; i<vec.size(); i++){
00068     cout << vec[i] << endl;
00069   }
00070   */
00071   theDbe->goUp();
00072 
00073 
00074 
00075   vector<string> entries;
00076   entries.push_back(directoryName + "/Warnings/modules_warnings");
00077   entries.push_back(directoryName + "/Errors/modules_errors");
00078   entries.push_back(directoryName + "/Warnings/categories_warnings");
00079   entries.push_back(directoryName + "/Errors/categories_errors");
00080   
00081   
00082   int mel = 0;
00083   
00084   for(vector<string>::const_iterator ent = entries.begin();
00085                                       ent != entries.end(); ++ent) {
00086     mel++;
00087     //RESET VECTORS
00088     binContent.clear();
00089     binLabel.clear();
00090     
00091 
00092     // RETURN ME
00093     
00094    
00095    MonitorElement *me = theDbe->get(*ent);
00096     // GET TH1F
00097    if(theDbe->get(*ent)){
00098     if (TH1 *rootHisto = me->getTH1()) {
00099       int nonzeros  = 0;
00100       int Nbins = me->getNbinsX();
00101       
00102       
00103       // LOOP OVER TH1F
00104       for(int bin = 1; bin <= Nbins ; ++bin) {
00105         if( rootHisto->GetBinContent(bin)>0){ 
00106           nonzeros++;
00107           binContent.push_back(rootHisto->GetBinContent(bin));
00108           binLabel.push_back(rootHisto->GetXaxis()->GetBinLabel(bin));
00109         }
00110         
00111       }
00112       
00113       switch(mel){
00114       case 1:
00115         theDbe->setCurrentFolder(directoryName + "/Warnings");
00116         modulesWarningsFound = theDbe->get(directoryName + "/Warnings/modulesWarningsFound");
00117         if (modulesWarningsFound) theDbe->removeElement(modulesWarningsFound->getName());
00118         if(nonzeros>0){
00119           modulesWarningsFound = theDbe->book1D("modulesWarningsFound", "Warnings per module", binContent.size(), 0, binContent.size());
00120         }else{
00121           modulesWarningsFound = theDbe->book1D("modulesWarningsFound", "Warnings per module", 1, 0, 1);
00122           modulesWarningsFound->setBinLabel(1,"Module name");
00123         }
00124         for (int i=0; i<nonzeros; ++i){
00125           if(modulesWarningsFound!=NULL){
00126             //gPad->SetBottomMargin(2);
00127             //cout << binContent[i] <<" "<<binLabel[i] << endl;
00128             modulesWarningsFound->setBinContent(i+1,binContent[i]);
00129             modulesWarningsFound->setBinLabel(i+1,binLabel[i]);
00130           }
00131         }
00132         if(nonzeros>4) modulesWarningsFound->getTH1()->GetXaxis()->LabelsOption("v");
00133         break;
00134       case 2:
00135         theDbe->setCurrentFolder(directoryName + "/Errors");
00136         modulesErrorsFound = theDbe->get(directoryName + "/Errors/modulesErrorsFound");
00137         if (modulesErrorsFound) theDbe->removeElement(modulesErrorsFound->getName());
00138         if(nonzeros>0){
00139           modulesErrorsFound = theDbe->book1D("modulesErrorsFound", "Errors per module",binContent.size(), 0, binContent.size() );
00140         }else{
00141           modulesErrorsFound = theDbe->book1D("modulesErrorsFound", "Errors per module",1, 0, 1 );
00142           modulesErrorsFound->setBinLabel(1,"Module name");
00143         }
00144         for (int i=0; i<nonzeros; ++i){
00145           if(modulesErrorsFound!=NULL){
00146             //gPad->SetBottomMargin(2);
00147             modulesErrorsFound->setBinContent(i+1,binContent[i]);
00148             modulesErrorsFound->setBinLabel(i+1,binLabel[i]);
00149           }
00150         }
00151         if(nonzeros>4) modulesErrorsFound->getTH1()->GetXaxis()->LabelsOption("v");
00152         break;
00153       case 3:
00154         theDbe->setCurrentFolder(directoryName + "/Warnings");
00155         categoriesWarningsFound = theDbe->get(directoryName + "/Warnings/categoriesWarningsFound");
00156         if (categoriesWarningsFound) theDbe->removeElement(categoriesWarningsFound->getName());
00157         if(nonzeros>0){
00158           categoriesWarningsFound = theDbe->book1D("categoriesWarningsFound", "Warnings per category", binContent.size(),0,binContent.size());
00159         } else{
00160           categoriesWarningsFound = theDbe->book1D("categoriesWarningsFound", "Warnings per category", 1,0,1);
00161           categoriesWarningsFound->setBinLabel(1,"Category name");
00162         }
00163         for (int i=0; i<nonzeros; ++i){
00164           if(categoriesWarningsFound!=NULL){
00165             //gPad->SetBottomMargin(2);
00166             //cout << binContent[i] <<" " <<binLabel[i] << endl;
00167             categoriesWarningsFound->setBinContent(i+1,binContent[i]);
00168             categoriesWarningsFound->setBinLabel(i+1,binLabel[i]);
00169           }
00170         }
00171         if(nonzeros>4) categoriesWarningsFound->getTH1()->GetXaxis()->LabelsOption("v");
00172         break;
00173       case 4:
00174         theDbe->setCurrentFolder(directoryName + "/Errors");
00175         categoriesErrorsFound = theDbe->get(directoryName + "/Errors/categoriesErrorsFound");
00176         if (categoriesErrorsFound) theDbe->removeElement(categoriesErrorsFound->getName());
00177         if(nonzeros>0){
00178           categoriesErrorsFound = theDbe->book1D("categoriesErrorsFound", "Errors per category", binContent.size(),0,binContent.size());
00179         }else{
00180           categoriesErrorsFound = theDbe->book1D("categoriesErrorsFound", "Errors per category", 1,0,1);
00181           categoriesErrorsFound->setBinLabel(1,"Category name");
00182         }
00183         for (int i=0; i<nonzeros; ++i){
00184           if(categoriesErrorsFound!=NULL){
00185             //gPad->SetBottomMargin(2);
00186             categoriesErrorsFound->setBinContent(i+1,binContent[i]);
00187             categoriesErrorsFound->setBinLabel(i+1,binLabel[i]);
00188           }
00189         }
00190         if(nonzeros>4) categoriesErrorsFound->getTH1()->GetXaxis()->LabelsOption("v");
00191         break;
00192       }
00193       
00194     }
00195    }
00196   }
00197 }
00198 
00199 
00200 
00201 void DQMMessageLoggerClient::endRun(const Run& r, const EventSetup& es){
00202   fillHistograms();
00203 }
00204 
00205 
00206 void DQMMessageLoggerClient::endJob() {
00207   
00208   //LogTrace(metname)<<"[DQMMessageLoggerClient] EndJob";
00209 }