CMS 3D CMS Logo

SiStripAnalyser.cc

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

Generated on Tue Jun 9 17:33:34 2009 for CMSSW by  doxygen 1.5.4