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 
80  if(!Tier0Flag_){
81  string localPath = string("DQM/SiPixelMonitorClient/test/loader.html");
82  ifstream fin(edm::FileInPath(localPath).fullPath().c_str(), ios::in);
83  char buf[BUF_SIZE];
84 
85  if (!fin) {
86  cerr << "Input File: loader.html"<< " could not be opened!" << endl;
87  return;
88  }
89 
90  while (fin.getline(buf, BUF_SIZE, '\n')) { // pops off the newline character
91  html_out_ << buf ;
92  }
93  fin.close();
94 
95  }
96 
97  // instantiate web interface
98  sipixelWebInterface_ = new SiPixelWebInterface(bei_,offlineXMLfile_,Tier0Flag_);
99  //instantiate the three work horses of the client:
101  sipixelActionExecutor_ = new SiPixelActionExecutor(offlineXMLfile_, Tier0Flag_);
102  sipixelDataQuality_ = new SiPixelDataQuality(offlineXMLfile_);
103 
104 // cout<<"...leaving SiPixelEDAClient::SiPixelEDAClient. "<<endl;
105 }
106 //
107 // -- Destructor
108 //
110 // cout<<"Entering SiPixelEDAClient::~SiPixelEDAClient: "<<endl;
111 
112  edm::LogInfo("SiPixelEDAClient") << " Deleting SiPixelEDAClient " << "\n" ;
113  if (sipixelWebInterface_) {
114  delete sipixelWebInterface_;
116  }
120  }
122  delete sipixelActionExecutor_;
124  }
125  if (sipixelDataQuality_) {
126  delete sipixelDataQuality_;
128  }
129 
130 // cout<<"...leaving SiPixelEDAClient::~SiPixelEDAClient. "<<endl;
131 }
132 //
133 // -- Begin Job
134 //
136  firstRun = true;
137 }
138 //
139 // -- Begin Run
140 //
141 void SiPixelEDAClient::beginRun(Run const& run, edm::EventSetup const& eSetup) {
142  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Begining of Run";
143 // cout<<"Entering SiPixelEDAClient::beginRun: "<<endl;
144 
145  if(firstRun){
146 
147  // Read the summary configuration file
149  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Error to read configuration file!! Summary will not be produced!!!";
150  summaryFrequency_ = -1;
151  tkMapFrequency_ = -1;
152  actionOnLumiSec_ = false;
153  actionOnRunEnd_ = true;
154  evtOffsetForInit_ = -1;
155  }
156  nLumiSecs_ = 0;
157  nEvents_ = 0;
158  if(Tier0Flag_) nFEDs_ = 40;
159  else nFEDs_ = 0;
160 
161  bei_->setCurrentFolder("Pixel/");
162  // Setting up QTests:
163 // sipixelActionExecutor_->setupQTests(bei_);
164  // Creating Summary Histos:
166  // Booking Deviation Histos:
168  // Booking Efficiency Histos:
170  // Creating occupancy plots:
172  // Booking noisy pixel ME's:
174  // Booking summary report ME's:
176  // Booking Static Tracker Maps:
177 // sipixelActionExecutor_->bookTrackerMaps(bei_, "adc");
178 // sipixelActionExecutor_->bookTrackerMaps(bei_, "charge");
179 // sipixelActionExecutor_->bookTrackerMaps(bei_, "ndigis");
180 // sipixelActionExecutor_->bookTrackerMaps(bei_, "NErrors");
181 
182  firstRun = false;
183  }
184 
185 // cout<<"...leaving SiPixelEDAClient::beginRun. "<<endl;
186 
187 }
188 //
189 // -- Begin Luminosity Block
190 //
192  edm::EventSetup const& context) {
193 // cout<<"Entering SiPixelEDAClient::beginLuminosityBlock: "<<endl;
194 
195  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Begin of LS transition";
196 
197  MonitorElement * me = bei_->get("Pixel/AdditionalPixelErrors/byLumiErrors");
198  if(me){
199  nEvents_lastLS_ = int(me->getBinContent(0));
200  me->Reset();
201  }
202 // cout<<"...leaving SiPixelEDAClient::beginLuminosityBlock. "<<endl;
203 }
204 //
205 // -- Analyze
206 //
208 // cout<<"[SiPixelEDAClient::analyze()] "<<endl;
209  nEvents_++;
210  if(!Tier0Flag_){
211 
212  if(nEvents_==1){
213  // check if any Pixel FED is in readout:
214  edm::Handle<FEDRawDataCollection> rawDataHandle;
215  e.getByLabel("source", rawDataHandle);
216  if(!rawDataHandle.isValid()){
217  edm::LogInfo("SiPixelEDAClient") << "source" << " is empty";
218  return;
219  }
220  const FEDRawDataCollection& rawDataCollection = *rawDataHandle;
221  nFEDs_ = 0;
222  for(int i = 0; i != 40; i++){
223  if(rawDataCollection.FEDData(i).size() && rawDataCollection.FEDData(i).data()) nFEDs_++;
224  }
225  }
226 
227  // This is needed for plotting with the Pixel Expert GUI (interactive client):
230  }
231 
232 }
233 //
234 // -- End Luminosity Block
235 //
237 // cout<<"Entering SiPixelEDAClient::endLuminosityBlock: "<<endl;
238 
239  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: End of LS transition, performing the DQM client operation";
240 
241  nLumiSecs_++;
242  //cout << "nLumiSecs_: "<< nLumiSecs_ << endl;
243 
244  edm::LogInfo("SiPixelEDAClient") << "====================================================== " << endl << " ===> Iteration # " << nLumiSecs_ << " " << lumiSeg.luminosityBlock() << endl << "====================================================== " << endl;
245 
246  if(actionOnLumiSec_ && !Tier0Flag_ && nLumiSecs_ % 1 == 0 ){
247  //cout << " Updating Summary " << endl;
250  //cout << " Updating efficiency plots" << endl;
252  //cout << " Checking QTest results " << endl;
255  //cout << " Updating occupancy plots" << endl;
257  //cout << " Checking Pixel quality flags " << endl;;
258  bei_->cd();
259  bool init=true;
260  //sipixelDataQuality_->computeGlobalQualityFlag(bei_,init,nFEDs_,Tier0Flag_);
262  init=true;
263  bei_->cd();
265  //cout << " Checking for new noisy pixels " << endl;
266  init=true;
268  // cout << "*** Creating Tracker Map Histos for End Run ***" << endl;
269 // sipixelActionExecutor_->createMaps(bei_, "adc_siPixelDigis", "adc", Mean);
270 // sipixelActionExecutor_->createMaps(bei_, "charge_siPixelClusters", "charge", Mean);
271 // sipixelActionExecutor_->createMaps(bei_, "ndigis_siPixelDigis", "ndigis", WeightedSum);
272 // sipixelActionExecutor_->createMaps(bei_, "NErrors_siPixelDigis", "NErrors", WeightedSum);
273  // cout << "*** Done with Tracker Map Histos for End Run ***" << endl;
274  }
275 
276 // cout<<"...leaving SiPixelEDAClient::endLuminosityBlock. "<<endl;
277 }
278 //
279 // -- End Run
280 //
282  //cout<<"Entering SiPixelEDAClient::endRun: "<<endl;
283 
284  //edm::LogVerbatim ("SiPixelEDAClient") <<"[SiPixelEDAClient]: End of Run, saving DQM output ";
285  //int iRun = run.run();
286 
287  if(actionOnRunEnd_){
288  //cout << " Updating Summary " << endl;
291  //cout << " Updating efficiency plots" << endl;
293  //cout << " Checking QTest results " << endl;
296  //cout << " Updating occupancy plots" << endl;
298  //cout << " Checking Pixel quality flags " << endl;;
299  bei_->cd();
300  bool init=true;
302  init=true;
303  bei_->cd();
304  //cout << " Making run end reportSummaryMap: " <<nFEDs_<< endl;;
306  //cout << " Checking for new noisy pixels " << endl;
307  init=true;
309  // cout << "*** Creating Tracker Map Histos for End Run ***" << endl;
310 // sipixelActionExecutor_->createMaps(bei_, "adc_siPixelDigis", "adc", Mean);
311 // sipixelActionExecutor_->createMaps(bei_, "charge_siPixelClusters", "charge", Mean);
312 // sipixelActionExecutor_->createMaps(bei_, "ndigis_siPixelDigis", "ndigis", WeightedSum);
313 // sipixelActionExecutor_->createMaps(bei_, "NErrors_siPixelDigis", "NErrors", WeightedSum);
314  // cout << "*** Done with Tracker Map Histos for End Run ***" << endl;
315 
316  // On demand, dump module ID's and stuff on the screen:
317  //sipixelActionExecutor_->dumpModIds(bei_,eSetup);
318  // On demand, dump summary histo values for reference on the screen:
319  //sipixelActionExecutor_->dumpRefValues(bei_,eSetup);
320  }
321 
322 // cout<<"...leaving SiPixelEDAClient::endRun. "<<endl;
323 }
324 
325 //
326 // -- End Job
327 //
329 // cout<<"In SiPixelEDAClient::endJob "<<endl;
330  edm::LogInfo("SiPixelEDAClient") <<"[SiPixelEDAClient]: endjob called!";
331 
332 }
333 //
334 // -- Create default web page
335 //
337 {
338 // cout<<"Entering SiPixelEDAClient::defaultWebPage: "<<endl;
339 
340  bool isRequest = false;
341  cgicc::Cgicc cgi(in);
342  cgicc::CgiEnvironment cgie(in);
343  // edm::LogInfo("SiPixelEDAClient") <<"[SiPixelEDAClient]: defaultWebPage "
344  // << " query string : " << cgie.getQueryString();
345  // if ( xgi::Utils::hasFormElement(cgi,"ClientRequest") ) isRequest = true;
346  string q_string = cgie.getQueryString();
347  if (q_string.find("RequestID") != string::npos) isRequest = true;
348  if (!isRequest) {
349  *out << html_out_.str() << std::endl;
350  } else {
351  // Handles all HTTP requests of the form
352  int iter = nEvents_/100;
353  sipixelWebInterface_->handleEDARequest(in, out, iter);
354  }
355 
356 // cout<<"...leaving SiPixelEDAClient::defaultWebPage. "<<endl;
357 }
358 
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
unsigned int staticUpdateFrequency_
void computeGlobalQualityFlagByLumi(DQMStore *bei, bool init, int nFEDs, bool Tier0Flag, int nEvents_lastLS_)
#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:214
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)
SiPixelActionExecutor * sipixelActionExecutor_
virtual ~SiPixelEDAClient()
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
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:1270
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:359
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:237
void createSummary(DQMStore *bei)
Definition: Run.h:31