CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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();
18  it != values.end(); it++) (*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) 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();
42  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; gval = 255; bval = 0;
78  } else if (status == dqm::qstatus::WARNING) {
79  rval = 255; gval = 255; bval = 0;
80  } else if (status == dqm::qstatus::ERROR) {
81  rval = 255; gval = 0; bval = 0;
82  } else if (status == dqm::qstatus::OTHER) {
83  rval = 255; gval = 150; bval = 0;
84  } else {
85  rval = 0; gval = 0; bval = 255;
86  }
87 }
88 //
89 // -- Get Color code from Status
90 //
91 void SiPixelUtility::getStatusColor(int status, int& icol, string& tag) {
92  if (status == dqm::qstatus::STATUS_OK) {
93  tag = "Ok";
94  icol = 3;
95  } else if (status == dqm::qstatus::WARNING) {
96  tag = "Warning";
97  icol = 5;
98  } else if (status == dqm::qstatus::ERROR) {
99  tag = "Error";
100  icol = 2;
101  } else if (status == dqm::qstatus::OTHER) {
102  tag = "Other";
103  icol = 1;
104  } else {
105  tag = " ";
106  icol = 1;
107  }
108 }
109 //
110 // -- Get Color code from Status
111 //
112 void SiPixelUtility::getStatusColor(double status, int& rval, int&gval, int& bval) {
113  rval = SiPixelContinuousPalette::r[(int)(status * 100)] ;
114  gval = SiPixelContinuousPalette::g[(int)(status * 100)] ;
115  bval = SiPixelContinuousPalette::b[(int)(status * 100)] ;
116 }
117 //
118 // -- Get Status of Monitor Element
119 //
121  int status = 0;
122  if (me->getQReports().size() == 0) {
123  status = 0;
124  } else if (me->hasError()) {
125  status = dqm::qstatus::ERROR;
126  } else if (me->hasWarning()) {
127  status = dqm::qstatus::WARNING;
128  } else if (me->hasOtherReport()) {
129  status = dqm::qstatus::OTHER;
130  } else {
131  status = dqm::qstatus::STATUS_OK;
132  }
133  return status;
134 }
135 
136 
138  vector<string> qtestNameList;
139  return qtestNameList;
140 }
141 
143  int code = 0;
144  switch(status){
146  code = 1;
147  break;
149  code = 2;
150  break;
151  case dqm::qstatus::ERROR:
152  code = 3;
153  break;
154  } // end switch
155 
156  return code;
157 
158 }
159 
161  string & module_path){
162  int status = bei->getStatus(module_path);
163 
164  int code = -1;
165  switch(status){
167  code = 0;
168  break;
170  code = 1;
171  break;
173  code = 2;
174  break;
175  case dqm::qstatus::ERROR:
176  code = 3;
177  break;
178  } // end of switch
179 
180  return code;
181 
182 }
183 
184 
185 
186 int SiPixelUtility::computeHistoBin(string & module_path){
187 
188  int module_bin = 0;
189 
190  int module = 0;
191  int shell = 0;
192  int layer = 0;
193  int ladder = 0;
194  int halfcylinder = 0;
195  int disk = 0;
196  int blade = 0;
197  int panel = 0;
198 
199  int nbinShell = 192;
200  int nbinLayer = 0;
201  int nbinLadder = 4;
202 
203  int nbinHalfcylinder = 168;
204  int nbinDisk = 84;
205  int nbinBlade = 7;
206  int nbinPanel = 0;
207 
208  vector<string> subDirVector;
209  SiPixelUtility::split(module_path,subDirVector,"/");
210 
211  for (vector<string>::const_iterator it = subDirVector.begin();
212  it != subDirVector.end(); it++) {
213  if((*it).find("Collector") != string::npos ||
214  //(*it).find("Collated") != string::npos ||
215  (*it).find("FU") != string::npos ||
216  (*it).find("Pixel") != string::npos ||
217  (*it).find("Barrel") != string::npos ||
218  (*it).find("Endcap") != string::npos) 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) shell = 1;
226  if((*it).find("mO") != string::npos) shell = 2;
227  if((*it).find("pI") != string::npos) shell = 3;
228  if((*it).find("pO") != string::npos) shell = 4;
229  }
230  if((*it).find("Layer") != string::npos){
231  layer = atoi((*it).substr((*it).find("_")+1).c_str());
232  if(layer==1){
233  nbinLayer = 0;
234  }
235  if(layer==2){
236  nbinLayer = 40;
237  }
238  if(layer==3){
239  nbinLayer = 40+64;
240  }
241  }
242  if((*it).find("Ladder") != string::npos){
243  ladder = atoi((*it).substr((*it).find("_")+1,2).c_str());
244  }
245  if((*it).find("HalfCylinder") != string::npos){
246  if((*it).find("mI") != string::npos) halfcylinder = 1;
247  if((*it).find("mO") != string::npos) halfcylinder = 2;
248  if((*it).find("pI") != string::npos) halfcylinder = 3;
249  if((*it).find("pO") != string::npos) halfcylinder = 4;
250  }
251  if((*it).find("Disk") != string::npos){
252  disk = atoi((*it).substr((*it).find("_")+1).c_str());
253  }
254  if((*it).find("Blade") != string::npos){
255  blade = atoi((*it).substr((*it).find("_")+1,2).c_str());
256  }
257  if((*it).find("Panel") != string::npos){
258  panel = atoi((*it).substr((*it).find("_")+1).c_str());
259  if(panel==1) nbinPanel = 0;
260  if(panel==2) nbinPanel = 4;
261  }
262  }
263  if(module_path.find("Barrel") != string::npos){
264  module_bin = module +
265  (ladder-1)*nbinLadder +
266  nbinLayer +
267  (shell -1)*nbinShell;
268  }
269  if(module_path.find("Endcap") != string::npos){
270  module_bin = module +
271  (panel -1)*nbinPanel +
272  (blade -1)*nbinBlade +
273  (disk -1)*nbinDisk +
274  (halfcylinder-1)*nbinHalfcylinder;
275  }
276 
277  return module_bin;
278 
279  // cout << "leaving SiPixelInformationExtractor::computeHistoBin" << endl;
280 }
281 
282 
283 void SiPixelUtility::fillPaveText(TPaveText * pave,
284  const map<string,pair<int,double> >& messages){
285 
286  TText* sourceCodeOnCanvas;
287  for(map<string, pair<int,double> >::const_iterator it = messages.begin();
288  it != messages.end();
289  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 
301 map<string,string> SiPixelUtility::sourceCodeMap(){
302 
303  map<string,string> sourceCode;
304  for(int iSource=0; iSource<5;iSource++){
305  string type;
306  string code;
307  switch(iSource){
308  case 0: type = "RAW"; code = "1 ";
309  break;
310  case 1: type = "DIG"; code = "10 ";
311  break;
312  case 2: type = "CLU"; code = "100 ";
313  break;
314  case 3: type = "TRK"; code = "1000 ";
315  break;
316  case 4: type = "REC"; code = "10000";
317  break;
318  } // end of switch
319  sourceCode[type]=code;
320  }
321  return sourceCode;
322 
323 }
324 
325 void SiPixelUtility::createStatusLegendMessages(map<string,pair<int,double> > & messages){
326  for(int iStatus=1; iStatus<5;iStatus++){
327  pair<int,double> color_size;
328  int color = 1;
329  double size = 0.03;
330  string code;
331  string type;
332  color_size.second = size;
333  switch(iStatus){
334  case 1: code = "1"; type = "INSUF_STAT"; color = kBlue;
335  break;
336  case 2: code = "2"; type = "WARNING(S)"; color = kYellow;
337  break;
338  case 3: code = "3"; type = "ERROR(S) "; color = kRed;
339  break;
340  case 4: code = "4"; type = "ERRORS "; color = kMagenta;
341  break;
342  } // end of switch
343  string messageString = code + ": " + type;
344  color_size.first = color;
345  messages[messageString] = color_size;
346  }
347 }
348 
349 //------------------------------------------------------------------------------
350 //
351 // -- Set Drawing Option
352 //
354  float xlow,
355  float xhigh) {
356  if (!hist) return;
357 
358  TAxis* xa = hist->GetXaxis();
359  TAxis* ya = hist->GetYaxis();
360 
361  xa->SetTitleOffset(0.7);
362  xa->SetTitleSize(0.06);
363  xa->SetLabelSize(0.04);
364  // xa->SetLabelColor(0);
365 
366  ya->SetTitleOffset(0.7);
367  ya->SetTitleSize(0.06);
368 
369 
370  if (xlow != -1 && xhigh != -1.0) {
371  xa->SetRangeUser(xlow, xhigh);
372  }
373 }
type
Definition: HCALResponse.h:21
static const int OTHER
static int getMEList(std::string name, std::vector< std::string > &values)
bool hasError(void) const
true if at least of one of the quality tests returned an error
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)
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(void) const
true if at least of one of the quality tests returned a warning
static const int INSUF_STAT
static void getStatusColor(int status, int &rval, int &gval, int &bval)
static void createStatusLegendMessages(std::map< std::string, std::pair< int, double > > &messages)
static void fillPaveText(TPaveText *pave, const std::map< std::string, std::pair< int, double > > &messages)
unsigned long long int rval
Definition: vlib.h:22
std::vector< QReport * > getQReports(void) const
get map of QReports
bool hasOtherReport(void) const
true if at least of one of the tests returned some other (non-ok) status
static const int STATUS_OK
static int computeErrorCode(DQMStore *bei, std::string &module_path)
tuple status
Definition: ntuplemaker.py:245
Definition: vlib.h:208
double split
Definition: MVATrainer.cc:139
tuple size
Write out results.
static std::vector< std::string > getQTestNameList(MonitorElement *me)
static const int ERROR