CMS 3D CMS Logo

SiPixelUtility.cc
Go to the documentation of this file.
4 #include <cstdlib>
5 
6 using namespace std;
7 //
8 // Get a list of MEs in a folder
9 //
10 int SiPixelUtility::getMEList(string name, vector<string> &values) {
11  values.clear();
12  string prefix_str = name.substr(0, (name.find(":")));
13  prefix_str += "/";
14  string temp_str = name.substr(name.find(":") + 1);
15  split(temp_str, values, ",");
16  for (vector<string>::iterator it = values.begin(); it != values.end(); it++)
17  (*it).insert(0, prefix_str);
18  return values.size();
19 }
20 //
21 // Get a list of MEs in a folder and the path name
22 //
23 int SiPixelUtility::getMEList(string name, string &dir_path, vector<string> &values) {
24  values.clear();
25  dir_path = name.substr(0, (name.find(":")));
26  dir_path += "/";
27  string temp_str = name.substr(name.find(":") + 1);
28  split(temp_str, values, ",");
29  return values.size();
30 }
31 
32 // Check if the requested ME exists in a folder
33 bool SiPixelUtility::checkME(string name, string me_name, string &full_path) {
34  if (name.find(name) == string::npos)
35  return false;
36  string prefix_str = name.substr(0, (name.find(":")));
37  prefix_str += "/";
38  string temp_str = name.substr(name.find(":") + 1);
39  vector<string> values;
40  split(temp_str, values, ",");
41  for (vector<string>::iterator it = values.begin(); it != values.end(); it++) {
42  if ((*it).find(me_name) != string::npos) {
43  full_path = prefix_str + (*it);
44  return true;
45  }
46  }
47  return false;
48 }
49 //
50 // -- Split a given string into a number of strings using given
51 // delimiters and fill a vector with splitted strings
52 //
53 void SiPixelUtility::split(const string &str, vector<string> &tokens, const string &delimiters) {
54  // Skip delimiters at beginning.
55  string::size_type lastPos = str.find_first_not_of(delimiters, 0);
56 
57  // Find first "non-delimiter".
58  string::size_type pos = str.find_first_of(delimiters, lastPos);
59 
60  while (string::npos != pos || string::npos != lastPos) {
61  // Found a token, add it to the vector.
62  tokens.push_back(str.substr(lastPos, pos - lastPos));
63 
64  // Skip delimiters. Note the "not_of"
65  lastPos = str.find_first_not_of(delimiters, pos);
66 
67  // Find next "non-delimiter"
68  pos = str.find_first_of(delimiters, lastPos);
69  }
70 }
71 //
72 // -- Get Color code from Status
73 //
74 void SiPixelUtility::getStatusColor(int status, int &rval, int &gval, int &bval) {
75  if (status == dqm::qstatus::STATUS_OK) {
76  rval = 0;
77  gval = 255;
78  bval = 0;
79  } else if (status == dqm::qstatus::WARNING) {
80  rval = 255;
81  gval = 255;
82  bval = 0;
83  } else if (status == dqm::qstatus::ERROR) {
84  rval = 255;
85  gval = 0;
86  bval = 0;
87  } else if (status == dqm::qstatus::OTHER) {
88  rval = 255;
89  gval = 150;
90  bval = 0;
91  } else {
92  rval = 0;
93  gval = 0;
94  bval = 255;
95  }
96 }
97 //
98 // -- Get Color code from Status
99 //
100 void SiPixelUtility::getStatusColor(int status, int &icol, string &tag) {
101  if (status == dqm::qstatus::STATUS_OK) {
102  tag = "Ok";
103  icol = 3;
104  } else if (status == dqm::qstatus::WARNING) {
105  tag = "Warning";
106  icol = 5;
107  } else if (status == dqm::qstatus::ERROR) {
108  tag = "Error";
109  icol = 2;
110  } else if (status == dqm::qstatus::OTHER) {
111  tag = "Other";
112  icol = 1;
113  } else {
114  tag = " ";
115  icol = 1;
116  }
117 }
118 //
119 // -- Get Color code from Status
120 //
121 void SiPixelUtility::getStatusColor(double status, int &rval, int &gval, int &bval) {
122  rval = SiPixelContinuousPalette::r[(int)(status * 100)];
123  gval = SiPixelContinuousPalette::g[(int)(status * 100)];
124  bval = SiPixelContinuousPalette::b[(int)(status * 100)];
125 }
126 //
127 // -- Get Status of Monitor Element
128 //
130  int status = 0;
131  if (me->getQReports().empty()) {
132  status = 0;
133  } else if (me->hasError()) {
134  status = dqm::qstatus::ERROR;
135  } else if (me->hasWarning()) {
136  status = dqm::qstatus::WARNING;
137  } else if (me->hasOtherReport()) {
138  status = dqm::qstatus::OTHER;
139  } else {
140  status = dqm::qstatus::STATUS_OK;
141  }
142  return status;
143 }
144 
146  vector<string> qtestNameList;
147  return qtestNameList;
148 }
149 
151  int code = 0;
152  switch (status) {
154  code = 1;
155  break;
157  code = 2;
158  break;
159  case dqm::qstatus::ERROR:
160  code = 3;
161  break;
162  } // end switch
163 
164  return code;
165 }
166 
167 int SiPixelUtility::computeErrorCode(DQMStore *bei, string &module_path) {
168  int status = bei->getStatus(module_path);
169 
170  int code = -1;
171  switch (status) {
173  code = 0;
174  break;
176  code = 1;
177  break;
179  code = 2;
180  break;
181  case dqm::qstatus::ERROR:
182  code = 3;
183  break;
184  } // end of switch
185 
186  return code;
187 }
188 
189 int SiPixelUtility::computeHistoBin(string &module_path) {
190  int module_bin = 0;
191 
192  int module = 0;
193  int shell = 0;
194  int layer = 0;
195  int ladder = 0;
196  int halfcylinder = 0;
197  int disk = 0;
198  int blade = 0;
199  int panel = 0;
200 
201  int nbinShell = 192;
202  int nbinLayer = 0;
203  int nbinLadder = 4;
204 
205  int nbinHalfcylinder = 168;
206  int nbinDisk = 84;
207  int nbinBlade = 7;
208  int nbinPanel = 0;
209 
210  vector<string> subDirVector;
211  SiPixelUtility::split(module_path, subDirVector, "/");
212 
213  for (vector<string>::const_iterator it = subDirVector.begin(); it != subDirVector.end(); it++) {
214  if ((*it).find("Collector") != string::npos ||
215  //(*it).find("Collated") != string::npos ||
216  (*it).find("FU") != string::npos || (*it).find("Pixel") != string::npos ||
217  (*it).find("Barrel") != string::npos || (*it).find("Endcap") != string::npos)
218  continue;
219 
220  if ((*it).find("Module") != string::npos) {
221  module = atoi((*it).substr((*it).find("_") + 1).c_str());
222  }
223 
224  if ((*it).find("Shell") != string::npos) {
225  if ((*it).find("mI") != string::npos)
226  shell = 1;
227  if ((*it).find("mO") != string::npos)
228  shell = 2;
229  if ((*it).find("pI") != string::npos)
230  shell = 3;
231  if ((*it).find("pO") != string::npos)
232  shell = 4;
233  }
234  if ((*it).find("Layer") != string::npos) {
235  layer = atoi((*it).substr((*it).find("_") + 1).c_str());
236  if (layer == 1) {
237  nbinLayer = 0;
238  }
239  if (layer == 2) {
240  nbinLayer = 40;
241  }
242  if (layer == 3) {
243  nbinLayer = 40 + 64;
244  }
245  }
246  if ((*it).find("Ladder") != string::npos) {
247  ladder = atoi((*it).substr((*it).find("_") + 1, 2).c_str());
248  }
249  if ((*it).find("HalfCylinder") != string::npos) {
250  if ((*it).find("mI") != string::npos)
251  halfcylinder = 1;
252  if ((*it).find("mO") != string::npos)
253  halfcylinder = 2;
254  if ((*it).find("pI") != string::npos)
255  halfcylinder = 3;
256  if ((*it).find("pO") != string::npos)
257  halfcylinder = 4;
258  }
259  if ((*it).find("Disk") != string::npos) {
260  disk = atoi((*it).substr((*it).find("_") + 1).c_str());
261  }
262  if ((*it).find("Blade") != string::npos) {
263  blade = atoi((*it).substr((*it).find("_") + 1, 2).c_str());
264  }
265  if ((*it).find("Panel") != string::npos) {
266  panel = atoi((*it).substr((*it).find("_") + 1).c_str());
267  if (panel == 1)
268  nbinPanel = 0;
269  if (panel == 2)
270  nbinPanel = 4;
271  }
272  }
273  if (module_path.find("Barrel") != string::npos) {
274  module_bin = module + (ladder - 1) * nbinLadder + nbinLayer + (shell - 1) * nbinShell;
275  }
276  if (module_path.find("Endcap") != string::npos) {
277  module_bin = module + (panel - 1) * nbinPanel + (blade - 1) * nbinBlade + (disk - 1) * nbinDisk +
278  (halfcylinder - 1) * nbinHalfcylinder;
279  }
280 
281  return module_bin;
282 
283  // cout << "leaving SiPixelInformationExtractor::computeHistoBin" << endl;
284 }
285 
286 void SiPixelUtility::fillPaveText(TPaveText *pave, const map<string, pair<int, double>> &messages) {
287  TText *sourceCodeOnCanvas;
288  for (map<string, pair<int, double>>::const_iterator it = messages.begin(); it != messages.end(); it++) {
289  string message = it->first;
290  int color = (it->second).first;
291  double size = (it->second).second;
292  sourceCodeOnCanvas = pave->AddText(message.c_str());
293  sourceCodeOnCanvas->SetTextColor(color);
294  sourceCodeOnCanvas->SetTextSize(size);
295  sourceCodeOnCanvas->SetTextFont(112);
296  }
297 }
298 
299 map<string, string> SiPixelUtility::sourceCodeMap() {
300  map<string, string> sourceCode;
301  for (int iSource = 0; iSource < 5; iSource++) {
302  string type;
303  string code;
304  switch (iSource) {
305  case 0:
306  type = "RAW";
307  code = "1 ";
308  break;
309  case 1:
310  type = "DIG";
311  code = "10 ";
312  break;
313  case 2:
314  type = "CLU";
315  code = "100 ";
316  break;
317  case 3:
318  type = "TRK";
319  code = "1000 ";
320  break;
321  case 4:
322  type = "REC";
323  code = "10000";
324  break;
325  } // end of switch
326  sourceCode[type] = code;
327  }
328  return sourceCode;
329 }
330 
331 void SiPixelUtility::createStatusLegendMessages(map<string, pair<int, double>> &messages) {
332  for (int iStatus = 1; iStatus < 5; iStatus++) {
333  pair<int, double> color_size;
334  int color = 1;
335  double size = 0.03;
336  string code;
337  string type;
338  color_size.second = size;
339  switch (iStatus) {
340  case 1:
341  code = "1";
342  type = "INSUF_STAT";
343  color = kBlue;
344  break;
345  case 2:
346  code = "2";
347  type = "WARNING(S)";
348  color = kYellow;
349  break;
350  case 3:
351  code = "3";
352  type = "ERROR(S) ";
353  color = kRed;
354  break;
355  case 4:
356  code = "4";
357  type = "ERRORS ";
358  color = kMagenta;
359  break;
360  } // end of switch
361  string messageString = code + ": " + type;
362  color_size.first = color;
363  messages[messageString] = color_size;
364  }
365 }
366 
367 //------------------------------------------------------------------------------
368 //
369 // -- Set Drawing Option
370 //
371 void SiPixelUtility::setDrawingOption(TH1 *hist, float xlow, float xhigh) {
372  if (!hist)
373  return;
374 
375  TAxis *xa = hist->GetXaxis();
376  TAxis *ya = hist->GetYaxis();
377 
378  xa->SetTitleOffset(0.7);
379  xa->SetTitleSize(0.06);
380  xa->SetLabelSize(0.04);
381  // xa->SetLabelColor(0);
382 
383  ya->SetTitleOffset(0.7);
384  ya->SetTitleSize(0.06);
385 
386  if (xlow != -1 && xhigh != -1.0) {
387  xa->SetRangeUser(xlow, xhigh);
388  }
389 }
size
Write out results.
std::vector< std::string_view > split(std::string_view, const char *)
type
Definition: HCALResponse.h:21
static const int OTHER
static int getMEList(std::string name, std::vector< std::string > &values)
static const int WARNING
static bool checkME(std::string element, std::string name, std::string &full_path)
bool hasOtherReport() const
true if at least of one of the tests returned some other (non-ok) status
static std::map< std::string, std::string > sourceCodeMap()
static void split(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
uint16_t size_type
static int computeHistoBin(std::string &module_path)
int getStatus(std::string const &path="") const
Definition: DQMStore.cc:2903
U second(std::pair< T, U > const &p)
static void setDrawingOption(TH1 *hist, float xlow=-1., float xhigh=-1.)
bool hasWarning() const
true if at least of one of the quality tests returned a warning
static int getStatus(MonitorElement *me)
static const int INSUF_STAT
static void fillPaveText(TPaveText *pave, const std::map< std::string, std::pair< int, double >> &messages)
static void getStatusColor(int status, int &rval, int &gval, int &bval)
std::vector< QReport * > getQReports() const
get map of QReports
unsigned long long int rval
Definition: vlib.h:21
bool hasError() const
true if at least of one of the quality tests returned an error
static const int STATUS_OK
static int computeErrorCode(DQMStore *bei, std::string &module_path)
Definition: shell.py:1
#define str(s)
Definition: vlib.h:198
static void createStatusLegendMessages(std::map< std::string, std::pair< int, double >> &messages)
static std::vector< std::string > getQTestNameList(MonitorElement *me)
static const int ERROR