CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMClientExample.cc
Go to the documentation of this file.
1 /*
2  * \file DQMClientExample.cc
3  * \author M. Zanetti - CERN
4  *
5  * Last Update:
6  * $Date: 2009/10/13 18:20:26 $
7  * $Revision: 1.15 $
8  * $Author: ameyer $
9  *
10  */
11 
12 
13 /* Description: Simple example showing how to access the histograms
14  * already defined and filled by the DQM producer(source)
15  * and how to access the quality test results.
16  */
17 
18 /* Jan 17, 2009: the code has been modified significantly
19  * to steer the client operations
20  * Author: D.Volyanskyy
21  */
22 
23 
28 
29 #include <TF1.h>
30 #include <stdio.h>
31 #include <sstream>
32 #include <math.h>
33 
34 using namespace edm;
35 using namespace std;
36 
37 //==================================================================//
38 //================= Constructor and Destructor =====================//
39 //==================================================================//
41 {
42  parameters_=ps;
43  initialize();
44 }
45 
47 }
48 
49 //==================================================================//
50 //======================= Initialise ===============================//
51 //==================================================================//
53 
55  counterEvt_=0; counterLS_ = 0;
56  counterClientOperation = 0;
57 
60 
62  monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
63  cout << "DQMClientExample: Monitor name = " << monitorName_ << endl;
64  if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
65 
67  prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
68  cout << "DQMClientExample: DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
69  prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
70  cout << "DQMClientExample: DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
71 
72  //-- QTestName that is going to bu run on clienHisto, as defined in XML file
73  QTestName_ = parameters_.getUntrackedParameter<string>("QTestName","exampleQTest");
74  cout << "DQMClientExample: QTest name to be ran on clientHisto = " << QTestName_ << endl;
75  //-- define where to run the Client
76  clientOnEachEvent = parameters_.getUntrackedParameter<bool>("clientOnEachEvent",false);
77  if(clientOnEachEvent) cout << "DQMClientExample: run Client on each event" << endl;
78  clientOnEndLumi = parameters_.getUntrackedParameter<bool>("clientOnEndLumi",true);
79  if(clientOnEndLumi) cout << "DQMClientExample: run Client at the end of each lumi section" << endl;
80  clientOnEndRun = parameters_.getUntrackedParameter<bool>("clientOnEndRun",false);
81  if(clientOnEndRun) cout << "DQMClientExample: run Client at the end of each run" << endl;
82  clientOnEndJob = parameters_.getUntrackedParameter<bool>("clientOnEndJob",false);
83  if(clientOnEndJob) cout << "DQMClientExample: run Client at the end of the job" << endl;
84 
85 }
86 //==================================================================//
87 //========================= beginJob ===============================//
88 //==================================================================//
90 
93 
95  dbe_->setCurrentFolder(monitorName_+"DQMclient");
96  clientHisto = dbe_->book1D("clientHisto", "Guassian fit results.", 2, 0, 1);
97 }
98 
99 //==================================================================//
100 //========================= beginRun ===============================//
101 //==================================================================//
102 void DQMClientExample::beginRun(const Run& r, const EventSetup& context) {
103 }
104 
105 //==================================================================//
106 //==================== beginLuminosityBlock ========================//
107 //==================================================================//
109  // optionally reset histograms here
110  // clientHisto->Reset();
111 }
112 
113 //==================================================================//
114 //==================== analyse (takes each event) ==================//
115 //==================================================================//
116 void DQMClientExample::analyze(const Event& e, const EventSetup& context){
117  counterEvt_++;
118  if(clientOnEachEvent){
119  if (prescaleEvt_>0 && counterEvt_ % prescaleEvt_ == 0) performClient();
120  }
121 }
122 
123 //==================================================================//
124 //========================= endLuminosityBlock =====================//
125 //==================================================================//
127  counterLS_ ++;
128  if(!clientOnEachEvent && clientOnEndLumi){
129  if( prescaleLS_ > 0 && counterLS_ % prescaleLS_ == 0) performClient();
130  }
131 }
132 //==================================================================//
133 //============================= endRun =============================//
134 //==================================================================//
135 void DQMClientExample::endRun(const Run& r, const EventSetup& context){
136  if(clientOnEndRun) performClient();
137 }
138 
139 //==================================================================//
140 //============================= endJob =============================//
141 //==================================================================//
143  std::cout << "DQMSourceClient::endJob()" << std::endl;
144  if(clientOnEndJob) performClient();
145 }
146 
147 
148 //==================================================================//
149 //======================= performClient ============================//
150 //==================================================================//
152 
153  std::cout << "***** run Client operations as defined in: *****" << std::endl;
154  std::cout << "***** DQMClientExample::performClient ********" << std::endl;
155 
156  //----------------------------------------------------------------------------------------------
157  // example how to retrieve a ME created by the DQM producer (in Examples/src/DQMSourceExample.cc)
158  //---------------------------------------------------------------------------------------------
159  float mean =0; float rms = 0;
160 
162  string histoName = monitorName_ + "DQMsource/C1/histo2";
163  MonitorElement * meHisto = dbe_->get(histoName);
165  if (meHisto) {
167  if (TH1F *rootHisto = meHisto->getTH1F()) {
168  if(counterClientOperation<1)
169  std::cout<<"=== DQMClientExample::performClient => the histo is found: entries="<< rootHisto->GetEntries() << "\n"
170  <<" mean=" << rootHisto->GetMean() << " rms=" << rootHisto->GetRMS() << std::endl;
171 
173  TF1 *f1 = new TF1("f1","gaus",1,3);
174  rootHisto->Fit("f1");
175  mean = f1->GetParameter(1);
176  rms = f1->GetParameter(2);
177  }
178  clientHisto->setBinContent(1,mean);
179  clientHisto->setBinContent(2,rms);
180  }
181 
182  else { //when it is not found !
183  clientHisto->setBinContent(1,-1);
184  clientHisto->setBinContent(2,-1);
185  if(counterClientOperation<1) edm::LogError ("DQMClientExample") <<"--- The following ME :"<< histoName <<" cannot be found\n"
186  <<"--- on the DQM source side !\n";
187  }
188 
189  //----------------------------------------------------------------------------------------------
190  // example how to access the Quality test result for clientHisto
191  //---------------------------------------------------------------------------------------------
192 
193  // qtest to be ran on clientHisto is defined in Examples/test/QualityTests.xml
194  const QReport * theQReport = clientHisto->getQReport(QTestName_);
195  if(theQReport) {
196  if(counterClientOperation<1)
197  edm::LogWarning ("DQMClientExample") <<"*** Summary of Quality Test for clientHisto: \n"
198  //<<"--- value ="<< theQReport->getQTresult()<<"\n"
199  <<"--- status ="<< theQReport->getStatus() << "\n"
200  <<"--- message ="<< theQReport->getMessage() << "\n";
201 
202  vector<dqm::me_util::Channel> badChannels = theQReport->getBadChannels();
203  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
204  channel != badChannels.end(); channel++) {
205  if(counterClientOperation<1)
206  edm::LogError ("DQMClientExample") <<" Bad channels: "<<(*channel).getBin()<<" "<<(*channel).getContents();
207  }
208  }
209  else {
210  if(counterClientOperation<1) edm::LogError ("DQMClientExample") <<"--- No QReport is found for clientHisto!\n"
211  << "--- Please check your XML and config files -> QTestName ( " << QTestName_ << " )must be the same!\n";
212  }
213 
214  counterClientOperation++;
215 }
216 
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:519
const std::string & getMessage(void) const
get message attached to test
Definition: QReport.h:24
virtual ~DQMClientExample()
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
int getStatus(void) const
get test status (see Core/interface/QTestStatus.h)
Definition: QReport.h:16
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1270
const std::vector< DQMChannel > & getBadChannels(void) const
Definition: QReport.h:33
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
DQMStore * dbe_
void beginRun(const edm::Run &r, const edm::EventSetup &c)
DQMClientExample(const edm::ParameterSet &ps)
TH1F * getTH1F(void) const
void endRun(const edm::Run &r, const edm::EventSetup &c)
tuple cout
Definition: gather_cfg.py:41
void analyze(const edm::Event &e, const edm::EventSetup &c)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237
Definition: Run.h:31