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