CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelEDAClient.cc
Go to the documentation of this file.
2 
3 // Framework
10 
19 
22 
28 
31 
37 
38 #include "xgi/Method.h"
39 #include "xgi/Utils.h"
40 
41 #include "cgicc/Cgicc.h"
42 #include "cgicc/FormEntry.h"
43 #include "cgicc/HTMLClasses.h"
44 
45 #include <iostream>
46 #include <iomanip>
47 #include <stdio.h>
48 #include <string>
49 #include <sstream>
50 #include <math.h>
51 
52 #define BUF_SIZE 256
53 
54 using namespace edm;
55 using namespace std;
56 //
57 // -- Constructor
58 //
60  ModuleWeb("SiPixelEDAClient"){
61 // cout<<"Entering SiPixelEDAClient::SiPixelEDAClient: "<<endl;
62 
63  edm::LogInfo("SiPixelEDAClient") << " Creating SiPixelEDAClient " << "\n" ;
64 
66 
67  summaryFrequency_ = ps.getUntrackedParameter<int>("SummaryCreationFrequency",20);
68  tkMapFrequency_ = ps.getUntrackedParameter<int>("TkMapCreationFrequency",50);
69  staticUpdateFrequency_ = ps.getUntrackedParameter<int>("StaticUpdateFrequency",10);
70  actionOnLumiSec_ = ps.getUntrackedParameter<bool>("ActionOnLumiSection",false); //client
71  actionOnRunEnd_ = ps.getUntrackedParameter<bool>("ActionOnRunEnd",true); //client
72  evtOffsetForInit_ = ps.getUntrackedParameter<int>("EventOffsetForInit",10); //client
73  offlineXMLfile_ = ps.getUntrackedParameter<bool>("UseOfflineXMLFile",false); //client
74  hiRes_ = ps.getUntrackedParameter<bool>("HighResolutionOccupancy",false); //client
75  noiseRate_ = ps.getUntrackedParameter<double>("NoiseRateCutValue",0.001); //client
76  noiseRateDenominator_ = ps.getUntrackedParameter<int>("NEventsForNoiseCalculation",100000); //client
77  Tier0Flag_ = ps.getUntrackedParameter<bool>("Tier0Flag",false); //client
78  doHitEfficiency_ = ps.getUntrackedParameter<bool>("DoHitEfficiency",true); //client
79  inputSource_ = ps.getUntrackedParameter<string>("inputSource", "source");
80 
81  if(!Tier0Flag_){
82  string localPath = string("DQM/SiPixelMonitorClient/test/loader.html");
83  ifstream fin(edm::FileInPath(localPath).fullPath().c_str(), ios::in);
84  char buf[BUF_SIZE];
85 
86  if (!fin) {
87  cerr << "Input File: loader.html"<< " could not be opened!" << endl;
88  return;
89  }
90 
91  while (fin.getline(buf, BUF_SIZE, '\n')) { // pops off the newline character
92  html_out_ << buf ;
93  }
94  fin.close();
95 
96  }
97 
98  // instantiate web interface
99  sipixelWebInterface_ = new SiPixelWebInterface(bei_,offlineXMLfile_,Tier0Flag_);
100  //instantiate the three work horses of the client:
102  sipixelActionExecutor_ = new SiPixelActionExecutor(offlineXMLfile_, Tier0Flag_);
103  sipixelDataQuality_ = new SiPixelDataQuality(offlineXMLfile_);
104 
105 // cout<<"...leaving SiPixelEDAClient::SiPixelEDAClient. "<<endl;
106 }
107 //
108 // -- Destructor
109 //
111 // cout<<"Entering SiPixelEDAClient::~SiPixelEDAClient: "<<endl;
112 
113  edm::LogInfo("SiPixelEDAClient") << " Deleting SiPixelEDAClient " << "\n" ;
114  if (sipixelWebInterface_) {
115  delete sipixelWebInterface_;
117  }
121  }
123  delete sipixelActionExecutor_;
125  }
126  if (sipixelDataQuality_) {
127  delete sipixelDataQuality_;
129  }
130 
131 // cout<<"...leaving SiPixelEDAClient::~SiPixelEDAClient. "<<endl;
132 }
133 //
134 // -- Begin Job
135 //
137  firstRun = true;
138 }
139 //
140 // -- Begin Run
141 //
142 void SiPixelEDAClient::beginRun(Run const& run, edm::EventSetup const& eSetup) {
143  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Begining of Run";
144 // cout<<"Entering SiPixelEDAClient::beginRun: "<<endl;
145 
146  if(firstRun){
147 
148  // Read the summary configuration file
150  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Error to read configuration file!! Summary will not be produced!!!";
151  summaryFrequency_ = -1;
152  tkMapFrequency_ = -1;
153  actionOnLumiSec_ = false;
154  actionOnRunEnd_ = true;
155  evtOffsetForInit_ = -1;
156  }
157  nLumiSecs_ = 0;
158  nEvents_ = 0;
159  if(Tier0Flag_) nFEDs_ = 40;
160  else nFEDs_ = 0;
161 
162  bei_->setCurrentFolder("Pixel/");
163  // Setting up QTests:
164 // sipixelActionExecutor_->setupQTests(bei_);
165  // Creating Summary Histos:
167  // Booking Deviation Histos:
169  // Booking Efficiency Histos:
171  // Creating occupancy plots:
173  // Booking noisy pixel ME's:
175  // Booking summary report ME's:
177  // Booking Static Tracker Maps:
178 // sipixelActionExecutor_->bookTrackerMaps(bei_, "adc");
179 // sipixelActionExecutor_->bookTrackerMaps(bei_, "charge");
180 // sipixelActionExecutor_->bookTrackerMaps(bei_, "ndigis");
181 // sipixelActionExecutor_->bookTrackerMaps(bei_, "NErrors");
182 
183  firstRun = false;
184  }
185 
186 // cout<<"...leaving SiPixelEDAClient::beginRun. "<<endl;
187 
188 }
189 //
190 // -- Begin Luminosity Block
191 //
193  edm::EventSetup const& context) {
194 // cout<<"Entering SiPixelEDAClient::beginLuminosityBlock: "<<endl;
195 
196  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Begin of LS transition";
197 
199  MonitorElement * me = bei_->get("Pixel/AdditionalPixelErrors/byLumiErrors");
200  if(me){
201  nEvents_lastLS_ = int(me->getBinContent(0));
202  nErrorsBarrel_lastLS_ = int(me->getBinContent(1));
203  nErrorsEndcap_lastLS_ = int(me->getBinContent(2));
204  //std::cout<<"Nevts in lastLS in EDAClient: "<<nEvents_lastLS_<<" "<<nErrorsBarrel_lastLS_<<" "<<nErrorsEndcap_lastLS_<<std::endl;
205  me->Reset();
206  }
207 // cout<<"...leaving SiPixelEDAClient::beginLuminosityBlock. "<<endl;
208 }
209 //
210 // -- Analyze
211 //
213 // cout<<"[SiPixelEDAClient::analyze()] "<<endl;
214  nEvents_++;
215  if(!Tier0Flag_){
216 
217  if(nEvents_==1){
218  // check if any Pixel FED is in readout:
219  edm::Handle<FEDRawDataCollection> rawDataHandle;
220  e.getByLabel(inputSource_, rawDataHandle);
221  if(!rawDataHandle.isValid()){
222  edm::LogInfo("SiPixelEDAClient") << inputSource_ << " is empty";
223  return;
224  }
225  const FEDRawDataCollection& rawDataCollection = *rawDataHandle;
226  nFEDs_ = 0;
227  for(int i = 0; i != 40; i++){
228  if(rawDataCollection.FEDData(i).size() && rawDataCollection.FEDData(i).data()) nFEDs_++;
229  }
230  }
231 
232  // This is needed for plotting with the Pixel Expert GUI (interactive client):
235  }
236 
237 }
238 //
239 // -- End Luminosity Block
240 //
242  //cout<<"Entering SiPixelEDAClient::endLuminosityBlock: "<<endl;
243 
244  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: End of LS transition, performing the DQM client operation";
245 
246  nLumiSecs_++;
247  //cout << "nLumiSecs_: "<< nLumiSecs_ << endl;
248 
249  edm::LogInfo("SiPixelEDAClient") << "====================================================== " << endl << " ===> Iteration # " << nLumiSecs_ << " " << lumiSeg.luminosityBlock() << endl << "====================================================== " << endl;
250 
251  //if(actionOnLumiSec_ && !Tier0Flag_ && nLumiSecs_ % 1 == 0 ){
252  if(actionOnLumiSec_ && nLumiSecs_ % 1 == 0 ){
255  //cout << " Updating efficiency plots" << endl;
257  //cout << " Checking QTest results " << endl;
260  //cout << " Updating occupancy plots" << endl;
262  //cout << " Checking Pixel quality flags " << endl;;
263  bei_->cd();
264  bool init=true;
265  //sipixelDataQuality_->computeGlobalQualityFlag(bei_,init,nFEDs_,Tier0Flag_);
267  init=true;
268  bei_->cd();
270  //cout << " Checking for new noisy pixels " << endl;
271  init=true;
273  // cout << "*** Creating Tracker Map Histos for End Run ***" << endl;
274 // sipixelActionExecutor_->createMaps(bei_, "adc_siPixelDigis", "adc", Mean);
275 // sipixelActionExecutor_->createMaps(bei_, "charge_siPixelClusters", "charge", Mean);
276 // sipixelActionExecutor_->createMaps(bei_, "ndigis_siPixelDigis", "ndigis", WeightedSum);
277 // sipixelActionExecutor_->createMaps(bei_, "NErrors_siPixelDigis", "NErrors", WeightedSum);
278  // cout << "*** Done with Tracker Map Histos for End Run ***" << endl;
279  }
280 
281  //cout<<"...leaving SiPixelEDAClient::endLuminosityBlock. "<<endl;
282 }
283 //
284 // -- End Run
285 //
287  //cout<<"Entering SiPixelEDAClient::endRun: "<<endl;
288 
289  //edm::LogVerbatim ("SiPixelEDAClient") <<"[SiPixelEDAClient]: End of Run, saving DQM output ";
290  //int iRun = run.run();
291 
292  if(actionOnRunEnd_){
293  //cout << " Updating Summary " << endl;
296  //cout << " Updating efficiency plots" << endl;
298  //cout << " Checking QTest results " << endl;
301  //cout << " Updating occupancy plots" << endl;
303  //cout << " Checking Pixel quality flags " << endl;;
304  bei_->cd();
305  bool init=true;
307  init=true;
308  bei_->cd();
309  //cout << " Making run end reportSummaryMap: " <<nFEDs_<< endl;;
311  //cout << " Checking for new noisy pixels " << endl;
312  init=true;
314  // cout << "*** Creating Tracker Map Histos for End Run ***" << endl;
315 // sipixelActionExecutor_->createMaps(bei_, "adc_siPixelDigis", "adc", Mean);
316 // sipixelActionExecutor_->createMaps(bei_, "charge_siPixelClusters", "charge", Mean);
317 // sipixelActionExecutor_->createMaps(bei_, "ndigis_siPixelDigis", "ndigis", WeightedSum);
318 // sipixelActionExecutor_->createMaps(bei_, "NErrors_siPixelDigis", "NErrors", WeightedSum);
319  // cout << "*** Done with Tracker Map Histos for End Run ***" << endl;
320 
321  // On demand, dump module ID's and stuff on the screen:
322  //sipixelActionExecutor_->dumpModIds(bei_,eSetup);
323  // On demand, dump summary histo values for reference on the screen:
324  //sipixelActionExecutor_->dumpRefValues(bei_,eSetup);
325  }
326 
327 // cout<<"...leaving SiPixelEDAClient::endRun. "<<endl;
328 }
329 
330 //
331 // -- End Job
332 //
334 // cout<<"In SiPixelEDAClient::endJob "<<endl;
335  edm::LogInfo("SiPixelEDAClient") <<"[SiPixelEDAClient]: endjob called!";
336 
337 }
338 //
339 // -- Create default web page
340 //
342 {
343 // cout<<"Entering SiPixelEDAClient::defaultWebPage: "<<endl;
344 
345  bool isRequest = false;
346  cgicc::Cgicc cgi(in);
347  cgicc::CgiEnvironment cgie(in);
348  // edm::LogInfo("SiPixelEDAClient") <<"[SiPixelEDAClient]: defaultWebPage "
349  // << " query string : " << cgie.getQueryString();
350  // if ( xgi::Utils::hasFormElement(cgi,"ClientRequest") ) isRequest = true;
351  string q_string = cgie.getQueryString();
352  if (q_string.find("RequestID") != string::npos) isRequest = true;
353  if (!isRequest) {
354  *out << html_out_.str() << std::endl;
355  } else {
356  // Handles all HTTP requests of the form
357  int iter = nEvents_/100;
358  sipixelWebInterface_->handleEDARequest(in, out, iter);
359  }
360 
361 // cout<<"...leaving SiPixelEDAClient::defaultWebPage. "<<endl;
362 }
363 
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
unsigned int staticUpdateFrequency_
#define Input(cl)
Definition: vmac.h:189
SiPixelEDAClient(const edm::ParameterSet &ps)
void createEfficiency(DQMStore *bei)
bool readConfiguration(int &tkmap_freq, int &summary_freq)
void fillGlobalQualityPlot(DQMStore *bei, bool init, edm::EventSetup const &eSetup, int nFEDs, bool Tier0Flag, int lumisec)
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:406
void computeGlobalQualityFlag(DQMStore *bei, bool init, int nFEDs, bool Tier0Flag)
int init
Definition: HydjetWrapper.h:63
SiPixelInformationExtractor * sipixelInformationExtractor_
void bookOccupancyPlots(DQMStore *bei, bool hiRes, bool isbarrel)
std::string inputSource_
SiPixelActionExecutor * sipixelActionExecutor_
virtual ~SiPixelEDAClient()
void computeGlobalQualityFlagByLumi(DQMStore *bei, bool init, int nFEDs, bool Tier0Flag, int nEvents_lastLS_, int nErrorsBarrel_lastLS_, int nErrorsEndcap_lastLS_)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
LuminosityBlockNumber_t luminosityBlock() const
void defaultWebPage(xgi::Input *in, xgi::Output *out)
#define BUF_SIZE
void bookDeviations(DQMStore *bei)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void createOccupancy(DQMStore *bei)
std::ostringstream html_out_
void endRun(edm::Run const &run, edm::EventSetup const &eSetup)
void setActionFlag(SiPixelActionType flag)
void bookGlobalQualityFlag(DQMStore *bei, bool Tier0Flag, int nFEDs)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1468
void handleEDARequest(xgi::Input *in, xgi::Output *out, int niter)
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple out
Definition: dbtoconf.py:99
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
SiPixelWebInterface * sipixelWebInterface_
void bookEfficiency(DQMStore *bei)
SiPixelDataQuality * sipixelDataQuality_
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
void analyze(edm::Event const &e, edm::EventSetup const &eSetup)
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup)
double getBinContent(int binx) const
get content of bin (1-D)
#define Output(cl)
Definition: vmac.h:193
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
void findNoisyPixels(DQMStore *bei, bool init, float noiseRate, int noiseRateDenominator, edm::EventSetup const &eSetup)
void bookNoisyPixels(DQMStore *bei, float noiseRate, bool Tier0Flag)
void Reset(void)
reset ME (ie. contents, errors, etc)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
void createSummary(DQMStore *bei)
Definition: Run.h:33