00001 #include "DQM/SiPixelMonitorClient/interface/SiPixelEDAClient.h"
00002
00003
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "FWCore/Framework/interface/LuminosityBlock.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 #include "FWCore/ParameterSet/interface/FileInPath.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010
00011 #include "DataFormats/DetId/interface/DetId.h"
00012 #include "DataFormats/GeometrySurface/interface/Surface.h"
00013 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00014 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00015 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00016 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00017 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00018 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00019
00020 #include "CondFormats/SiPixelObjects/interface/DetectorIndex.h"
00021 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
00022
00023 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00024 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00025 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00026 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00027 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00028
00029 #include "DQMServices/Core/interface/DQMStore.h"
00030 #include "DQMServices/Core/interface/MonitorElement.h"
00031
00032 #include "DQM/SiPixelMonitorClient/interface/SiPixelWebInterface.h"
00033 #include "DQM/SiPixelMonitorClient/interface/SiPixelActionExecutor.h"
00034 #include "DQM/SiPixelMonitorClient/interface/SiPixelInformationExtractor.h"
00035 #include "DQM/SiPixelMonitorClient/interface/SiPixelDataQuality.h"
00036 #include "DQM/SiPixelMonitorClient/interface/SiPixelUtility.h"
00037
00038 #include "xgi/Method.h"
00039 #include "xgi/Utils.h"
00040
00041 #include "cgicc/Cgicc.h"
00042 #include "cgicc/FormEntry.h"
00043 #include "cgicc/HTMLClasses.h"
00044
00045 #include <iostream>
00046 #include <iomanip>
00047 #include <stdio.h>
00048 #include <string>
00049 #include <sstream>
00050 #include <math.h>
00051
00052 #define BUF_SIZE 256
00053
00054 using namespace edm;
00055 using namespace std;
00056
00057
00058
00059 SiPixelEDAClient::SiPixelEDAClient(const edm::ParameterSet& ps) :
00060 ModuleWeb("SiPixelEDAClient"){
00061
00062
00063 edm::LogInfo("SiPixelEDAClient") << " Creating SiPixelEDAClient " << "\n" ;
00064
00065 bei_ = Service<DQMStore>().operator->();
00066
00067 summaryFrequency_ = ps.getUntrackedParameter<int>("SummaryCreationFrequency",20);
00068 tkMapFrequency_ = ps.getUntrackedParameter<int>("TkMapCreationFrequency",50);
00069 staticUpdateFrequency_ = ps.getUntrackedParameter<int>("StaticUpdateFrequency",10);
00070 actionOnLumiSec_ = ps.getUntrackedParameter<bool>("ActionOnLumiSection",false);
00071 actionOnRunEnd_ = ps.getUntrackedParameter<bool>("ActionOnRunEnd",true);
00072 evtOffsetForInit_ = ps.getUntrackedParameter<int>("EventOffsetForInit",10);
00073 offlineXMLfile_ = ps.getUntrackedParameter<bool>("UseOfflineXMLFile",false);
00074 hiRes_ = ps.getUntrackedParameter<bool>("HighResolutionOccupancy",false);
00075 noiseRate_ = ps.getUntrackedParameter<double>("NoiseRateCutValue",0.001);
00076 noiseRateDenominator_ = ps.getUntrackedParameter<int>("NEventsForNoiseCalculation",100000);
00077 Tier0Flag_ = ps.getUntrackedParameter<bool>("Tier0Flag",false);
00078 doHitEfficiency_ = ps.getUntrackedParameter<bool>("DoHitEfficiency",true);
00079 inputSource_ = ps.getUntrackedParameter<string>("inputSource", "source");
00080
00081 if(!Tier0Flag_){
00082 string localPath = string("DQM/SiPixelMonitorClient/test/loader.html");
00083 ifstream fin(edm::FileInPath(localPath).fullPath().c_str(), ios::in);
00084 char buf[BUF_SIZE];
00085
00086 if (!fin) {
00087 cerr << "Input File: loader.html"<< " could not be opened!" << endl;
00088 return;
00089 }
00090
00091 while (fin.getline(buf, BUF_SIZE, '\n')) {
00092 html_out_ << buf ;
00093 }
00094 fin.close();
00095
00096 }
00097
00098
00099 sipixelWebInterface_ = new SiPixelWebInterface(bei_,offlineXMLfile_,Tier0Flag_);
00100
00101 sipixelInformationExtractor_ = new SiPixelInformationExtractor(offlineXMLfile_);
00102 sipixelActionExecutor_ = new SiPixelActionExecutor(offlineXMLfile_, Tier0Flag_);
00103 sipixelDataQuality_ = new SiPixelDataQuality(offlineXMLfile_);
00104
00105
00106 }
00107
00108
00109
00110 SiPixelEDAClient::~SiPixelEDAClient(){
00111
00112
00113 edm::LogInfo("SiPixelEDAClient") << " Deleting SiPixelEDAClient " << "\n" ;
00114 if (sipixelWebInterface_) {
00115 delete sipixelWebInterface_;
00116 sipixelWebInterface_ = 0;
00117 }
00118 if (sipixelInformationExtractor_) {
00119 delete sipixelInformationExtractor_;
00120 sipixelInformationExtractor_ = 0;
00121 }
00122 if (sipixelActionExecutor_) {
00123 delete sipixelActionExecutor_;
00124 sipixelActionExecutor_ = 0;
00125 }
00126 if (sipixelDataQuality_) {
00127 delete sipixelDataQuality_;
00128 sipixelDataQuality_ = 0;
00129 }
00130
00131
00132 }
00133
00134
00135
00136 void SiPixelEDAClient::beginJob(){
00137 firstRun = true;
00138 }
00139
00140
00141
00142 void SiPixelEDAClient::beginRun(Run const& run, edm::EventSetup const& eSetup) {
00143 edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Begining of Run";
00144
00145
00146 if(firstRun){
00147
00148
00149 if (!sipixelWebInterface_->readConfiguration(tkMapFrequency_,summaryFrequency_)) {
00150 edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Error to read configuration file!! Summary will not be produced!!!";
00151 summaryFrequency_ = -1;
00152 tkMapFrequency_ = -1;
00153 actionOnLumiSec_ = false;
00154 actionOnRunEnd_ = true;
00155 evtOffsetForInit_ = -1;
00156 }
00157 nLumiSecs_ = 0;
00158 nEvents_ = 0;
00159 if(Tier0Flag_) nFEDs_ = 40;
00160 else nFEDs_ = 0;
00161
00162 bei_->setCurrentFolder("Pixel/");
00163
00164
00165
00166 sipixelActionExecutor_->createSummary(bei_);
00167
00168 if(!Tier0Flag_) sipixelActionExecutor_->bookDeviations(bei_);
00169
00170 if(doHitEfficiency_) sipixelActionExecutor_->bookEfficiency(bei_);
00171
00172 sipixelActionExecutor_->bookOccupancyPlots(bei_, hiRes_);
00173
00174 if(noiseRate_>0.) sipixelInformationExtractor_->bookNoisyPixels(bei_, noiseRate_, Tier0Flag_);
00175
00176 sipixelDataQuality_->bookGlobalQualityFlag(bei_, Tier0Flag_, nFEDs_);
00177
00178
00179
00180
00181
00182
00183 firstRun = false;
00184 }
00185
00186
00187
00188 }
00189
00190
00191
00192 void SiPixelEDAClient::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg,
00193 edm::EventSetup const& context) {
00194
00195
00196 edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: Begin of LS transition";
00197
00198 nEvents_lastLS_=0; nErrorsBarrel_lastLS_=0; nErrorsEndcap_lastLS_=0;
00199 MonitorElement * me = bei_->get("Pixel/AdditionalPixelErrors/byLumiErrors");
00200 if(me){
00201 nEvents_lastLS_ = int(me->getBinContent(0));
00202 nErrorsBarrel_lastLS_ = int(me->getBinContent(1));
00203 nErrorsEndcap_lastLS_ = int(me->getBinContent(2));
00204
00205 me->Reset();
00206 }
00207
00208 }
00209
00210
00211
00212 void SiPixelEDAClient::analyze(const edm::Event& e, const edm::EventSetup& eSetup){
00213
00214 nEvents_++;
00215 if(!Tier0Flag_){
00216
00217 if(nEvents_==1){
00218
00219 edm::Handle<FEDRawDataCollection> rawDataHandle;
00220 e.getByLabel(inputSource_, rawDataHandle);
00221 if(!rawDataHandle.isValid()){
00222 edm::LogInfo("SiPixelEDAClient") << inputSource_ << " is empty";
00223 return;
00224 }
00225 const FEDRawDataCollection& rawDataCollection = *rawDataHandle;
00226 nFEDs_ = 0;
00227 for(int i = 0; i != 40; i++){
00228 if(rawDataCollection.FEDData(i).size() && rawDataCollection.FEDData(i).data()) nFEDs_++;
00229 }
00230 }
00231
00232
00233 sipixelWebInterface_->setActionFlag(SiPixelWebInterface::CreatePlots);
00234 sipixelWebInterface_->performAction();
00235 }
00236
00237 }
00238
00239
00240
00241 void SiPixelEDAClient::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) {
00242
00243
00244 edm::LogInfo ("SiPixelEDAClient") <<"[SiPixelEDAClient]: End of LS transition, performing the DQM client operation";
00245
00246 nLumiSecs_++;
00247
00248
00249 edm::LogInfo("SiPixelEDAClient") << "====================================================== " << endl << " ===> Iteration # " << nLumiSecs_ << " " << lumiSeg.luminosityBlock() << endl << "====================================================== " << endl;
00250
00251
00252 if(actionOnLumiSec_ && nLumiSecs_ % 1 == 0 ){
00253 sipixelWebInterface_->setActionFlag(SiPixelWebInterface::Summary);
00254 sipixelWebInterface_->performAction();
00255
00256 if(doHitEfficiency_) sipixelActionExecutor_->createEfficiency(bei_);
00257
00258 sipixelWebInterface_->setActionFlag(SiPixelWebInterface::QTestResult);
00259 sipixelWebInterface_->performAction();
00260
00261 sipixelActionExecutor_->createOccupancy(bei_);
00262
00263 bei_->cd();
00264 bool init=true;
00265
00266 sipixelDataQuality_->computeGlobalQualityFlagByLumi(bei_,init,nFEDs_,Tier0Flag_,nEvents_lastLS_,nErrorsBarrel_lastLS_,nErrorsEndcap_lastLS_);
00267 init=true;
00268 bei_->cd();
00269 sipixelDataQuality_->fillGlobalQualityPlot(bei_,init,eSetup,nFEDs_,Tier0Flag_,nLumiSecs_);
00270
00271 init=true;
00272 if(noiseRate_>=0.) sipixelInformationExtractor_->findNoisyPixels(bei_, init, noiseRate_, noiseRateDenominator_, eSetup);
00273
00274
00275
00276
00277
00278
00279 }
00280
00281
00282 }
00283
00284
00285
00286 void SiPixelEDAClient::endRun(edm::Run const& run, edm::EventSetup const& eSetup){
00287
00288
00289
00290
00291
00292 if(actionOnRunEnd_){
00293
00294 sipixelWebInterface_->setActionFlag(SiPixelWebInterface::Summary);
00295 sipixelWebInterface_->performAction();
00296
00297 if(doHitEfficiency_) sipixelActionExecutor_->createEfficiency(bei_);
00298
00299 sipixelWebInterface_->setActionFlag(SiPixelWebInterface::QTestResult);
00300 sipixelWebInterface_->performAction();
00301
00302 sipixelActionExecutor_->createOccupancy(bei_);
00303
00304 bei_->cd();
00305 bool init=true;
00306 sipixelDataQuality_->computeGlobalQualityFlag(bei_,init,nFEDs_,Tier0Flag_);
00307 init=true;
00308 bei_->cd();
00309
00310 sipixelDataQuality_->fillGlobalQualityPlot(bei_,init,eSetup,nFEDs_,Tier0Flag_,nLumiSecs_);
00311
00312 init=true;
00313 if(noiseRate_>=0.) sipixelInformationExtractor_->findNoisyPixels(bei_, init, noiseRate_, noiseRateDenominator_, eSetup);
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 }
00326
00327
00328 }
00329
00330
00331
00332
00333 void SiPixelEDAClient::endJob(){
00334
00335 edm::LogInfo("SiPixelEDAClient") <<"[SiPixelEDAClient]: endjob called!";
00336
00337 }
00338
00339
00340
00341 void SiPixelEDAClient::defaultWebPage(xgi::Input *in, xgi::Output *out)
00342 {
00343
00344
00345 bool isRequest = false;
00346 cgicc::Cgicc cgi(in);
00347 cgicc::CgiEnvironment cgie(in);
00348
00349
00350
00351 string q_string = cgie.getQueryString();
00352 if (q_string.find("RequestID") != string::npos) isRequest = true;
00353 if (!isRequest) {
00354 *out << html_out_.str() << std::endl;
00355 } else {
00356
00357 int iter = nEvents_/100;
00358 sipixelWebInterface_->handleEDARequest(in, out, iter);
00359 }
00360
00361
00362 }
00363