CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/SiStripMonitorClient/plugins/SiStripAnalyser.cc

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