CMS 3D CMS Logo

DQMClientExample.cc

Go to the documentation of this file.
00001 
00002 /*
00003  * \file DQMClientExample.cc
00004  * \author M. Zanetti - CERN
00005  *
00006  * Last Update:
00007  * $Date: 2008/02/22 23:52:29 $
00008  * $Revision: 1.10 $
00009  * $Author: lat $
00010  *
00011  */
00012 
00013 #include "DQMServices/Examples/interface/DQMClientExample.h"
00014 
00015 #include "FWCore/ServiceRegistry/interface/Service.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 
00020 
00021 #include <TF1.h>
00022 #include <stdio.h>
00023 #include <sstream>
00024 #include <math.h>
00025 
00026 using namespace edm;
00027 using namespace std;
00028 
00029 DQMClientExample::DQMClientExample(const edm::ParameterSet& ps)
00030 {
00031   parameters_=ps;
00032   initialize();
00033 }
00034 
00035 DQMClientExample::~DQMClientExample(){
00036 }
00037 
00038 //--------------------------------------------------------
00039 void DQMClientExample::initialize(){ 
00040 
00041   counterLS_=0; 
00042   counterEvt_=0; 
00043   
00044   // get back-end interface
00045   dbe_ = Service<DQMStore>().operator->();
00046   
00047   // base folder for the contents of this job
00048   monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
00049   cout << "Monitor name = " << monitorName_ << endl;
00050   if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
00051 
00052   prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
00053   cout << "DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
00054   prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00055   cout << "DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
00056 
00057       
00058 }
00059 
00060 //--------------------------------------------------------
00061 void DQMClientExample::beginJob(const EventSetup& context){
00062 
00063   // get backendinterface  
00064   dbe_ = Service<DQMStore>().operator->();
00065 
00066   // do your thing
00067   dbe_->setCurrentFolder(monitorName_+"C1/Tests");
00068   clientHisto = dbe_->book1D("clientHisto", "Guassian fit results.", 2, 0, 1);
00069 }
00070 
00071 //--------------------------------------------------------
00072 void DQMClientExample::beginRun(const Run& r, const EventSetup& context) {
00073 }
00074 
00075 //--------------------------------------------------------
00076 void DQMClientExample::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00077    // optionally reset histograms here
00078    // clientHisto->Reset();
00079 }
00080 
00081 //--------------------------------------------------------
00082 void DQMClientExample::analyze(const Event& e, const EventSetup& context){
00083     
00084    counterEvt_++;
00085    if (prescaleEvt_<1) return;
00086    if (prescaleEvt_>0 && counterEvt_%prescaleEvt_ != 0) return;
00087 
00088 //    // endLuminosityBlock(); // FIXME call client here
00089 // 
00090 // }
00091 // 
00092 // 
00093 // //--------------------------------------------------------
00094 // void DQMClientExample::endLuminosityBlock(const LuminosityBlock& lumiSeg, 
00095 //                                           const EventSetup& context) {
00096 //                                        
00097 //   counterLS_++;
00098 //   if ( prescaleLS_>0 && counterLS_%prescaleLS_ != 0 ) return;
00099 //   // do your thing here
00100 //   
00101   
00102   string histoName = monitorName_ + "C1/C2/histo4";
00103 
00104   float mean =0;
00105   float rms = 0;
00106 
00107   MonitorElement * meHisto = dbe_->get(histoName);
00108 
00109   if (meHisto)
00110   {
00111     if (TH1F *rootHisto = meHisto->getTH1F())
00112     {
00113       TF1 *f1 = new TF1("f1","gaus",1,3);
00114       rootHisto->Fit("f1");
00115       mean = f1->GetParameter(1);
00116       rms = f1->GetParameter(2);
00117     }
00118   }
00119 
00120   clientHisto->setBinContent(1,mean);
00121   clientHisto->setBinContent(2,rms);
00122 
00123 
00124   string criterionName = parameters_.getUntrackedParameter<string>("QTestName","exampleQTest"); 
00125   const QReport * theQReport = clientHisto->getQReport(criterionName);
00126   if(theQReport) {
00127     vector<dqm::me_util::Channel> badChannels = theQReport->getBadChannels();
00128     for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00129          channel != badChannels.end(); channel++) {
00130       edm::LogError ("DQMClientExample") <<" Bad channels: "<<(*channel).getBin()<<" "<<(*channel).getContents();
00131     }
00132     edm::LogWarning ("DQMClientExample") <<"-------- "<<theQReport->getMessage()<<" ------- "<<theQReport->getStatus();
00133   } 
00134 
00135 }
00136 
00137 //--------------------------------------------------------
00138 void DQMClientExample::endRun(const Run& r, const EventSetup& context){
00139 }
00140 
00141 //--------------------------------------------------------
00142 void DQMClientExample::endJob(){
00143 }
00144 
00145 
00146 
00147 

Generated on Tue Jun 9 17:34:15 2009 for CMSSW by  doxygen 1.5.4