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) {
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) {
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()) {
135  } else if (me->hasWarning()) {
137  } else if (me->hasOtherReport()) {
139  } else {
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::computeHistoBin(string &module_path) {
168  int module_bin = 0;
169 
170  int module = 0;
171  int shell = 0;
172  int layer = 0;
173  int ladder = 0;
174  int halfcylinder = 0;
175  int disk = 0;
176  int blade = 0;
177  int panel = 0;
178 
179  int nbinShell = 192;
180  int nbinLayer = 0;
181  int nbinLadder = 4;
182 
183  int nbinHalfcylinder = 168;
184  int nbinDisk = 84;
185  int nbinBlade = 7;
186  int nbinPanel = 0;
187 
188  vector<string> subDirVector;
189  SiPixelUtility::split(module_path, subDirVector, "/");
190 
191  for (vector<string>::const_iterator it = subDirVector.begin(); it != subDirVector.end(); it++) {
192  if ((*it).find("Collector") != string::npos ||
193  //(*it).find("Collated") != string::npos ||
194  (*it).find("FU") != string::npos || (*it).find("Pixel") != string::npos ||
195  (*it).find("Barrel") != string::npos || (*it).find("Endcap") != string::npos)
196  continue;
197 
198  if ((*it).find("Module") != string::npos) {
199  module = atoi((*it).substr((*it).find("_") + 1).c_str());
200  }
201 
202  if ((*it).find("Shell") != string::npos) {
203  if ((*it).find("mI") != string::npos)
204  shell = 1;
205  if ((*it).find("mO") != string::npos)
206  shell = 2;
207  if ((*it).find("pI") != string::npos)
208  shell = 3;
209  if ((*it).find("pO") != string::npos)
210  shell = 4;
211  }
212  if ((*it).find("Layer") != string::npos) {
213  layer = atoi((*it).substr((*it).find("_") + 1).c_str());
214  if (layer == 1) {
215  nbinLayer = 0;
216  }
217  if (layer == 2) {
218  nbinLayer = 40;
219  }
220  if (layer == 3) {
221  nbinLayer = 40 + 64;
222  }
223  }
224  if ((*it).find("Ladder") != string::npos) {
225  ladder = atoi((*it).substr((*it).find("_") + 1, 2).c_str());
226  }
227  if ((*it).find("HalfCylinder") != string::npos) {
228  if ((*it).find("mI") != string::npos)
229  halfcylinder = 1;
230  if ((*it).find("mO") != string::npos)
231  halfcylinder = 2;
232  if ((*it).find("pI") != string::npos)
233  halfcylinder = 3;
234  if ((*it).find("pO") != string::npos)
235  halfcylinder = 4;
236  }
237  if ((*it).find("Disk") != string::npos) {
238  disk = atoi((*it).substr((*it).find("_") + 1).c_str());
239  }
240  if ((*it).find("Blade") != string::npos) {
241  blade = atoi((*it).substr((*it).find("_") + 1, 2).c_str());
242  }
243  if ((*it).find("Panel") != string::npos) {
244  panel = atoi((*it).substr((*it).find("_") + 1).c_str());
245  if (panel == 1)
246  nbinPanel = 0;
247  if (panel == 2)
248  nbinPanel = 4;
249  }
250  }
251  if (module_path.find("Barrel") != string::npos) {
252  module_bin = module + (ladder - 1) * nbinLadder + nbinLayer + (shell - 1) * nbinShell;
253  }
254  if (module_path.find("Endcap") != string::npos) {
255  module_bin = module + (panel - 1) * nbinPanel + (blade - 1) * nbinBlade + (disk - 1) * nbinDisk +
256  (halfcylinder - 1) * nbinHalfcylinder;
257  }
258 
259  return module_bin;
260 
261  // cout << "leaving SiPixelInformationExtractor::computeHistoBin" << endl;
262 }
263 
264 void SiPixelUtility::fillPaveText(TPaveText *pave, const map<string, pair<int, double>> &messages) {
265  TText *sourceCodeOnCanvas;
266  for (map<string, pair<int, double>>::const_iterator it = messages.begin(); it != messages.end(); it++) {
267  string message = it->first;
268  int color = (it->second).first;
269  double size = (it->second).second;
270  sourceCodeOnCanvas = pave->AddText(message.c_str());
271  sourceCodeOnCanvas->SetTextColor(color);
272  sourceCodeOnCanvas->SetTextSize(size);
273  sourceCodeOnCanvas->SetTextFont(112);
274  }
275 }
276 
277 map<string, string> SiPixelUtility::sourceCodeMap() {
278  map<string, string> sourceCode;
279  for (int iSource = 0; iSource < 5; iSource++) {
280  string type;
281  string code;
282  switch (iSource) {
283  case 0:
284  type = "RAW";
285  code = "1 ";
286  break;
287  case 1:
288  type = "DIG";
289  code = "10 ";
290  break;
291  case 2:
292  type = "CLU";
293  code = "100 ";
294  break;
295  case 3:
296  type = "TRK";
297  code = "1000 ";
298  break;
299  case 4:
300  type = "REC";
301  code = "10000";
302  break;
303  } // end of switch
304  sourceCode[type] = code;
305  }
306  return sourceCode;
307 }
308 
309 void SiPixelUtility::createStatusLegendMessages(map<string, pair<int, double>> &messages) {
310  for (int iStatus = 1; iStatus < 5; iStatus++) {
311  pair<int, double> color_size;
312  int color = 1;
313  double size = 0.03;
314  string code;
315  string type;
316  color_size.second = size;
317  switch (iStatus) {
318  case 1:
319  code = "1";
320  type = "INSUF_STAT";
321  color = kBlue;
322  break;
323  case 2:
324  code = "2";
325  type = "WARNING(S)";
326  color = kYellow;
327  break;
328  case 3:
329  code = "3";
330  type = "ERROR(S) ";
331  color = kRed;
332  break;
333  case 4:
334  code = "4";
335  type = "ERRORS ";
336  color = kMagenta;
337  break;
338  } // end of switch
339  string messageString = code + ": " + type;
340  color_size.first = color;
341  messages[messageString] = color_size;
342  }
343 }
344 
345 //------------------------------------------------------------------------------
346 //
347 // -- Set Drawing Option
348 //
349 void SiPixelUtility::setDrawingOption(TH1 *hist, float xlow, float xhigh) {
350  if (!hist)
351  return;
352 
353  TAxis *xa = hist->GetXaxis();
354  TAxis *ya = hist->GetYaxis();
355 
356  xa->SetTitleOffset(0.7);
357  xa->SetTitleSize(0.06);
358  xa->SetLabelSize(0.04);
359  // xa->SetLabelColor(0);
360 
361  ya->SetTitleOffset(0.7);
362  ya->SetTitleSize(0.06);
363 
364  if (xlow != -1 && xhigh != -1.0) {
365  xa->SetRangeUser(xlow, xhigh);
366  }
367 }
size
Write out results.
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)
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)
constexpr std::array< uint8_t, layerIndexSize > layer
U second(std::pair< T, U > const &p)
static void setDrawingOption(TH1 *hist, float xlow=-1., float xhigh=-1.)
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)
static int computeErrorCode(int status)
__shared__ Hist hist
static const int STATUS_OK
Definition: shell.py:1
#define str(s)
static void createStatusLegendMessages(std::map< std::string, std::pair< int, double >> &messages)
static std::vector< std::string > getQTestNameList(MonitorElement *me)
static const int ERROR