CMS 3D CMS Logo

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 && (me->kind() == MonitorElement::Kind::REAL || me->kind() == MonitorElement::Kind::INT)) {
242  val = me->valueString();
243  val = val.substr(val.find("=") + 1);
244  }
245 }
246 //
247 // -- go to a given Directory
248 //
250  std::string currDir = dqm_store.pwd();
251  std::string dirName = currDir.substr(currDir.find_last_of("/") + 1);
252  if (dirName.find(name) == 0) {
253  return true;
254  }
255  auto const subdirs = dqm_store.getSubdirs();
256  for (auto const& fname : subdirs) {
257  if ((fname.find("Reference") != std::string::npos) || (fname.find("AlCaReco") != std::string::npos) ||
258  (fname.find("HLT") != std::string::npos) || (fname.find("IsolatedBunches") != std::string::npos))
259  continue;
260  dqm_store.cd(fname);
261  if (!goToDir(dqm_store, name)) {
262  dqm_store.goUp();
263  } else {
264  return true;
265  }
266  }
267  return false;
268 }
269 
271  std::string currDir = ibooker.pwd();
272  std::string dirName = currDir.substr(currDir.find_last_of("/") + 1);
273  if (dirName.find(name) == 0) {
274  return true;
275  }
276  auto const subdirs = igetter.getSubdirs();
277  for (auto const& fname : subdirs) {
278  if ((fname.find("Reference") != std::string::npos) || (fname.find("AlCaReco") != std::string::npos) ||
279  (fname.find("HLT") != std::string::npos) || (fname.find("IsolatedBunches") != std::string::npos))
280  continue;
281  igetter.cd(fname);
282  if (!goToDir(ibooker, igetter, name)) {
283  ibooker.goUp();
284  } else
285  return true;
286  }
287  return false;
288 }
289 
290 //
291 // -- Get Sub Detector tag from DetId
292 //
293 void SiStripUtility::getSubDetectorTag(uint32_t const det_id, std::string& subdet_tag, const TrackerTopology* tTopo) {
294  StripSubdetector const subdet(det_id);
295  subdet_tag = "";
296  switch (subdet.subdetId()) {
297  case StripSubdetector::TIB: {
298  subdet_tag = "TIB";
299  return;
300  }
301  case StripSubdetector::TID: {
302  if (tTopo->tidSide(det_id) == 2) {
303  subdet_tag = "TIDF";
304  } else if (tTopo->tidSide(det_id) == 1) {
305  subdet_tag = "TIDB";
306  }
307  return;
308  }
309  case StripSubdetector::TOB: {
310  subdet_tag = "TOB";
311  return;
312  }
313  case StripSubdetector::TEC: {
314  if (tTopo->tecSide(det_id) == 2) {
315  subdet_tag = "TECF";
316  } else if (tTopo->tecSide(det_id) == 1) {
317  subdet_tag = "TECB";
318  }
319  }
320  }
321 }
322 //
323 // -- Set Bad Channel Flag from hname
324 //
325 void SiStripUtility::setBadModuleFlag(std::string& hname, uint16_t& flg) {
326  if (hname.find("FractionOfBadChannels") != std::string::npos)
327  flg |= (1 << 0);
328  else if (hname.find("NumberOfDigi") != std::string::npos)
329  flg |= (1 << 1);
330  else if (hname.find("NumberOfCluster") != std::string::npos)
331  flg |= (1 << 2);
332  else if (hname.find("ExcludedFedChannel") != std::string::npos)
333  flg |= (1 << 3);
334  else if (hname.find("DCSError") != std::string::npos)
335  flg |= (1 << 4);
336 }
337 //
338 // -- Get the Status Message from Bad Module Flag
339 //
341  if (flag == 0)
342  message += " No Error";
343  else {
344  if (((flag >> 0) & 0x1) > 0)
345  message += " Fed BadChannel : ";
346  if (((flag >> 1) & 0x1) > 0)
347  message += " # of Digi : ";
348  if (((flag >> 2) & 0x1) > 0)
349  message += " # of Clusters :";
350  if (((flag >> 3) & 0x1) > 0)
351  message += " Excluded FED Channel ";
352  if (((flag >> 4) & 0x1) > 0)
353  message += " DCSError ";
354  }
355 }
356 //
357 // -- Set Event Info Folder
358 //
360  path = "";
361  dqm_store.cd();
362  if (dqm_store.dirExists(top_dir)) {
363  dqm_store.cd(top_dir);
364  path = dqm_store.pwd();
365  } else {
366  if (SiStripUtility::goToDir(dqm_store, top_dir)) {
367  std::string mdir = "MechanicalView";
368  if (SiStripUtility::goToDir(dqm_store, mdir)) {
369  path = dqm_store.pwd();
370  path = path.substr(0, path.find(mdir) - 1);
371  }
372  }
373  }
374 }
375 
377  DQMStore::IGetter& igetter,
378  std::string const& top_dir,
379  std::string& path) {
380  path = "";
381  ibooker.cd();
382  if (igetter.dirExists(top_dir)) {
383  ibooker.cd(top_dir);
384  path = ibooker.pwd();
385  } else {
386  if (SiStripUtility::goToDir(ibooker, igetter, top_dir)) {
387  std::string tdir = "MechanicalView";
388  if (SiStripUtility::goToDir(ibooker, igetter, tdir)) {
389  path = ibooker.pwd();
390  path = path.substr(0, path.find(tdir) - 1);
391  }
392  }
393  }
394 }
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
static constexpr auto TEC
void goUp()
equivalent to "cd .."
Definition: DQMStore.cc:648
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
static void getDetectorStatusColor(int status, int &rval, int &gval, int &bval)
Kind kind() const
Get the type of the monitor element.
std::string const & pwd() const
Definition: DQMStore.cc:618
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)
void cd()
go to top directory (ie. root)
Definition: DQMStore.cc:621
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
bool dirExists(std::string const &path)
Definition: DQMStore.cc:461
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
Definition: value.py:1
static constexpr auto TOB
std::vector< QReport * > getQReports() const
get map of QReports
unsigned long long int rval
Definition: vlib.h:21
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=" ")
std::string valueString() const
std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:1466
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)
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
bool dirExists(std::string const &path) const
true if directory exists
Definition: DQMStore.cc:698
std::vector< std::string > getSubdirs()
Definition: DQMStore.cc:453