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 
21 
24 
30 
33 
38 
39 #include <iostream>
40 #include <iomanip>
41 #include <stdio.h>
42 #include <string>
43 #include <sstream>
44 #include <math.h>
45 
46 #define BUF_SIZE 256
47 
48 using namespace edm;
49 using namespace std;
50 //
51 // -- Constructor
52 //
54 // cout<<"Entering SiPixelEDAClient::SiPixelEDAClient: "<<endl;
55 
56  edm::LogInfo("SiPixelEDAClient") << " Creating SiPixelEDAClient " << "\n" ;
57 
58  bei_ = Service<DQMStore>().operator->();
59 
60  summaryFrequency_ = ps.getUntrackedParameter<int>("SummaryCreationFrequency",20);
61  tkMapFrequency_ = ps.getUntrackedParameter<int>("TkMapCreationFrequency",50);
62  staticUpdateFrequency_ = ps.getUntrackedParameter<int>("StaticUpdateFrequency",10);
63  actionOnLumiSec_ = ps.getUntrackedParameter<bool>("ActionOnLumiSection",false); //client
64  actionOnRunEnd_ = ps.getUntrackedParameter<bool>("ActionOnRunEnd",true); //client
65  evtOffsetForInit_ = ps.getUntrackedParameter<int>("EventOffsetForInit",10); //client
66  offlineXMLfile_ = ps.getUntrackedParameter<bool>("UseOfflineXMLFile",false); //client
67  hiRes_ = ps.getUntrackedParameter<bool>("HighResolutionOccupancy",false); //client
68  noiseRate_ = ps.getUntrackedParameter<double>("NoiseRateCutValue",0.001); //client
69  noiseRateDenominator_ = ps.getUntrackedParameter<int>("NEventsForNoiseCalculation",100000); //client
70  Tier0Flag_ = ps.getUntrackedParameter<bool>("Tier0Flag",false); //client
71  doHitEfficiency_ = ps.getUntrackedParameter<bool>("DoHitEfficiency",true); //client
72  inputSource_ = ps.getUntrackedParameter<string>("inputSource", "source");
73  isUpgrade_ = ps.getUntrackedParameter<bool>("isUpgrade",false); //client
74 
75  if(!Tier0Flag_){
76  string localPath = string("DQM/SiPixelMonitorClient/test/loader.html");
77  std::ifstream fin(edm::FileInPath(localPath).fullPath().c_str(), ios::in);
78  char buf[BUF_SIZE];
79 
80  if (!fin) {
81  cerr << "Input File: loader.html"<< " could not be opened!" << endl;
82  return;
83  }
84 
85  while (fin.getline(buf, BUF_SIZE, '\n')) { // pops off the newline character
86  html_out_ << buf ;
87  }
88  fin.close();
89 
90  }
91 
92  // instantiate web interface
93  //sipixelWebInterface_ = new SiPixelWebInterface(bei_,offlineXMLfile_,Tier0Flag_);
94  //instantiate the three work horses of the client:
95  sipixelInformationExtractor_ = new SiPixelInformationExtractor(offlineXMLfile_);
96  sipixelActionExecutor_ = new SiPixelActionExecutor(offlineXMLfile_, Tier0Flag_);
97  sipixelDataQuality_ = new SiPixelDataQuality(offlineXMLfile_);
98 
99  //set Token(-s)
100  inputSourceToken_ = consumes<FEDRawDataCollection>(ps.getUntrackedParameter<string>("inputSource", "source"));
101 // cout<<"...leaving SiPixelEDAClient::SiPixelEDAClient. "<<endl;
102 }
103 //
104 // -- Destructor
105 //
107 // cout<<"Entering SiPixelEDAClient::~SiPixelEDAClient: "<<endl;
108 
109  edm::LogInfo("SiPixelEDAClient") << " Deleting SiPixelEDAClient " << "\n" ;
110  /* Removing xdaq deps
111  if (sipixelWebInterface_) {
112  delete sipixelWebInterface_;
113  sipixelWebInterface_ = 0;
114  }
115  */
116  if (sipixelInformationExtractor_) {
117  delete sipixelInformationExtractor_;
118  sipixelInformationExtractor_ = 0;
119  }
120  if (sipixelActionExecutor_) {
121  delete sipixelActionExecutor_;
122  sipixelActionExecutor_ = 0;
123  }
124  if (sipixelDataQuality_) {
125  delete sipixelDataQuality_;
126  sipixelDataQuality_ = 0;
127  }
128 
129 // cout<<"...leaving SiPixelEDAClient::~SiPixelEDAClient. "<<endl;
130 }
131 //
132 // -- Begin Job
133 //
135  firstRun = true;
136 }
137 //
138 // -- Begin Run
139 //
140 void SiPixelEDAClient::beginRun(Run const& run, edm::EventSetup const& eSetup) {
141  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Begining of Run";
142 // cout<<"Entering SiPixelEDAClient::beginRun: "<<endl;
143 
144  if(firstRun){
145 
146  // Read the summary configuration file
147  //if (!sipixelWebInterface_->readConfiguration(tkMapFrequency_,summaryFrequency_)) {
148  // edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Error to read configuration file!! Summary will not be produced!!!";
149  //}
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:
165  sipixelActionExecutor_->createSummary(bei_, isUpgrade_);
166  // Booking Deviation Histos:
167  if(!Tier0Flag_) sipixelActionExecutor_->bookDeviations(bei_, isUpgrade_);
168  // Booking Efficiency Histos:
169  if(doHitEfficiency_) sipixelActionExecutor_->bookEfficiency(bei_, isUpgrade_);
170  // Creating occupancy plots:
171  sipixelActionExecutor_->bookOccupancyPlots(bei_, hiRes_);
172  // Booking noisy pixel ME's:
173  if(noiseRate_>0.) sipixelInformationExtractor_->bookNoisyPixels(bei_, noiseRate_, Tier0Flag_);
174  // Booking summary report ME's:
175  sipixelDataQuality_->bookGlobalQualityFlag(bei_, Tier0Flag_, nFEDs_);
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  nEvents_lastLS_=0; nErrorsBarrel_lastLS_=0; nErrorsEndcap_lastLS_=0;
198  MonitorElement * me = bei_->get("Pixel/AdditionalPixelErrors/byLumiErrors");
199  if(me){
200  nEvents_lastLS_ = int(me->getBinContent(0));
201  nErrorsBarrel_lastLS_ = int(me->getBinContent(1));
202  nErrorsEndcap_lastLS_ = int(me->getBinContent(2));
203  //std::cout<<"Nevts in lastLS in EDAClient: "<<nEvents_lastLS_<<" "<<nErrorsBarrel_lastLS_<<" "<<nErrorsEndcap_lastLS_<<std::endl;
204  me->Reset();
205  }
206 // cout<<"...leaving SiPixelEDAClient::beginLuminosityBlock. "<<endl;
207 }
208 //
209 // -- Analyze
210 //
212 // cout<<"[SiPixelEDAClient::analyze()] "<<endl;
213  nEvents_++;
214  if(!Tier0Flag_){
215 
216  if(nEvents_==1){
217  // check if any Pixel FED is in readout:
218  edm::Handle<FEDRawDataCollection> rawDataHandle;
219  e.getByToken(inputSourceToken_, rawDataHandle);
220  if(!rawDataHandle.isValid()){
221  edm::LogInfo("SiPixelEDAClient") << inputSource_ << " is empty";
222  return;
223  }
224  const FEDRawDataCollection& rawDataCollection = *rawDataHandle;
225  nFEDs_ = 0;
226  for(int i = 0; i != 40; i++){
227  if(rawDataCollection.FEDData(i).size() && rawDataCollection.FEDData(i).data()) nFEDs_++;
228  }
229  }
230 
231  // This is needed for plotting with the Pixel Expert GUI (interactive client):
232  //sipixelWebInterface_->setActionFlag(SiPixelWebInterface::CreatePlots);
233  //sipixelWebInterface_->performAction();
234  }
235 
236 }
237 //
238 // -- End Luminosity Block
239 //
241  //cout<<"Entering SiPixelEDAClient::endLuminosityBlock: "<<endl;
242 
243  edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: End of LS transition, performing the DQM client operation";
244 
245  nLumiSecs_++;
246  //cout << "nLumiSecs_: "<< nLumiSecs_ << endl;
247 
248  edm::LogInfo("SiPixelEDAClient") << "====================================================== " << endl << " ===> Iteration # " << nLumiSecs_ << " " << lumiSeg.luminosityBlock() << endl << "====================================================== " << endl;
249 
250  //if(actionOnLumiSec_ && !Tier0Flag_ && nLumiSecs_ % 1 == 0 ){
251  if(actionOnLumiSec_ && nLumiSecs_ % 1 == 0 ){
252  //sipixelWebInterface_->setActionFlag(SiPixelWebInterface::Summary);
253  //sipixelWebInterface_->performAction();
254  //cout << " Updating efficiency plots" << endl;
255  if(doHitEfficiency_) sipixelActionExecutor_->createEfficiency(bei_, isUpgrade_);
256  //cout << " Checking QTest results " << endl;
257  //sipixelWebInterface_->setActionFlag(SiPixelWebInterface::QTestResult);
258  //sipixelWebInterface_->performAction();
259  //cout << " Updating occupancy plots" << endl;
260  sipixelActionExecutor_->createOccupancy(bei_);
261  //cout << " Checking Pixel quality flags " << endl;;
262  bei_->cd();
263  bool init=true;
264  //sipixelDataQuality_->computeGlobalQualityFlag(bei_,init,nFEDs_,Tier0Flag_);
265  sipixelDataQuality_->computeGlobalQualityFlagByLumi(bei_,init,nFEDs_,Tier0Flag_,nEvents_lastLS_,nErrorsBarrel_lastLS_,nErrorsEndcap_lastLS_);
266  init=true;
267  bei_->cd();
268  sipixelDataQuality_->fillGlobalQualityPlot(bei_,init,eSetup,nFEDs_,Tier0Flag_,nLumiSecs_);
269  //cout << " Checking for new noisy pixels " << endl;
270  init=true;
271  if(noiseRate_>=0.) sipixelInformationExtractor_->findNoisyPixels(bei_, init, noiseRate_, noiseRateDenominator_, eSetup);
272  // cout << "*** Creating Tracker Map Histos for End Run ***" << endl;
273 // sipixelActionExecutor_->createMaps(bei_, "adc_siPixelDigis", "adc", Mean);
274 // sipixelActionExecutor_->createMaps(bei_, "charge_siPixelClusters", "charge", Mean);
275 // sipixelActionExecutor_->createMaps(bei_, "ndigis_siPixelDigis", "ndigis", WeightedSum);
276 // sipixelActionExecutor_->createMaps(bei_, "NErrors_siPixelDigis", "NErrors", WeightedSum);
277  // cout << "*** Done with Tracker Map Histos for End Run ***" << endl;
278  }
279 
280  //cout<<"...leaving SiPixelEDAClient::endLuminosityBlock. "<<endl;
281 }
282 //
283 // -- End Run
284 //
286  //cout<<"Entering SiPixelEDAClient::endRun: "<<endl;
287 
288  //edm::LogVerbatim ("SiPixelEDAClient") <<"[SiPixelEDAClient]: End of Run, saving DQM output ";
289  //int iRun = run.run();
290 
291  if(actionOnRunEnd_){
292  //cout << " Updating Summary " << endl;
293  //sipixelWebInterface_->setActionFlag(SiPixelWebInterface::Summary);
294  //sipixelWebInterface_->performAction();
295  sipixelActionExecutor_->createSummary(bei_, isUpgrade_);
296  //cout << " Updating efficiency plots" << endl;
297  if(doHitEfficiency_) sipixelActionExecutor_->createEfficiency(bei_, isUpgrade_);
298  //cout << " Checking QTest results " << endl;
299  //sipixelWebInterface_->setActionFlag(SiPixelWebInterface::QTestResult);
300  //sipixelWebInterface_->performAction();
301  //cout << " Updating occupancy plots" << endl;
302  sipixelActionExecutor_->createOccupancy(bei_);
303  //cout << " Checking Pixel quality flags " << endl;;
304  bei_->cd();
305  bool init=true;
306  sipixelDataQuality_->computeGlobalQualityFlag(bei_,init,nFEDs_,Tier0Flag_);
307  init=true;
308  bei_->cd();
309  //cout << " Making run end reportSummaryMap: " <<nFEDs_<< endl;;
310  sipixelDataQuality_->fillGlobalQualityPlot(bei_,init,eSetup,nFEDs_,Tier0Flag_,nLumiSecs_);
311  //cout << " Checking for new noisy pixels " << endl;
312  init=true;
313  if(noiseRate_>=0.) sipixelInformationExtractor_->findNoisyPixels(bei_, init, noiseRate_, noiseRateDenominator_, eSetup);
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 //
341 /* removing xdaq deps
342 void SiPixelEDAClient::defaultWebPage(xgi::Input *in, xgi::Output *out)
343 {
344 // cout<<"Entering SiPixelEDAClient::defaultWebPage: "<<endl;
345 
346  bool isRequest = false;
347  cgicc::Cgicc cgi(in);
348  cgicc::CgiEnvironment cgie(in);
349  // edm::LogInfo("SiPixelEDAClient") <<"[SiPixelEDAClient]: defaultWebPage "
350  // << " query string : " << cgie.getQueryString();
351  // if ( xgi::Utils::hasFormElement(cgi,"ClientRequest") ) isRequest = true;
352  string q_string = cgie.getQueryString();
353  if (q_string.find("RequestID") != string::npos) isRequest = true;
354  if (!isRequest) {
355  *out << html_out_.str() << std::endl;
356  } else {
357  // Handles all HTTP requests of the form
358  int iter = nEvents_/100;
359  sipixelWebInterface_->handleEDARequest(in, out, iter);
360  }
361 
362 // cout<<"...leaving SiPixelEDAClient::defaultWebPage. "<<endl;
363 }
364 */
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:402
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