CMS 3D CMS Logo

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