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
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
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
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
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
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
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
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
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
00112
00113 void SiStripActionExecutor::createStatus(DQMStore* dqm_store){
00114 if (!qualityChecker_) qualityChecker_ = new SiStripQualityChecker(pSet_);
00115 qualityChecker_->bookStatus(dqm_store);
00116 }
00117
00118
00119
00120 void SiStripActionExecutor::fillDummyStatus(){
00121 qualityChecker_->fillDummyStatus();
00122 }
00123
00124
00125
00126 void SiStripActionExecutor::fillStatus(DQMStore* dqm_store, const edm::ESHandle<SiStripDetCabling>& detcabling) {
00127 qualityChecker_->fillStatus(dqm_store, detcabling);
00128 }
00129
00130
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
00146
00147 void SiStripActionExecutor::createShiftReport(DQMStore * dqm_store){
00148
00149
00150 std::string localPath = std::string("DQM/SiStripMonitorClient/data/sistrip_plot_layout.xml");
00151 SiStripLayoutParser* layout_parser = new SiStripLayoutParser();
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 delete layout_parser;
00157
00158
00159 std::ostringstream shift_summary;
00160 if (configWriter_) delete configWriter_;
00161 configWriter_ = new SiStripConfigWriter();
00162 configWriter_->init("ShiftReport");
00163
00164
00165
00166 shift_summary << " Report Summary Content :" << std::endl;
00167 shift_summary << " =========================" << std::endl;
00168 configWriter_->createElement("ReportSummary");
00169
00170 MonitorElement* me;
00171 std::string report_path;
00172 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TECB";
00173 me = dqm_store->get(report_path);
00174 printReportSummary(me, shift_summary, "TECB");
00175
00176 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TECF";
00177 me = dqm_store->get(report_path);
00178 printReportSummary(me, shift_summary, "TECF");
00179
00180 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIB";
00181 me = dqm_store->get(report_path);
00182 printReportSummary(me, shift_summary, "TIB");
00183
00184 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIDB";
00185 me = dqm_store->get(report_path);
00186 printReportSummary(me, shift_summary, "TIDB");
00187
00188 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIDF";
00189 me = dqm_store->get(report_path);
00190 printReportSummary(me, shift_summary, "TIDF");
00191
00192 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TOB";
00193 me = dqm_store->get(report_path);
00194 printReportSummary(me, shift_summary, "TOB");
00195
00196 shift_summary << std::endl;
00197 printShiftHistoParameters(dqm_store, layout_map, shift_summary);
00198
00199 ofstream report_file;
00200 report_file.open("sistrip_shift_report.txt", std::ios::out);
00201 report_file << shift_summary.str() << std::endl;
00202 report_file.close();
00203 configWriter_->write("sistrip_shift_report.xml");
00204 delete configWriter_;
00205 configWriter_ = 0;
00206 }
00207
00208
00209
00210 void SiStripActionExecutor::printReportSummary(MonitorElement* me,
00211 std::ostringstream& str_val, std::string name) {
00212 str_val <<" " << name << " : ";
00213 std::string value;
00214 SiStripUtility::getMEValue(me, value);
00215 configWriter_->createChildElement("MonitorElement", name, "value", value);
00216 float fvalue = atof(value.c_str());
00217 if (fvalue == -1.0) str_val <<" Dummy Value "<<std::endl;
00218 else str_val << fvalue << std::endl;
00219 }
00220
00221
00222
00223 void SiStripActionExecutor::printShiftHistoParameters(DQMStore * dqm_store, std::map<std::string, std::vector<std::string> >& layout_map, std::ostringstream& str_val) {
00224
00225 str_val << std::endl;
00226 for (std::map<std::string, std::vector< std::string > >::iterator it = layout_map.begin() ; it != layout_map.end(); it++) {
00227 std::string set_name = it->first;
00228 if (set_name.find("Summary") != std::string::npos) continue;
00229 configWriter_->createElement(set_name);
00230
00231 str_val << " " << set_name << " : " << std::endl;
00232 str_val << " ===================================="<< std::endl;
00233
00234 str_val << std::setprecision(2);
00235 str_val << setiosflags(std::ios::fixed);
00236 for (std::vector<std::string>::iterator im = it->second.begin();
00237 im != it->second.end(); im++) {
00238 std::string path_name = (*im);
00239 if (path_name.size() == 0) continue;
00240 MonitorElement* me = dqm_store->get(path_name);
00241 std::ostringstream entry_str, mean_str, rms_str;
00242 entry_str << std::setprecision(2);
00243 entry_str << setiosflags(std::ios::fixed);
00244 mean_str << std::setprecision(2);
00245 mean_str << setiosflags(std::ios::fixed);
00246 rms_str << std::setprecision(2);
00247 rms_str << setiosflags(std::ios::fixed);
00248 entry_str << std::setw(7) << me->getEntries();
00249 mean_str << std::setw(7) << me->getMean();
00250 rms_str << std::setw(7) << me->getRMS();
00251 configWriter_->createChildElement("MonitorElement", me->getName(),
00252 "entries",entry_str.str(),"mean",mean_str.str(),"rms",rms_str.str());
00253
00254 if (me) str_val << " "<< me->getName() <<" : entries = "<< std::setw(7)
00255 << me->getEntries() << " mean = "<< me->getMean()
00256 <<" : rms = "<< me->getRMS()<< std::endl;
00257 }
00258 str_val << std::endl;
00259 }
00260 }
00261
00262
00263
00264 void SiStripActionExecutor::printFaultyModuleList(DQMStore * dqm_store, std::ostringstream& str_val) {
00265 dqm_store->cd();
00266
00267 std::string mdir = "MechanicalView";
00268 if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
00269 std::string mechanicalview_dir = dqm_store->pwd();
00270
00271 std::vector<std::string> subdet_folder;
00272 subdet_folder.push_back("TIB");
00273 subdet_folder.push_back("TOB");
00274 subdet_folder.push_back("TEC/side_1");
00275 subdet_folder.push_back("TEC/side_2");
00276 subdet_folder.push_back("TID/side_1");
00277 subdet_folder.push_back("TID/side_2");
00278
00279 int nDetsTotal = 0;
00280 int nDetsWithErrorTotal = 0;
00281 for (std::vector<std::string>::const_iterator im = subdet_folder.begin(); im != subdet_folder.end(); im++) {
00282 std::string dname = mechanicalview_dir + "/" + (*im);
00283 if (!dqm_store->dirExists(dname)) continue;
00284 str_val << "============"<< std::endl;
00285 str_val << (*im) << std::endl;
00286 str_val << "============"<< std::endl;
00287 str_val << std::endl;
00288
00289 dqm_store->cd(dname);
00290 std::vector<std::string> module_folders;
00291 SiStripUtility::getModuleFolderList(dqm_store, module_folders);
00292 int nDets = module_folders.size();
00293 dqm_store->cd();
00294
00295 int nDetsWithError = 0;
00296 std::string bad_module_folder = dname + "/" + "BadModuleList";
00297 if (dqm_store->dirExists(bad_module_folder)) {
00298 std::vector<MonitorElement *> meVec = dqm_store->getContents(bad_module_folder);
00299 for (std::vector<MonitorElement *>::const_iterator it = meVec.begin();
00300 it != meVec.end(); it++) {
00301 nDetsWithError++;
00302 uint16_t flag = (*it)->getIntValue();
00303 std::string message;
00304 SiStripUtility::getBadModuleStatus(flag, message);
00305 str_val << (*it)->getName() << " flag : " << (*it)->getIntValue() << " " << message << std::endl;
00306 }
00307 }
00308 str_val << "--------------------------------------------------------------------"<< std::endl;
00309 str_val << " Detectors : Total "<< nDets
00310 << " with Error " << nDetsWithError<< std::endl;
00311 str_val << "--------------------------------------------------------------------"<< std::endl;
00312 nDetsTotal += nDets;
00313 nDetsWithErrorTotal += nDetsWithError;
00314 }
00315 dqm_store->cd();
00316 str_val << "--------------------------------------------------------------------"<< std::endl;
00317 str_val << " Total Number of Connected Detectors : " << nDetsTotal << std::endl;
00318 str_val << " Total Number of Detectors with Error : " << nDetsWithErrorTotal << std::endl;
00319 str_val << "--------------------------------------------------------------------"<< std::endl;
00320
00321 }