CMS 3D CMS Logo

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