File indexing completed on 2023-03-17 10:56:42
0001 #include "DQM/SiStripMonitorClient/interface/SiStripActionExecutor.h"
0002 #include "DQMServices/Core/interface/DQMStore.h"
0003
0004 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0005
0006 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0007
0008 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0009 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
0010 #include "DQM/SiStripMonitorClient/interface/SiStripLayoutParser.h"
0011
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013
0014 #include <fstream>
0015 #include <iomanip>
0016 #include <iostream>
0017 #include <sstream>
0018
0019 SiStripActionExecutor::SiStripActionExecutor(edm::ParameterSet const& ps) : pSet_{ps} {
0020 edm::LogInfo("SiStripActionExecutor") << " Creating SiStripActionExecutor "
0021 << "\n";
0022 }
0023
0024 SiStripActionExecutor::~SiStripActionExecutor() {
0025 edm::LogInfo("SiStripActionExecutor") << " Deleting SiStripActionExecutor "
0026 << "\n";
0027 }
0028
0029 bool SiStripActionExecutor::readConfiguration() {
0030 if (!summaryCreator_) {
0031 summaryCreator_ = std::make_unique<SiStripSummaryCreator>();
0032 }
0033 auto const fpath = pSet_.getUntrackedParameter<std::string>(
0034 "SummaryConfigPath", "DQM/SiStripMonitorClient/data/sistrip_monitorelement_config.xml");
0035 return summaryCreator_->readConfiguration(fpath);
0036 }
0037
0038
0039
0040
0041 bool SiStripActionExecutor::readTkMapConfiguration(const SiStripDetCabling* detCabling,
0042 const TkDetMap* tkDetMap,
0043 const TrackerTopology* tTopo) {
0044 tkMapCreator_ = std::make_unique<SiStripTrackerMapCreator>(detCabling, tkDetMap, tTopo);
0045 return tkMapCreator_.get() != nullptr;
0046 }
0047
0048
0049
0050 void SiStripActionExecutor::createSummary(DQMStore& dqm_store) {
0051 if (!summaryCreator_)
0052 return;
0053
0054 dqm_store.cd();
0055 std::string dname = "SiStrip/MechanicalView";
0056 if (dqm_store.dirExists(dname)) {
0057 dqm_store.cd(dname);
0058 summaryCreator_->createSummary(dqm_store);
0059 }
0060 }
0061
0062
0063
0064 void SiStripActionExecutor::createSummaryOffline(DQMStore& dqm_store) {
0065 if (!summaryCreator_)
0066 return;
0067
0068 dqm_store.cd();
0069 std::string dname = "MechanicalView";
0070 if (SiStripUtility::goToDir(dqm_store, dname)) {
0071 summaryCreator_->createSummary(dqm_store);
0072 }
0073 dqm_store.cd();
0074 }
0075
0076
0077
0078 void SiStripActionExecutor::createTkMap(edm::ParameterSet const& tkmapPset,
0079 DQMStore& dqm_store,
0080 const std::string& map_type) {
0081 if (tkMapCreator_)
0082 tkMapCreator_->create(tkmapPset, dqm_store, map_type);
0083 }
0084
0085
0086
0087 void SiStripActionExecutor::createOfflineTkMap(edm::ParameterSet const& tkmapPset,
0088 DQMStore& dqm_store,
0089 std::string& map_type,
0090 const SiStripQuality* stripQuality) {
0091 if (tkMapCreator_)
0092 tkMapCreator_->createForOffline(tkmapPset, dqm_store, map_type, stripQuality);
0093 }
0094
0095
0096
0097 void SiStripActionExecutor::createTkInfoFile(std::vector<std::string> map_names,
0098 TTree* tkinfo_tree,
0099 DQMStore& dqm_store,
0100 const GeometricDet* geomDet) {
0101 if (!tkMapCreator_)
0102 return;
0103
0104 tkMapCreator_->createInfoFile(map_names, tkinfo_tree, dqm_store, geomDet);
0105 }
0106
0107
0108
0109 void SiStripActionExecutor::createStatus(DQMStore& dqm_store) {
0110 if (qualityChecker_.get() == nullptr) {
0111 qualityChecker_ = std::make_unique<SiStripQualityChecker>(pSet_);
0112 }
0113 qualityChecker_->bookStatus(dqm_store);
0114 }
0115
0116 void SiStripActionExecutor::fillDummyStatus() { qualityChecker_->fillDummyStatus(); }
0117
0118 void SiStripActionExecutor::fillStatus(DQMStore& dqm_store,
0119 const SiStripDetCabling* detcabling,
0120 const TkDetMap* tkDetMap,
0121 const TrackerTopology* tTopo) {
0122 qualityChecker_->fillStatus(dqm_store, detcabling, tkDetMap, tTopo);
0123 }
0124
0125 void SiStripActionExecutor::fillStatusAtLumi(DQMStore& dqm_store) { qualityChecker_->fillStatusAtLumi(dqm_store); }
0126
0127 void SiStripActionExecutor::createDummyShiftReport() {
0128 std::ofstream report_file;
0129 report_file.open("sistrip_shift_report.txt", std::ios::out);
0130 report_file << " Nothing to report!!" << std::endl;
0131 report_file.close();
0132 }
0133
0134 void SiStripActionExecutor::createShiftReport(DQMStore& dqm_store) {
0135
0136 std::string const localPath{"DQM/SiStripMonitorClient/data/sistrip_plot_layout.xml"};
0137 SiStripLayoutParser layout_parser;
0138 layout_parser.getDocument(edm::FileInPath(localPath).fullPath());
0139
0140 std::map<std::string, std::vector<std::string>> layout_map;
0141 if (!layout_parser.getAllLayouts(layout_map))
0142 return;
0143
0144 std::ostringstream shift_summary;
0145 configWriter_ = std::make_unique<SiStripConfigWriter>();
0146 configWriter_->init("ShiftReport");
0147
0148
0149 shift_summary << " Report Summary Content :\n"
0150 << " =========================" << std::endl;
0151 configWriter_->createElement("ReportSummary");
0152
0153 MonitorElement* me{nullptr};
0154 std::string report_path;
0155 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TECB";
0156 me = dqm_store.get(report_path);
0157 printReportSummary(me, shift_summary, "TECB");
0158
0159 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TECF";
0160 me = dqm_store.get(report_path);
0161 printReportSummary(me, shift_summary, "TECF");
0162
0163 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIB";
0164 me = dqm_store.get(report_path);
0165 printReportSummary(me, shift_summary, "TIB");
0166
0167 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIDB";
0168 me = dqm_store.get(report_path);
0169 printReportSummary(me, shift_summary, "TIDB");
0170
0171 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIDF";
0172 me = dqm_store.get(report_path);
0173 printReportSummary(me, shift_summary, "TIDF");
0174
0175 report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TOB";
0176 me = dqm_store.get(report_path);
0177 printReportSummary(me, shift_summary, "TOB");
0178
0179 shift_summary << std::endl;
0180 printShiftHistoParameters(dqm_store, layout_map, shift_summary);
0181
0182 std::ofstream report_file;
0183 report_file.open("sistrip_shift_report.txt", std::ios::out);
0184 report_file << shift_summary.str() << std::endl;
0185 report_file.close();
0186 configWriter_->write("sistrip_shift_report.xml");
0187 configWriter_.reset();
0188 }
0189
0190 void SiStripActionExecutor::printReportSummary(MonitorElement* me, std::ostringstream& str_val, std::string name) {
0191 str_val << " " << name << " : ";
0192 std::string value;
0193 SiStripUtility::getMEValue(me, value);
0194 configWriter_->createChildElement("MonitorElement", name, "value", value);
0195 float fvalue = atof(value.c_str());
0196 if (fvalue == -1.0)
0197 str_val << " Dummy Value " << std::endl;
0198 else
0199 str_val << fvalue << std::endl;
0200 }
0201
0202 void SiStripActionExecutor::printShiftHistoParameters(DQMStore& dqm_store,
0203 std::map<std::string, std::vector<std::string>> const& layout_map,
0204 std::ostringstream& str_val) {
0205 str_val << std::endl;
0206 for (auto const& [set_name, path_names] : layout_map) {
0207 if (set_name.find("Summary") != std::string::npos)
0208 continue;
0209 configWriter_->createElement(set_name);
0210
0211 str_val << " " << set_name << " : " << std::endl;
0212 str_val << " ====================================" << std::endl;
0213
0214 str_val << std::setprecision(2);
0215 str_val << setiosflags(std::ios::fixed);
0216 for (auto const& path_name : path_names) {
0217 if (path_name.empty())
0218 continue;
0219 MonitorElement* me = dqm_store.get(path_name);
0220 std::ostringstream entry_str, mean_str, rms_str;
0221 entry_str << std::setprecision(2);
0222 entry_str << setiosflags(std::ios::fixed);
0223 mean_str << std::setprecision(2);
0224 mean_str << setiosflags(std::ios::fixed);
0225 rms_str << std::setprecision(2);
0226 rms_str << setiosflags(std::ios::fixed);
0227 entry_str << std::setw(7) << me->getEntries();
0228 mean_str << std::setw(7) << me->getMean();
0229 rms_str << std::setw(7) << me->getRMS();
0230 configWriter_->createChildElement(
0231 "MonitorElement", me->getName(), "entries", entry_str.str(), "mean", mean_str.str(), "rms", rms_str.str());
0232
0233 if (me)
0234 str_val << " " << me->getName() << " : entries = " << std::setw(7) << me->getEntries()
0235 << " mean = " << me->getMean() << " : rms = " << me->getRMS() << '\n';
0236 }
0237 str_val << std::endl;
0238 }
0239 }
0240
0241
0242
0243
0244 void SiStripActionExecutor::printFaultyModuleList(DQMStore& dqm_store, std::ostringstream& str_val) {
0245 dqm_store.cd();
0246
0247 std::string mdir = "MechanicalView";
0248 if (!SiStripUtility::goToDir(dqm_store, mdir))
0249 return;
0250 std::string mechanicalview_dir = dqm_store.pwd();
0251
0252 std::vector<std::string> subdet_folder;
0253 subdet_folder.push_back("TIB");
0254 subdet_folder.push_back("TOB");
0255 subdet_folder.push_back("TEC/MINUS");
0256 subdet_folder.push_back("TEC/PLUS");
0257 subdet_folder.push_back("TID/MINUS");
0258 subdet_folder.push_back("TID/PLUS");
0259
0260 int nDetsTotal = 0;
0261 int nDetsWithErrorTotal = 0;
0262 for (auto const& sd : subdet_folder) {
0263 std::string dname = mechanicalview_dir + "/" + sd;
0264 if (!dqm_store.dirExists(dname))
0265 continue;
0266 str_val << "============\n" << sd << '\n' << "============\n" << std::endl;
0267
0268 dqm_store.cd(dname);
0269 std::vector<std::string> module_folders;
0270 SiStripUtility::getModuleFolderList(dqm_store, module_folders);
0271 int nDets = module_folders.size();
0272 dqm_store.cd();
0273
0274 int nDetsWithError = 0;
0275 std::string bad_module_folder = dname + "/" + "BadModuleList";
0276 if (dqm_store.dirExists(bad_module_folder)) {
0277 auto const meVec = dqm_store.getContents(bad_module_folder);
0278 for (auto me : meVec) {
0279 nDetsWithError++;
0280 uint16_t flag = me->getIntValue();
0281 std::string message;
0282 SiStripUtility::getBadModuleStatus(flag, message);
0283 str_val << me->getName() << " flag : " << me->getIntValue() << " " << message << std::endl;
0284 }
0285 }
0286 str_val << "---------------------------------------------------------------"
0287 "-----\n"
0288 << " Detectors : Total " << nDets << " with Error " << nDetsWithError << '\n'
0289 << "---------------------------------------------------------------"
0290 "-----\n";
0291 nDetsTotal += nDets;
0292 nDetsWithErrorTotal += nDetsWithError;
0293 }
0294 dqm_store.cd();
0295 str_val << "--------------------------------------------------------------------\n"
0296 << " Total Number of Connected Detectors : " << nDetsTotal << '\n'
0297 << " Total Number of Detectors with Error : " << nDetsWithErrorTotal << '\n'
0298 << "--------------------------------------------------------------------" << std::endl;
0299 }