CMS 3D CMS Logo

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