CMS 3D CMS Logo

SiStripActionExecutor.cc
Go to the documentation of this file.
3 
5 
7 
11 
13 
14 #include <fstream>
15 #include <iomanip>
16 #include <iostream>
17 #include <sstream>
18 
20  edm::LogInfo("SiStripActionExecutor") << " Creating SiStripActionExecutor "
21  << "\n";
22 }
23 
25  edm::LogInfo("SiStripActionExecutor") << " Deleting SiStripActionExecutor "
26  << "\n";
27 }
28 
30  if (!summaryCreator_) {
31  summaryCreator_ = std::make_unique<SiStripSummaryCreator>();
32  }
33  auto const fpath = pSet_.getUntrackedParameter<std::string>(
34  "SummaryConfigPath", "DQM/SiStripMonitorClient/data/sistrip_monitorelement_config.xml");
35  return summaryCreator_->readConfiguration(fpath);
36 }
37 
38 //
39 // -- Read Configuration File
40 //
42  tkMapCreator_ = std::make_unique<SiStripTrackerMapCreator>(eSetup);
43  return tkMapCreator_.get() != nullptr;
44 }
45 //
46 // -- Create and Fill Summary Monitor Elements
47 //
49  if (!summaryCreator_)
50  return;
51 
52  dqm_store.cd();
53  std::string dname = "SiStrip/MechanicalView";
54  if (dqm_store.dirExists(dname)) {
55  dqm_store.cd(dname);
56  summaryCreator_->createSummary(dqm_store);
57  }
58 }
59 //
60 // -- Create and Fill Summary Monitor Elements
61 //
63  if (!summaryCreator_)
64  return;
65 
66  dqm_store.cd();
67  std::string dname = "MechanicalView";
68  if (SiStripUtility::goToDir(dqm_store, dname)) {
69  summaryCreator_->createSummary(dqm_store);
70  }
71  dqm_store.cd();
72 }
73 //
74 // -- create tracker map
75 //
77  DQMStore& dqm_store,
78  std::string& map_type,
79  edm::EventSetup const& eSetup) {
80  if (tkMapCreator_)
81  tkMapCreator_->create(tkmapPset, dqm_store, map_type, eSetup);
82 }
83 //
84 // -- create tracker map for offline
85 //
87  DQMStore& dqm_store,
88  std::string& map_type,
89  edm::EventSetup const& eSetup) {
90  if (tkMapCreator_)
91  tkMapCreator_->createForOffline(tkmapPset, dqm_store, map_type, eSetup);
92 }
93 //
94 // -- create root file with detId info from tracker maps
95 //
96 void SiStripActionExecutor::createTkInfoFile(std::vector<std::string> map_names,
97  TTree* tkinfo_tree,
98  DQMStore& dqm_store) {
99  if (!tkMapCreator_)
100  return;
101 
102  tkMapCreator_->createInfoFile(map_names, tkinfo_tree, dqm_store);
103 }
104 //
105 // -- Create Status Monitor Elements
106 //
108  if (qualityChecker_.get() == nullptr) {
109  qualityChecker_ = std::make_unique<SiStripQualityChecker>(pSet_);
110  }
111  qualityChecker_->bookStatus(dqm_store);
112 }
113 
115 
117  edm::ESHandle<SiStripDetCabling> const& detcabling,
118  edm::EventSetup const& eSetup) {
119  qualityChecker_->fillStatus(dqm_store, detcabling, eSetup);
120 }
121 
122 void SiStripActionExecutor::fillStatusAtLumi(DQMStore& dqm_store) { qualityChecker_->fillStatusAtLumi(dqm_store); }
123 
125  std::ofstream report_file;
126  report_file.open("sistrip_shift_report.txt", std::ios::out);
127  report_file << " Nothing to report!!" << std::endl;
128  report_file.close();
129 }
130 
132  // Read layout configuration
133  std::string const localPath{"DQM/SiStripMonitorClient/data/sistrip_plot_layout.xml"};
134  SiStripLayoutParser layout_parser;
135  layout_parser.getDocument(edm::FileInPath(localPath).fullPath());
136 
137  std::map<std::string, std::vector<std::string>> layout_map;
138  if (!layout_parser.getAllLayouts(layout_map))
139  return;
140 
141  std::ostringstream shift_summary;
142  configWriter_ = std::make_unique<SiStripConfigWriter>();
143  configWriter_->init("ShiftReport");
144 
145  // Print Report Summary Content
146  shift_summary << " Report Summary Content :\n"
147  << " =========================" << std::endl;
148  configWriter_->createElement("ReportSummary");
149 
150  MonitorElement* me{nullptr};
151  std::string report_path;
152  report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TECB";
153  me = dqm_store.get(report_path);
154  printReportSummary(me, shift_summary, "TECB");
155 
156  report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TECF";
157  me = dqm_store.get(report_path);
158  printReportSummary(me, shift_summary, "TECF");
159 
160  report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIB";
161  me = dqm_store.get(report_path);
162  printReportSummary(me, shift_summary, "TIB");
163 
164  report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIDB";
165  me = dqm_store.get(report_path);
166  printReportSummary(me, shift_summary, "TIDB");
167 
168  report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TIDF";
169  me = dqm_store.get(report_path);
170  printReportSummary(me, shift_summary, "TIDF");
171 
172  report_path = "SiStrip/EventInfo/reportSummaryContents/SiStrip_DetFraction_TOB";
173  me = dqm_store.get(report_path);
174  printReportSummary(me, shift_summary, "TOB");
175 
176  shift_summary << std::endl;
177  printShiftHistoParameters(dqm_store, layout_map, shift_summary);
178 
179  std::ofstream report_file;
180  report_file.open("sistrip_shift_report.txt", std::ios::out);
181  report_file << shift_summary.str() << std::endl;
182  report_file.close();
183  configWriter_->write("sistrip_shift_report.xml");
184  configWriter_.reset();
185 }
186 
188  str_val << " " << name << " : ";
190  SiStripUtility::getMEValue(me, value);
191  configWriter_->createChildElement("MonitorElement", name, "value", value);
192  float fvalue = atof(value.c_str());
193  if (fvalue == -1.0)
194  str_val << " Dummy Value " << std::endl;
195  else
196  str_val << fvalue << std::endl;
197 }
198 
200  std::map<std::string, std::vector<std::string>> const& layout_map,
201  std::ostringstream& str_val) {
202  str_val << std::endl;
203  for (auto const& [set_name, path_names] : layout_map) {
204  if (set_name.find("Summary") != std::string::npos)
205  continue;
206  configWriter_->createElement(set_name);
207 
208  str_val << " " << set_name << " : " << std::endl;
209  str_val << " ====================================" << std::endl;
210 
211  str_val << std::setprecision(2);
212  str_val << setiosflags(std::ios::fixed);
213  for (auto const& path_name : path_names) {
214  if (path_name.empty())
215  continue;
216  MonitorElement* me = dqm_store.get(path_name);
217  std::ostringstream entry_str, mean_str, rms_str;
218  entry_str << std::setprecision(2);
219  entry_str << setiosflags(std::ios::fixed);
220  mean_str << std::setprecision(2);
221  mean_str << setiosflags(std::ios::fixed);
222  rms_str << std::setprecision(2);
223  rms_str << setiosflags(std::ios::fixed);
224  entry_str << std::setw(7) << me->getEntries();
225  mean_str << std::setw(7) << me->getMean();
226  rms_str << std::setw(7) << me->getRMS();
227  configWriter_->createChildElement(
228  "MonitorElement", me->getName(), "entries", entry_str.str(), "mean", mean_str.str(), "rms", rms_str.str());
229 
230  if (me)
231  str_val << " " << me->getName() << " : entries = " << std::setw(7) << me->getEntries()
232  << " mean = " << me->getMean() << " : rms = " << me->getRMS() << '\n';
233  }
234  str_val << std::endl;
235  }
236 }
237 
238 //
239 // -- Print List of Modules with QTest warning or Error
240 //
241 void SiStripActionExecutor::printFaultyModuleList(DQMStore& dqm_store, std::ostringstream& str_val) {
242  dqm_store.cd();
243 
244  std::string mdir = "MechanicalView";
245  if (!SiStripUtility::goToDir(dqm_store, mdir))
246  return;
247  std::string mechanicalview_dir = dqm_store.pwd();
248 
249  std::vector<std::string> subdet_folder;
250  subdet_folder.push_back("TIB");
251  subdet_folder.push_back("TOB");
252  subdet_folder.push_back("TEC/MINUS");
253  subdet_folder.push_back("TEC/PLUS");
254  subdet_folder.push_back("TID/MINUS");
255  subdet_folder.push_back("TID/PLUS");
256 
257  int nDetsTotal = 0;
258  int nDetsWithErrorTotal = 0;
259  for (auto const& sd : subdet_folder) {
260  std::string dname = mechanicalview_dir + "/" + sd;
261  if (!dqm_store.dirExists(dname))
262  continue;
263  str_val << "============\n" << sd << '\n' << "============\n" << std::endl;
264 
265  dqm_store.cd(dname);
266  std::vector<std::string> module_folders;
267  SiStripUtility::getModuleFolderList(dqm_store, module_folders);
268  int nDets = module_folders.size();
269  dqm_store.cd();
270 
271  int nDetsWithError = 0;
272  std::string bad_module_folder = dname + "/" + "BadModuleList";
273  if (dqm_store.dirExists(bad_module_folder)) {
274  auto const meVec = dqm_store.getContents(bad_module_folder);
275  for (auto me : meVec) {
276  nDetsWithError++;
277  uint16_t flag = me->getIntValue();
278  std::string message;
279  SiStripUtility::getBadModuleStatus(flag, message);
280  str_val << me->getName() << " flag : " << me->getIntValue() << " " << message << std::endl;
281  }
282  }
283  str_val << "---------------------------------------------------------------"
284  "-----\n"
285  << " Detectors : Total " << nDets << " with Error " << nDetsWithError << '\n'
286  << "---------------------------------------------------------------"
287  "-----\n";
288  nDetsTotal += nDets;
289  nDetsWithErrorTotal += nDetsWithError;
290  }
291  dqm_store.cd();
292  str_val << "--------------------------------------------------------------------\n"
293  << " Total Number of Connected Detectors : " << nDetsTotal << '\n'
294  << " Total Number of Detectors with Error : " << nDetsWithErrorTotal << '\n'
295  << "--------------------------------------------------------------------" << std::endl;
296 }
T getUntrackedParameter(std::string const &, T const &) const
static void getModuleFolderList(DQMStore &dqm_store, std::vector< std::string > &m_ids)
std::unique_ptr< SiStripSummaryCreator > summaryCreator_
void createTkMap(const edm::ParameterSet &tkmapPset, DQMStore &dqm_store, std::string &map_type, const edm::EventSetup &eSetup)
void getDocument(std::string configFile, bool UseDB=false)
Methor that parses the xml file configFile.
void fillStatusAtLumi(DQMStore &dqm_store)
void createTkInfoFile(std::vector< std::string > tkhmap_names, TTree *tkinfo_tree, DQMStore &dqm_store)
std::vector< MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:1520
SiStripActionExecutor(edm::ParameterSet const &ps)
const std::string & getName() const
get name of ME
std::string const & pwd() const
Definition: DQMStore.cc:618
void createSummary(DQMStore &dqm_store)
bool readTkMapConfiguration(const edm::EventSetup &eSetup)
static void getBadModuleStatus(uint16_t flag, std::string &message)
void cd()
go to top directory (ie. root)
Definition: DQMStore.cc:621
std::unique_ptr< SiStripTrackerMapCreator > tkMapCreator_
void fillStatus(DQMStore &dqm_store, edm::ESHandle< SiStripDetCabling > const &fedcabling, edm::EventSetup const &eSetup)
static void getMEValue(MonitorElement const *me, std::string &val)
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1509
std::unique_ptr< SiStripQualityChecker > qualityChecker_
virtual double getEntries() const
get # of entries
edm::ParameterSet const pSet_
std::unique_ptr< SiStripConfigWriter > configWriter_
void printFaultyModuleList(DQMStore &dqm_store, std::ostringstream &str_val)
virtual double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
double sd
virtual double getRMS(int axis=1) const
get RMS of histogram along x, y or z axis (axis=1, 2, 3 respectively)
void createStatus(DQMStore &dqm_store)
static bool goToDir(DQMStore &dqm_store, std::string const &name)
void createSummaryOffline(DQMStore &dqm_store)
bool getAllLayouts(std::map< std::string, std::vector< std::string > > &me_names)
void printReportSummary(MonitorElement *me, std::ostringstream &str_val, std::string name)
void createShiftReport(DQMStore &dqm_store)
void createOfflineTkMap(const edm::ParameterSet &tkmapPset, DQMStore &dqm_store, std::string &map_type, const edm::EventSetup &eSetup)
void printShiftHistoParameters(DQMStore &dqm_store, std::map< std::string, std::vector< std::string >> const &layout_map, std::ostringstream &str_val)
bool dirExists(std::string const &path) const
true if directory exists
Definition: DQMStore.cc:698