CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripUtility.cc
Go to the documentation of this file.
3 
6 
7 //
8 // Get a list of MEs in a folder
9 //
10 int SiStripUtility::getMEList(std::string const& name, std::vector<std::string>& values) {
11  values.clear();
12  auto prefix_str = name.substr(0, (name.find(':')));
13  prefix_str += "/";
14  auto const temp_str = name.substr(name.find(':') + 1);
15  split(temp_str, values, ",");
16  for (auto& value : values) {
17  value.insert(0, prefix_str);
18  }
19  return values.size();
20 }
21 //
22 // Get a list of MEs in a folder and the path name
23 //
24 int SiStripUtility::getMEList(std::string const& name, std::string& dir_path, std::vector<std::string>& values) {
25  values.clear();
26  dir_path = name.substr(0, (name.find(':')));
27  dir_path += "/";
28  auto const temp_str = name.substr(name.find(':') + 1);
29  split(temp_str, values, ",");
30  return values.size();
31 }
32 
33 // Check if the requested ME exists in a folder
34 bool SiStripUtility::checkME(std::string const& name, std::string const& me_name, std::string& full_path) {
35  if (name.find(name) == std::string::npos)
36  return false;
37  auto prefix_str = name.substr(0, (name.find(':')));
38  prefix_str += "/";
39  auto const temp_str = name.substr(name.find(':') + 1);
40  std::vector<std::string> values;
41  split(temp_str, values, ",");
42  for (auto const& value : values) {
43  if (value.find(me_name) != std::string::npos) {
44  full_path = prefix_str + value;
45  return true;
46  }
47  }
48  return false;
49 }
50 //
51 // -- Split a given string into a number of strings using given
52 // delimiters and fill a vector with splitted strings
53 //
54 void SiStripUtility::split(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters) {
55  // Skip delimiters at beginning.
56  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
57 
58  // Find first "non-delimiter".
59  std::string::size_type pos = str.find_first_of(delimiters, lastPos);
60 
61  while (std::string::npos != pos || std::string::npos != lastPos) {
62  // Found a token, add it to the std::vector.
63  tokens.push_back(str.substr(lastPos, pos - lastPos));
64 
65  // Skip delimiters. Note the "not_of"
66  lastPos = str.find_first_not_of(delimiters, pos);
67 
68  // Find next "non-delimiter"
69  pos = str.find_first_of(delimiters, lastPos);
70  }
71 }
72 //
73 // -- Get Color code from Status
74 //
75 void SiStripUtility::getMEStatusColor(int status, int& rval, int& gval, int& bval) {
76  if (status == dqm::qstatus::STATUS_OK) {
77  rval = 0;
78  gval = 255;
79  bval = 0;
80  } else if (status == dqm::qstatus::WARNING) {
81  rval = 255;
82  gval = 255;
83  bval = 0;
84  } else if (status == dqm::qstatus::ERROR) {
85  rval = 255;
86  gval = 0;
87  bval = 0;
88  } else if (status == dqm::qstatus::OTHER) {
89  rval = 255;
90  gval = 150;
91  bval = 0;
92  } else {
93  rval = 0;
94  gval = 0;
95  bval = 255;
96  }
97 }
98 //
99 // -- Get Color code from Status
100 //
102  if (status == dqm::qstatus::STATUS_OK) {
103  tag = "Ok";
104  icol = 3;
105  } else if (status == dqm::qstatus::WARNING) {
106  tag = "Warning";
107  icol = 5;
108  } else if (status == dqm::qstatus::ERROR) {
109  tag = "Error";
110  icol = 2;
111  } else if (status == dqm::qstatus::OTHER) {
112  tag = "Other";
113  icol = 1;
114  } else {
115  tag = " ";
116  icol = 1;
117  }
118 }
119 //
120 // -- Get Color code from Status
121 //
122 void SiStripUtility::getDetectorStatusColor(int status, int& rval, int& gval, int& bval) {
123  // No Error
124  if (status == 0) {
125  rval = 0;
126  gval = 255;
127  bval = 0;
128  return;
129  }
130  // Error detected in FED Channel
131  if (((status >> 0) & 0x1) > 0) {
132  rval = 150;
133  gval = 0;
134  bval = 0;
135  return;
136  }
137  // Excluded FED Channel
138  if (((status >> 3) & 0x1) > 0) {
139  rval = 100;
140  gval = 100;
141  bval = 255;
142  return;
143  }
144  // DCS Error
145  if (((status >> 4) & 0x1) > 0) {
146  rval = 200;
147  gval = 20;
148  bval = 255;
149  return;
150  }
151  // Digi and Cluster Problem
152  if (((status >> 1) & 0x1) > 0) {
153  rval = 255;
154  bval = 0;
155  if (((status >> 2) & 0x1) > 0)
156  gval = 0;
157  else
158  gval = 100;
159  } else {
160  rval = 251;
161  gval = 0;
162  bval = 100;
163  }
164 }
165 
166 //
167 // -- Get Status of Monitor Element
168 //
170  int status = 0;
171  if (me->getQReports().empty()) {
172  return status;
173  } else if (me->hasError()) {
174  status = dqm::qstatus::ERROR;
175  } else if (me->hasWarning()) {
176  status = dqm::qstatus::WARNING;
177  } else if (me->hasOtherReport()) {
178  status = dqm::qstatus::OTHER;
179  } else {
180  status = dqm::qstatus::STATUS_OK;
181  }
182  return status;
183 }
184 //
185 // -- Fill Module Names
186 //
187 void SiStripUtility::getModuleFolderList(DQMStore& dqm_store, std::vector<std::string>& mfolders) {
188  if (auto currDir = dqm_store.pwd(); currDir.find("module_") != std::string::npos) {
189  mfolders.push_back(currDir);
190  } else {
191  auto const subdirs = dqm_store.getSubdirs();
192  for (auto const& subdir : subdirs) {
193  dqm_store.cd(subdir);
194  getModuleFolderList(dqm_store, mfolders);
195  dqm_store.goUp();
196  }
197  }
198 }
199 
201  DQMStore::IGetter& igetter,
202  std::vector<std::string>& mfolders) {
203  if (auto currDir = ibooker.pwd(); currDir.find("module_") != std::string::npos) {
204  mfolders.push_back(currDir);
205  } else {
206  auto const subdirs = igetter.getSubdirs();
207  for (auto const& subdir : subdirs) {
208  ibooker.cd(subdir);
209  getModuleFolderList(ibooker, igetter, mfolders);
210  ibooker.goUp();
211  }
212  }
213 }
214 //
215 // -- Get Status of Monitor Element
216 //
217 int SiStripUtility::getMEStatus(MonitorElement const* me, int& bad_channels) {
218  int status = 0;
219  if (me->getQReports().empty()) {
220  bad_channels = -1;
221  } else {
222  std::vector<QReport*> qreports = me->getQReports();
223  bad_channels = qreports[0]->getBadChannels().size();
224  if (me->hasError()) {
225  status = dqm::qstatus::ERROR;
226  } else if (me->hasWarning()) {
227  status = dqm::qstatus::WARNING;
228  } else if (me->hasOtherReport()) {
229  status = dqm::qstatus::OTHER;
230  } else {
231  status = dqm::qstatus::STATUS_OK;
232  }
233  }
234  return status;
235 }
236 //
237 // -- Get Status of Monitor Element
238 //
240  val = "";
241  if (me) {
242  if (me->kind() == MonitorElement::Kind::REAL) {
243  val = std::to_string(me->getFloatValue());
244  } else if (me->kind() == MonitorElement::Kind::INT) {
245  val = std::to_string(me->getIntValue());
246  }
247  }
248 }
249 //
250 // -- go to a given Directory
251 //
253  std::string currDir = dqm_store.pwd();
254  std::string dirName = currDir.substr(currDir.find_last_of('/') + 1);
255  if (dirName.find(name) == 0) {
256  return true;
257  }
258  auto const subdirs = dqm_store.getSubdirs();
259  for (auto const& fname : subdirs) {
260  if ((fname.find("Reference") != std::string::npos) || (fname.find("AlCaReco") != std::string::npos) ||
261  (fname.find("HLT") != std::string::npos) || (fname.find("IsolatedBunches") != std::string::npos))
262  continue;
263  dqm_store.cd(fname);
264  if (!goToDir(dqm_store, name)) {
265  dqm_store.goUp();
266  } else {
267  return true;
268  }
269  }
270  return false;
271 }
272 
274  std::string currDir = ibooker.pwd();
275  std::string dirName = currDir.substr(currDir.find_last_of('/') + 1);
276  if (dirName.find(name) == 0) {
277  return true;
278  }
279  auto const subdirs = igetter.getSubdirs();
280  for (auto const& fname : subdirs) {
281  if ((fname.find("Reference") != std::string::npos) || (fname.find("AlCaReco") != std::string::npos) ||
282  (fname.find("HLT") != std::string::npos) || (fname.find("IsolatedBunches") != std::string::npos))
283  continue;
284  igetter.cd(fname);
285  if (!goToDir(ibooker, igetter, name)) {
286  ibooker.goUp();
287  } else
288  return true;
289  }
290  return false;
291 }
292 
293 //
294 // -- Get Sub Detector tag from DetId
295 //
296 void SiStripUtility::getSubDetectorTag(uint32_t const det_id, std::string& subdet_tag, const TrackerTopology* tTopo) {
297  StripSubdetector const subdet(det_id);
298  subdet_tag = "";
299  switch (subdet.subdetId()) {
300  case StripSubdetector::TIB: {
301  subdet_tag = "TIB";
302  return;
303  }
304  case StripSubdetector::TID: {
305  if (tTopo->tidSide(det_id) == 2) {
306  subdet_tag = "TIDF";
307  } else if (tTopo->tidSide(det_id) == 1) {
308  subdet_tag = "TIDB";
309  }
310  return;
311  }
312  case StripSubdetector::TOB: {
313  subdet_tag = "TOB";
314  return;
315  }
316  case StripSubdetector::TEC: {
317  if (tTopo->tecSide(det_id) == 2) {
318  subdet_tag = "TECF";
319  } else if (tTopo->tecSide(det_id) == 1) {
320  subdet_tag = "TECB";
321  }
322  }
323  }
324 }
325 //
326 // -- Set Bad Channel Flag from hname
327 //
328 void SiStripUtility::setBadModuleFlag(std::string& hname, uint16_t& flg) {
329  if (hname.find("FractionOfBadChannels") != std::string::npos)
330  flg |= (1 << 0);
331  else if (hname.find("NumberOfDigi") != std::string::npos)
332  flg |= (1 << 1);
333  else if (hname.find("NumberOfCluster") != std::string::npos)
334  flg |= (1 << 2);
335  else if (hname.find("ExcludedFedChannel") != std::string::npos)
336  flg |= (1 << 3);
337  else if (hname.find("DCSError") != std::string::npos)
338  flg |= (1 << 4);
339 }
340 //
341 // -- Get the Status Message from Bad Module Flag
342 //
343 void SiStripUtility::getBadModuleStatus(uint16_t flag, std::string& message) {
344  if (flag == 0)
345  message += " No Error";
346  else {
347  if (((flag >> 0) & 0x1) > 0)
348  message += " Fed BadChannel : ";
349  if (((flag >> 1) & 0x1) > 0)
350  message += " # of Digi : ";
351  if (((flag >> 2) & 0x1) > 0)
352  message += " # of Clusters :";
353  if (((flag >> 3) & 0x1) > 0)
354  message += " Excluded FED Channel ";
355  if (((flag >> 4) & 0x1) > 0)
356  message += " DCSError ";
357  }
358 }
359 //
360 // -- Set Event Info Folder
361 //
363  path = "";
364  dqm_store.cd();
365  if (dqm_store.dirExists(top_dir)) {
366  dqm_store.cd(top_dir);
367  path = dqm_store.pwd();
368  } else {
369  if (SiStripUtility::goToDir(dqm_store, top_dir)) {
370  std::string mdir = "MechanicalView";
371  if (SiStripUtility::goToDir(dqm_store, mdir)) {
372  path = dqm_store.pwd();
373  path = path.substr(0, path.find(mdir) - 1);
374  }
375  }
376  }
377 }
378 
380  DQMStore::IGetter& igetter,
381  std::string const& top_dir,
382  std::string& path) {
383  path = "";
384  ibooker.cd();
385  if (igetter.dirExists(top_dir)) {
386  ibooker.cd(top_dir);
387  path = ibooker.pwd();
388  } else {
389  if (SiStripUtility::goToDir(ibooker, igetter, top_dir)) {
390  std::string tdir = "MechanicalView";
391  if (SiStripUtility::goToDir(ibooker, igetter, tdir)) {
392  path = ibooker.pwd();
393  path = path.substr(0, path.find(tdir) - 1);
394  }
395  }
396  }
397 }
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
static constexpr auto TEC
static void getModuleFolderList(DQMStore &dqm_store, std::vector< std::string > &m_ids)
static const int OTHER
static int getMEList(std::string const &name, std::vector< std::string > &values)
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:700
virtual std::string pwd()
Definition: DQMStore.cc:16
virtual int64_t getIntValue() const
list status
Definition: mps_update.py:107
static const int WARNING
static void getDetectorStatusColor(int status, int &rval, int &gval, int &bval)
Kind kind() const
Get the type of the monitor element.
std::string to_string(const V &value)
Definition: OMSAccess.h:71
virtual bool dirExists(std::string const &path) const
Definition: DQMStore.cc:730
std::string pwd() override
Definition: DQMStore.h:644
bool hasOtherReport() const
true if at least of one of the tests returned some other (non-ok) status
static void getBadModuleStatus(uint16_t flag, std::string &message)
uint16_t size_type
static void getMEValue(MonitorElement const *me, std::string &val)
bool hasWarning() const
true if at least of one of the quality tests returned a warning
std::vector< MonitorElementData::QReport * > getQReports() const
get map of QReports
unsigned int tidSide(const DetId &id) const
const std::string subdet_tag("SubDet")
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr auto TOB
static constexpr auto TIB
static void getMEStatusColor(int status, int &rval, int &gval, int &bval)
bool hasError() const
true if at least of one of the quality tests returned an error
static void split(std::string const &str, std::vector< std::string > &tokens, std::string const &delimiters=" ")
string fname
main script
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
virtual double getFloatValue() const
static bool goToDir(DQMStore &dqm_store, std::string const &name)
static const int STATUS_OK
static bool checkME(std::string const &element, std::string const &name, std::string &full_path)
static int getMEStatus(MonitorElement const *me)
#define str(s)
static constexpr auto TID
static void getTopFolderPath(DQMStore &dqm_store, std::string const &top_dir, std::string &path)
static const int ERROR
unsigned int tecSide(const DetId &id) const