CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/DQM/SiStripMonitorClient/src/SiStripActionExecutor.cc

Go to the documentation of this file.
00001 
00002 #include "DQM/SiStripMonitorClient/interface/SiStripActionExecutor.h"
00003 #include "DQMServices/Core/interface/DQMStore.h"
00004 
00005 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00006 
00007 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00008 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00009 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00010 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00011 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00012 
00013 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00014 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
00015 #include "DQM/SiStripMonitorClient/interface/SiStripSummaryCreator.h"
00016 #include "DQM/SiStripMonitorClient/interface/SiStripTrackerMapCreator.h"
00017 #include "DQM/SiStripMonitorClient/interface/SiStripLayoutParser.h"
00018 #include "DQM/SiStripMonitorClient/interface/SiStripConfigWriter.h"
00019 #include "DQM/SiStripMonitorClient/interface/SiStripQualityChecker.h"
00020 
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 
00023 
00024 #include <iomanip>
00025 //
00026 // -- Constructor
00027 // 
00028 SiStripActionExecutor::SiStripActionExecutor(edm::ParameterSet const& ps):pSet_(ps) {
00029   edm::LogInfo("SiStripActionExecutor") << 
00030     " Creating SiStripActionExecutor " << "\n" ;
00031   summaryCreator_ = 0;
00032   tkMapCreator_   = 0;
00033   qualityChecker_ = 0; 
00034   configWriter_   = 0;
00035 }
00036 //
00037 // --  Destructor
00038 // 
00039 SiStripActionExecutor::~SiStripActionExecutor() {
00040   edm::LogInfo("SiStripActionExecutor") << 
00041     " Deleting SiStripActionExecutor " << "\n" ;
00042   if (summaryCreator_) delete summaryCreator_;
00043   if (tkMapCreator_)   delete tkMapCreator_;
00044   if (qualityChecker_)  delete qualityChecker_;
00045 }
00046 //
00047 // -- Read Configurationn File
00048 //
00049 bool SiStripActionExecutor::readConfiguration() {
00050   
00051   if (!summaryCreator_) {
00052     summaryCreator_ = new SiStripSummaryCreator();
00053   }
00054   std::string fpath = pSet_.getUntrackedParameter<std::string>("SummaryConfigPath","DQM/SiStripMonitorClient/data/sistrip_monitorelement_config.xml");
00055   if (summaryCreator_->readConfiguration(fpath)) return true;
00056   else return false;
00057 }
00058 //
00059 // -- Read Configurationn File
00060 //
00061 /*
00062 bool SiStripActionExecutor::readTkMapConfiguration() {
00063   
00064   if (tkMapCreator_) delete tkMapCreator_;
00065   tkMapCreator_ = new SiStripTrackerMapCreator();
00066   if (tkMapCreator_) return true;
00067   else return false;
00068 }
00069 */
00070 bool SiStripActionExecutor::readTkMapConfiguration(const edm::EventSetup& eSetup) {
00071   
00072   if (tkMapCreator_) delete tkMapCreator_;
00073   tkMapCreator_ = new SiStripTrackerMapCreator(eSetup);
00074   if (tkMapCreator_) return true;
00075   else return false;
00076 }
00077 //
00078 // -- Create and Fill Summary Monitor Elements
00079 //
00080 void SiStripActionExecutor::createSummary(DQMStore* dqm_store) {
00081   if (summaryCreator_) {
00082     dqm_store->cd();
00083     std::string dname = "SiStrip/MechanicalView";
00084     if (dqm_store->dirExists(dname)) {
00085       dqm_store->cd(dname);
00086       summaryCreator_->createSummary(dqm_store);
00087     }
00088   }
00089 }
00090 //
00091 // -- Create and Fill Summary Monitor Elements
00092 //
00093 void SiStripActionExecutor::createSummaryOffline(DQMStore* dqm_store) {
00094   if (summaryCreator_) {
00095     dqm_store->cd();
00096     std::string dname = "MechanicalView";
00097     if (SiStripUtility::goToDir(dqm_store, dname)) {
00098       summaryCreator_->createSummary(dqm_store);
00099     }
00100     dqm_store->cd();
00101   }
00102 }
00103 //
00104 // -- create tracker map
00105 //
00106 void SiStripActionExecutor::createTkMap(const edm::ParameterSet & tkmapPset, 
00107                                         DQMStore* dqm_store, std::string& map_type) {
00108   if (tkMapCreator_) tkMapCreator_->create(tkmapPset, dqm_store, map_type);
00109 }
00110 //
00111 // -- create tracker map for offline
00112 //
00113 void SiStripActionExecutor::createOfflineTkMap(const edm::ParameterSet & tkmapPset,
00114                                                DQMStore* dqm_store, std::string& map_type) {
00115   if (tkMapCreator_) tkMapCreator_->createForOffline(tkmapPset, dqm_store, map_type);
00116 }
00117 
00118 //
00119 // -- Create Status Monitor Elements
00120 //
00121 void SiStripActionExecutor::createStatus(DQMStore* dqm_store){
00122   if (!qualityChecker_) qualityChecker_ = new SiStripQualityChecker(pSet_);
00123   qualityChecker_->bookStatus(dqm_store);
00124 }
00125 //
00126 // -- Fill Dummy Status
00127 //
00128 void SiStripActionExecutor::fillDummyStatus(){
00129   qualityChecker_->fillDummyStatus();
00130 }
00131 //
00132 // -- Fill Status
00133 //
00134 void SiStripActionExecutor::fillStatus(DQMStore* dqm_store, const edm::ESHandle<SiStripDetCabling>& detcabling) {
00135   qualityChecker_->fillStatus(dqm_store, detcabling);
00136 }
00137 //
00138 // -- Fill Lumi Status
00139 //
00140 void SiStripActionExecutor::fillStatusAtLumi(DQMStore* dqm_store) {
00141   qualityChecker_->fillStatusAtLumi(dqm_store);
00142 }
00143 //
00144 // -- 
00145 //
00146 void SiStripActionExecutor::createDummyShiftReport(){
00147   ofstream report_file;
00148   report_file.open("sistrip_shift_report.txt", std::ios::out);
00149   report_file << " Nothing to report!!" << std::endl;
00150   report_file.close();
00151 }
00152 //
00153 // -- Create Shift Report
00154 //
00155 void SiStripActionExecutor::createShiftReport(DQMStore * dqm_store){
00156 
00157   // Read layout configuration
00158   std::string localPath = std::string("DQM/SiStripMonitorClient/data/sistrip_plot_layout.xml");
00159   SiStripLayoutParser layout_parser;
00160   layout_parser.getDocument(edm::FileInPath(localPath).fullPath());
00161     
00162   std::map<std::string, std::vector<std::string> > layout_map;
00163   if (!layout_parser.getAllLayouts(layout_map)) return;
00164 
00165   
00166   std::ostringstream shift_summary;
00167   if (configWriter_) delete configWriter_;
00168   configWriter_ = new SiStripConfigWriter();
00169   configWriter_->init("ShiftReport");
00170 
00171 
00172   // Print Report Summary Content
00173   shift_summary << " Report Summary Content :" << std::endl;  
00174   shift_summary << " =========================" << std::endl;  
00175   configWriter_->createElement("ReportSummary");
00176   
00177   MonitorElement* me;
00178   std::string report_path;
00179   report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TECB";
00180   me  = dqm_store->get(report_path);    
00181   printReportSummary(me, shift_summary, "TECB"); 
00182 
00183   report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TECF";
00184   me = dqm_store->get(report_path);    
00185   printReportSummary(me, shift_summary, "TECF");
00186   
00187   report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIB";
00188   me = dqm_store->get(report_path);    
00189   printReportSummary(me, shift_summary, "TIB");
00190 
00191   report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIDB";
00192   me = dqm_store->get(report_path);    
00193   printReportSummary(me, shift_summary, "TIDB");
00194 
00195   report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIDF";
00196   me = dqm_store->get(report_path);    
00197   printReportSummary(me, shift_summary, "TIDF");
00198 
00199   report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TOB";
00200   me = dqm_store->get(report_path);    
00201   printReportSummary(me, shift_summary, "TOB");
00202 
00203   shift_summary << std::endl;
00204   printShiftHistoParameters(dqm_store, layout_map, shift_summary);
00205   
00206   ofstream report_file;
00207   report_file.open("sistrip_shift_report.txt", std::ios::out);
00208   report_file << shift_summary.str() << std::endl;
00209   report_file.close();
00210   configWriter_->write("sistrip_shift_report.xml");
00211   delete configWriter_;
00212   configWriter_ = 0;
00213 }
00214 //
00215 //  -- Print Report Summary
00216 //
00217 void SiStripActionExecutor::printReportSummary(MonitorElement* me,
00218                                                std::ostringstream& str_val, std::string name) { 
00219   str_val <<" " << name << "  : ";
00220   std::string value;
00221   SiStripUtility::getMEValue(me, value);
00222   configWriter_->createChildElement("MonitorElement", name, "value", value);
00223   float fvalue = atof(value.c_str());
00224   if (fvalue == -1.0)  str_val <<" Dummy Value "<<std::endl;
00225   else                 str_val << fvalue << std::endl;
00226 }
00227 //
00228 //  -- Print Shift Histogram Properties
00229 //
00230 void SiStripActionExecutor::printShiftHistoParameters(DQMStore * dqm_store, std::map<std::string, std::vector<std::string> >& layout_map, std::ostringstream& str_val) { 
00231 
00232   str_val << std::endl;
00233   for (std::map<std::string, std::vector< std::string > >::iterator it = layout_map.begin() ; it != layout_map.end(); it++) {
00234     std::string set_name = it->first;
00235     if (set_name.find("Summary") != std::string::npos) continue;
00236     configWriter_->createElement(set_name);
00237     
00238     str_val << " " << set_name << " : " << std::endl;
00239     str_val << " ===================================="<< std::endl;
00240     
00241     str_val << std::setprecision(2);
00242     str_val << setiosflags(std::ios::fixed);
00243     for (std::vector<std::string>::iterator im = it->second.begin(); 
00244          im != it->second.end(); im++) {  
00245       std::string path_name = (*im);
00246       if (path_name.size() == 0) continue;
00247       MonitorElement* me = dqm_store->get(path_name);
00248       std::ostringstream entry_str, mean_str, rms_str;
00249       entry_str << std::setprecision(2);
00250       entry_str << setiosflags(std::ios::fixed);
00251       mean_str << std::setprecision(2);
00252       mean_str << setiosflags(std::ios::fixed);
00253       rms_str << std::setprecision(2);
00254       rms_str << setiosflags(std::ios::fixed);
00255       entry_str << std::setw(7) << me->getEntries();
00256       mean_str << std::setw(7) << me->getMean();
00257       rms_str << std::setw(7) << me->getRMS();
00258       configWriter_->createChildElement("MonitorElement", me->getName(), 
00259         "entries",entry_str.str(),"mean",mean_str.str(),"rms",rms_str.str());
00260       
00261       if (me) str_val << " "<< me->getName()  <<" : entries = "<< std::setw(7) 
00262                       << me->getEntries() << " mean = "<< me->getMean()
00263                       <<" : rms = "<< me->getRMS()<< std::endl;
00264     }
00265     str_val << std::endl;
00266   }    
00267 }
00268 //
00269 //  -- Print List of Modules with QTest warning or Error
00270 //
00271 void SiStripActionExecutor::printFaultyModuleList(DQMStore * dqm_store, std::ostringstream& str_val) { 
00272   dqm_store->cd();
00273 
00274   std::string mdir = "MechanicalView";
00275   if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
00276   std::string mechanicalview_dir = dqm_store->pwd();
00277 
00278   std::vector<std::string> subdet_folder;
00279   subdet_folder.push_back("TIB");
00280   subdet_folder.push_back("TOB");
00281   subdet_folder.push_back("TEC/side_1");
00282   subdet_folder.push_back("TEC/side_2");
00283   subdet_folder.push_back("TID/side_1");
00284   subdet_folder.push_back("TID/side_2");
00285   
00286   int nDetsTotal = 0;
00287   int nDetsWithErrorTotal = 0;
00288   for (std::vector<std::string>::const_iterator im = subdet_folder.begin(); im != subdet_folder.end(); im++) {       
00289     std::string dname = mechanicalview_dir + "/" + (*im);
00290     if (!dqm_store->dirExists(dname)) continue;
00291     str_val << "============"<< std::endl;
00292     str_val << (*im)         << std::endl;                                                    
00293     str_val << "============"<< std::endl;
00294     str_val << std::endl;      
00295 
00296     dqm_store->cd(dname);
00297     std::vector<std::string> module_folders;
00298     SiStripUtility::getModuleFolderList(dqm_store, module_folders);
00299     int nDets = module_folders.size();
00300     dqm_store->cd();    
00301   
00302     int nDetsWithError = 0;
00303     std::string bad_module_folder = dname + "/" + "BadModuleList";
00304     if (dqm_store->dirExists(bad_module_folder)) {
00305       std::vector<MonitorElement *> meVec = dqm_store->getContents(bad_module_folder);
00306       for (std::vector<MonitorElement *>::const_iterator it = meVec.begin();
00307            it != meVec.end(); it++) {
00308         nDetsWithError++; 
00309         uint16_t flag = (*it)->getIntValue();
00310         std::string message;
00311         SiStripUtility::getBadModuleStatus(flag, message);
00312         str_val << (*it)->getName() <<  " flag : " << (*it)->getIntValue() << "  " << message << std::endl;
00313       } 
00314     }
00315     str_val << "--------------------------------------------------------------------"<< std::endl;
00316     str_val << " Detectors :  Total "<<   nDets
00317             << " with Error " << nDetsWithError<< std::endl;   
00318     str_val << "--------------------------------------------------------------------"<< std::endl;
00319     nDetsTotal += nDets;
00320     nDetsWithErrorTotal += nDetsWithError;        
00321   }    
00322   dqm_store->cd();
00323   str_val << "--------------------------------------------------------------------"<< std::endl;
00324   str_val << " Total Number of Connected Detectors : " <<   nDetsTotal << std::endl;
00325   str_val << " Total Number of Detectors with Error : " << nDetsWithErrorTotal << std::endl;
00326   str_val << "--------------------------------------------------------------------"<< std::endl;
00327 
00328 }