CMS 3D CMS Logo

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