CMS 3D CMS Logo

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