CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripMonitorClient/src/SiStripAnalyser.cc

Go to the documentation of this file.
00001 
00002 
00003 /*
00004  * \file SiStripAnalyser.cc
00005  * 
00006  * $Date: 2013/01/02 17:41:51 $
00007  * $Revision: 1.62 $
00008  * \author  S. Dutta INFN-Pisa
00009  *
00010  */
00011 
00012 
00013 #include "DQM/SiStripMonitorClient/interface/SiStripAnalyser.h"
00014 
00015 
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 
00019 #include "FWCore/Framework/interface/LuminosityBlock.h"
00020 #include "FWCore/ServiceRegistry/interface/Service.h"
00021 #include "FWCore/ParameterSet/interface/FileInPath.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Framework/interface/Event.h"
00024 #include "FWCore/Utilities/interface/InputTag.h"
00025 
00026 #include "DQMServices/Core/interface/DQMStore.h"
00027 
00028 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00029 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00030 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00031 
00032 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00033 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00034 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00035 
00036 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
00037 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00038 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00039 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00040 
00041 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00042 #include "DQM/SiStripMonitorClient/interface/SiStripWebInterface.h"
00043 #include "DQM/SiStripMonitorClient/interface/SiStripActionExecutor.h"
00044 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
00045 #include "DQM/SiStripMonitorSummary/interface/SiStripClassToMonitorCondData.h"
00046 
00047 #include "xgi/Method.h"
00048 #include "xgi/Utils.h"
00049 
00050 #include "cgicc/Cgicc.h"
00051 #include "cgicc/FormEntry.h"
00052 #include "cgicc/HTMLClasses.h"
00053 
00054 #include <iostream>
00055 #include <iomanip>
00056 #include <stdio.h>
00057 #include <string>
00058 #include <sstream>
00059 #include <math.h>
00060 
00061 #define BUF_SIZE 256
00062 
00063 //
00064 // -- Constructor
00065 //
00066 SiStripAnalyser::SiStripAnalyser(edm::ParameterSet const& ps) :
00067   ModuleWeb("SiStripAnalyser") {
00068   
00069   // Get TkMap ParameterSet 
00070   tkMapPSet_ = ps.getParameter<edm::ParameterSet>("TkmapParameters");
00071 
00072   std::string localPath = std::string("DQM/SiStripMonitorClient/test/loader.html");
00073   ifstream fin(edm::FileInPath(localPath).fullPath().c_str(), std::ios::in);
00074   char buf[BUF_SIZE];
00075   
00076   if (!fin) {
00077     std::cerr << "Input File: loader.html"<< " could not be opened!" << std::endl;
00078     return;
00079   }
00080 
00081   while (fin.getline(buf, BUF_SIZE, '\n')) { // pops off the newline character 
00082     html_out_ << buf ;
00083   }
00084   fin.close();
00085 
00086 
00087 
00088   edm::LogInfo("SiStripAnalyser") << " SiStripAnalyser::Creating SiStripAnalyser ";
00089   summaryFrequency_      = ps.getUntrackedParameter<int>("SummaryCreationFrequency",1);
00090   tkMapFrequency_        = ps.getUntrackedParameter<int>("TkMapCreationFrequency",1); 
00091   staticUpdateFrequency_ = ps.getUntrackedParameter<int>("StaticUpdateFrequency",1);
00092   globalStatusFilling_   = ps.getUntrackedParameter<int>("GlobalStatusFilling", 1);
00093   shiftReportFrequency_  = ps.getUntrackedParameter<int>("ShiftReportFrequency", 1);   
00094   rawDataTag_            = ps.getUntrackedParameter<edm::InputTag>("RawDataTag"); 
00095   printFaultyModuleList_ = ps.getUntrackedParameter<bool>("PrintFaultyModuleList", true);
00096 
00097   // get back-end interface
00098   dqmStore_ = edm::Service<DQMStore>().operator->();
00099 
00100 
00101   // instantiate web interface
00102   sistripWebInterface_ = new SiStripWebInterface(dqmStore_);
00103   actionExecutor_ = new SiStripActionExecutor(ps);
00104   condDataMon_    = new SiStripClassToMonitorCondData(ps);
00105   trackerFEDsFound_ = false;
00106   endLumiAnalysisOn_ = false;
00107 }
00108 //
00109 // -- Destructor
00110 //
00111 SiStripAnalyser::~SiStripAnalyser(){
00112 
00113   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser::Deleting SiStripAnalyser ";
00114 //  if (sistripWebInterface_) {
00115 //     delete sistripWebInterface_;
00116 //     sistripWebInterface_ = 0;
00117 //  }
00118 //  if (trackerMapCreator_) {
00119 //    delete trackerMapCreator_;
00120 //    trackerMapCreator_ = 0;
00121 //  }
00122 
00123 }
00124 //
00125 // -- Begin Job
00126 //
00127 void SiStripAnalyser::beginJob(){
00128 
00129   // Read the summary configuration file
00130   if (!actionExecutor_->readConfiguration()) {
00131      edm::LogInfo ("SiStripAnalyser") <<"SiStripAnalyser:: Error to read configuration file!! Summary will not be produced!!!";
00132      summaryFrequency_ = -1;
00133   }
00134   nLumiSecs_ = 0;
00135   nEvents_   = 0;
00136 }
00137 //
00138 // -- Begin Run
00139 //
00140 void SiStripAnalyser::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
00141   edm::LogInfo ("SiStripAnalyser") <<"SiStripAnalyser:: Begining of Run";
00142 
00143   // Check latest Fed cabling and create TrackerMapCreator
00144   unsigned long long cacheID = eSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
00145   if (m_cacheID_ != cacheID) {
00146     m_cacheID_ = cacheID;       
00147     edm::LogInfo("SiStripAnalyser") <<"SiStripAnalyser::beginRun: " 
00148                                     << " Change in Cabling, recrated TrackerMap";     
00149     if (!actionExecutor_->readTkMapConfiguration(eSetup)) {
00150       edm::LogInfo ("SiStripAnalyser") <<"SiStripAnalyser:: Error to read configuration file!! TrackerMap will not be produced!!!";    
00151       tkMapFrequency_ = -1;
00152 
00153     }
00154     eSetup.get<SiStripFedCablingRcd>().get(fedCabling_);
00155     eSetup.get<SiStripDetCablingRcd>().get(detCabling_);
00156   } 
00157   if (condDataMon_) condDataMon_->beginRun(eSetup);
00158   if (globalStatusFilling_) actionExecutor_->createStatus(dqmStore_);
00159 }
00160 //
00161 // -- Begin Luminosity Block
00162 //
00163 void SiStripAnalyser::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) {
00164   edm::LogInfo("SiStripAnalyser") <<"SiStripAnalyser:: Begin of LS transition";
00165 }
00166 //
00167 //  -- Analyze 
00168 //
00169 void SiStripAnalyser::analyze(edm::Event const& e, edm::EventSetup const& eSetup){
00170   nEvents_++;  
00171   if (nEvents_ == 1 && globalStatusFilling_ > 0) {
00172     checkTrackerFEDs(e);
00173     if (!trackerFEDsFound_) {
00174       actionExecutor_->fillDummyStatus();
00175       actionExecutor_->createDummyShiftReport();
00176     } else {
00177       actionExecutor_->fillStatus(dqmStore_, detCabling_, eSetup);
00178       if (shiftReportFrequency_ != -1) actionExecutor_->createShiftReport(dqmStore_);
00179     }
00180   }
00181 
00182   unsigned int nval = sistripWebInterface_->getNumberOfConDBPlotRequest();
00183   if (nval > 0) {
00184     for (unsigned int ival = 0; ival < nval; ival++) {
00185       uint32_t det_id;
00186       std::string   subdet_type;
00187       uint32_t subdet_side;
00188       uint32_t layer_number;
00189       sistripWebInterface_->getConDBPlotParameters(ival, det_id, subdet_type, subdet_side, layer_number);
00190       if (condDataMon_) {
00191         if (det_id == 999) condDataMon_->getLayerMEsOnDemand(eSetup,subdet_type, subdet_side,layer_number);
00192         else if (layer_number == 999 && subdet_side == 999) condDataMon_->getModMEsOnDemand(eSetup,det_id);
00193       }
00194     }
00195     sistripWebInterface_->clearConDBPlotRequests();
00196   }
00197   sistripWebInterface_->setActionFlag(SiStripWebInterface::CreatePlots);
00198   sistripWebInterface_->performAction();
00199 }
00200 //
00201 // -- End Luminosity Block
00202 //
00203 void SiStripAnalyser::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) {
00204   edm::LogInfo ("SiStripAnalyser") <<"SiStripAnalyser:: End of LS transition, performing the DQM client operation";
00205 
00206   nLumiSecs_++;
00207 
00208   if (!trackerFEDsFound_) {
00209     actionExecutor_->fillDummyStatus();
00210     return;
00211   }   
00212   endLumiAnalysisOn_ = true;
00213 
00214   //  sistripWebInterface_->setCabling(detCabling_);
00215  
00216   std::cout << "====================================================== " << std::endl;
00217   std::cout << " ===> Iteration # " << nLumiSecs_ << " " 
00218             << lumiSeg.luminosityBlock() << std::endl;
00219   std::cout << "====================================================== " << std::endl;
00220   // Create predefined plots
00221   if (staticUpdateFrequency_ != -1 && nLumiSecs_ > 0 && nLumiSecs_%staticUpdateFrequency_  == 0) {
00222     std::cout << " Creating predefined plots " << std::endl;
00223     sistripWebInterface_->setActionFlag(SiStripWebInterface::PlotHistogramFromLayout);
00224     sistripWebInterface_->performAction();
00225   }
00226   // Fill Global Status
00227   if (globalStatusFilling_ > 0) {
00228     actionExecutor_->fillStatus(dqmStore_, detCabling_, eSetup);
00229   }
00230   // -- Create summary monitor elements according to the frequency
00231   if (summaryFrequency_ != -1 && nLumiSecs_ > 0 && nLumiSecs_%summaryFrequency_ == 0) {
00232     std::cout << " Creating Summary " << std::endl;
00233     actionExecutor_->createSummary(dqmStore_);
00234   }
00235   // -- Create TrackerMap  according to the frequency
00236   if (tkMapFrequency_ != -1 && nLumiSecs_ > 0 && nLumiSecs_%tkMapFrequency_ == 0) {
00237     std::cout << " Creating Tracker Map " << std::endl;
00238     std::string tkmap_type =  sistripWebInterface_->getTkMapType();
00239     actionExecutor_->createTkMap(tkMapPSet_, dqmStore_, tkmap_type, eSetup);
00240   }
00241   // Create Shift Report
00242   //  if (shiftReportFrequency_ != -1 && trackerFEDsFound_ && nLumiSecs_%shiftReportFrequency_  == 0) {
00243   //    actionExecutor_->createShiftReport(dqmStore_);
00244   //  }
00245   endLumiAnalysisOn_ = false;
00246 }
00247 
00248 //
00249 // -- End Run
00250 //
00251 void SiStripAnalyser::endRun(edm::Run const& run, edm::EventSetup const& eSetup){
00252   edm::LogInfo ("SiStripAnalyser") <<"SiStripAnalyser:: End of Run";
00253 }
00254 //
00255 // -- End Job
00256 //
00257 void SiStripAnalyser::endJob(){
00258   edm::LogInfo("SiStripAnalyser") <<"SiStripAnalyser:: endjob called!";
00259   if (printFaultyModuleList_) {
00260     std::ostringstream str_val;
00261     actionExecutor_->printFaultyModuleList(dqmStore_, str_val);
00262     std::cout << str_val.str() << std::endl;
00263   }
00264 }
00265 //
00266 // Check Tracker FEDs
00267 //
00268 void SiStripAnalyser::checkTrackerFEDs(edm::Event const& e) {
00269   edm::Handle<FEDRawDataCollection> rawDataHandle;
00270   e.getByLabel(rawDataTag_, rawDataHandle);
00271   if ( !rawDataHandle.isValid() ) return;
00272   
00273   const FEDRawDataCollection& rawDataCollection = *rawDataHandle;
00274   const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
00275   const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID; 
00276     
00277   unsigned int nFed = 0;
00278   for (int i=siStripFedIdMin; i <= siStripFedIdMax; i++) {
00279     if (rawDataCollection.FEDData(i).size() && rawDataCollection.FEDData(i).data()) {
00280       nFed++;
00281     }
00282   }
00283   if (nFed > 0) trackerFEDsFound_ = true;
00284 }
00285 //
00286 // -- Create default web page
00287 //
00288 void SiStripAnalyser::defaultWebPage(xgi::Input *in, xgi::Output *out)
00289 {
00290   bool isRequest = false;
00291   cgicc::Cgicc cgi(in);
00292   cgicc::CgiEnvironment cgie(in);
00293   //  edm::LogInfo("SiStripAnalyser") <<"SiStripAnalyser:: defaultWebPage "
00294   //             << " query string : " << cgie.getQueryString();
00295   //  if ( xgi::Utils::hasFormElement(cgi,"ClientRequest") ) isRequest = true;
00296   std::string q_string = cgie.getQueryString();
00297   if (q_string.find("RequestID") != std::string::npos) isRequest = true;
00298   if (!isRequest) {    
00299     *out << html_out_.str() << std::endl;
00300   }  else {
00301     // Handles all HTTP requests of the form
00302     int iter = -1;
00303     if (endLumiAnalysisOn_) {
00304       sistripWebInterface_->handleAnalyserRequest(in, out, detCabling_, iter); 
00305     } else {
00306       iter = nEvents_/10;
00307       sistripWebInterface_->handleAnalyserRequest(in, out, detCabling_, iter);
00308     } 
00309   }
00310 }
00311 
00312 #include "FWCore/Framework/interface/MakerMacros.h"
00313 DEFINE_FWK_MODULE(SiStripAnalyser);