CMS 3D CMS Logo

SiPixelUtility.cc

Go to the documentation of this file.
00001 #include "DQM/SiPixelMonitorClient/interface/SiPixelUtility.h"
00002 #include "DQM/SiPixelMonitorClient/interface/SiPixelContinuousPalette.h"
00003 #include "DQMServices/Core/interface/DQMStore.h"
00004 #include "DQMServices/Core/interface/MonitorElement.h"
00005 
00006 using namespace std;
00007 //
00008 // Get a list of MEs in a folder
00009 //
00010 int SiPixelUtility::getMEList(string name, vector<string>& values) {
00011   values.clear();
00012   string prefix_str = name.substr(0,(name.find(":")));
00013   prefix_str += "/"; 
00014   string temp_str = name.substr(name.find(":")+1);
00015   split(temp_str, values, ",");
00016   for (vector<string>::iterator it = values.begin();
00017        it != values.end(); it++) (*it).insert(0,prefix_str);
00018   return values.size();
00019 }
00020 //
00021 // Get a list of MEs in a folder and the path name
00022 //
00023 int SiPixelUtility::getMEList(string name, string& dir_path, vector<string>& values) {
00024   values.clear();
00025   dir_path = name.substr(0,(name.find(":")));
00026   dir_path += "/"; 
00027   string temp_str = name.substr(name.find(":")+1);
00028   split(temp_str, values, ",");
00029   return values.size();
00030 }
00031 
00032 // Check if the requested ME exists in a folder
00033 bool SiPixelUtility::checkME(string name, string me_name, string& full_path) {
00034   if (name.find(name) == string::npos) return false;
00035   string prefix_str = name.substr(0,(name.find(":")));
00036   prefix_str += "/"; 
00037   string temp_str = name.substr(name.find(":")+1);
00038   vector<string> values;
00039   split(temp_str, values, ",");
00040   for (vector<string>::iterator it = values.begin();
00041        it != values.end(); it++) {
00042     if ((*it).find(me_name) != string::npos) {
00043       full_path = prefix_str + (*it);
00044       return true;
00045     }
00046   }
00047   return false;
00048 }
00049 //
00050 // -- Split a given string into a number of strings using given
00051 //    delimiters and fill a vector with splitted strings
00052 //
00053 void SiPixelUtility::split(const string& str, vector<string>& tokens, const string& delimiters) {
00054   // Skip delimiters at beginning.
00055   string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00056 
00057   // Find first "non-delimiter".
00058   string::size_type pos = str.find_first_of(delimiters, lastPos);
00059 
00060   while (string::npos != pos || string::npos != lastPos)  {
00061     // Found a token, add it to the vector.
00062     tokens.push_back(str.substr(lastPos, pos - lastPos));
00063 
00064     // Skip delimiters.  Note the "not_of"
00065     lastPos = str.find_first_not_of(delimiters, pos);
00066 
00067     // Find next "non-delimiter"
00068     pos = str.find_first_of(delimiters, lastPos);
00069   }
00070 }
00071 //
00072 // -- Get Color code from Status
00073 //
00074 void SiPixelUtility::getStatusColor(int status, int& rval, int&gval, int& bval) {
00075   if (status == dqm::qstatus::STATUS_OK) { 
00076     rval = 0;   gval = 255;   bval = 0; 
00077   } else if (status == dqm::qstatus::WARNING) { 
00078     rval = 255; gval = 255; bval = 0;
00079   } else if (status == dqm::qstatus::ERROR) { 
00080     rval = 255; gval = 0;  bval = 0;
00081   } else if (status == dqm::qstatus::OTHER) { 
00082     rval = 255; gval = 150;  bval = 0;
00083   } else {
00084     rval = 0; gval = 0;  bval = 255;
00085   }        
00086 }
00087 //
00088 // -- Get Color code from Status
00089 //
00090 void SiPixelUtility::getStatusColor(int status, int& icol, string& tag) {
00091   if (status == dqm::qstatus::STATUS_OK) { 
00092     tag = "Ok";
00093     icol = 3;
00094   } else if (status == dqm::qstatus::WARNING) { 
00095     tag = "Warning";
00096     icol = 5;     
00097   } else if (status == dqm::qstatus::ERROR) { 
00098     tag = "Error";
00099     icol = 2;
00100   } else if (status == dqm::qstatus::OTHER) { 
00101     tag = "Other";
00102     icol = 1;
00103   } else {
00104     tag = " ";
00105     icol = 1;
00106   }     
00107 }
00108 //
00109 // -- Get Color code from Status
00110 //
00111 void SiPixelUtility::getStatusColor(double status, int& rval, int&gval, int& bval) {
00112   rval = SiPixelContinuousPalette::r[(int)(status * 100)] ;
00113   gval = SiPixelContinuousPalette::g[(int)(status * 100)] ;
00114   bval = SiPixelContinuousPalette::b[(int)(status * 100)] ; 
00115 }
00116 //
00117 // -- Get Status of Monitor Element
00118 //
00119 int SiPixelUtility::getStatus(MonitorElement* me) {
00120   int status = 0; 
00121   if (me->getQReports().size() == 0) {
00122     status = 0;
00123   } else if (me->hasError()) {
00124     status = dqm::qstatus::ERROR;
00125   } else if (me->hasWarning()) {
00126     status = dqm::qstatus::WARNING;
00127   } else if (me->hasOtherReport()) {
00128     status = dqm::qstatus::OTHER;
00129   } else {  
00130     status = dqm::qstatus::STATUS_OK;
00131   }
00132   return status;
00133 }
00134 
00135 
00136 vector<string> SiPixelUtility::getQTestNameList(MonitorElement* me){
00137   vector<string> qtestNameList;
00138   return qtestNameList;
00139 }
00140 
00141 int SiPixelUtility::computeErrorCode(int status){
00142   int code = 0;
00143   switch(status){
00144   case dqm::qstatus::INSUF_STAT:
00145     code = 1;
00146     break;
00147   case dqm::qstatus::WARNING:
00148     code = 2;
00149     break;
00150   case dqm::qstatus::ERROR:
00151     code = 3;
00152     break;
00153   } // end switch
00154 
00155   return code;
00156 
00157 }
00158 
00159 int SiPixelUtility::computeErrorCode(DQMStore * bei,
00160                                      string                & module_path){
00161   int status = bei->getStatus(module_path);
00162   
00163   int code = -1;
00164   switch(status){
00165   case dqm::qstatus::STATUS_OK:
00166     code = 0;
00167     break;
00168   case dqm::qstatus::INSUF_STAT:
00169     code = 1;
00170     break;
00171   case dqm::qstatus::WARNING:
00172     code = 2;
00173     break;
00174   case dqm::qstatus::ERROR:
00175     code = 3;
00176     break;
00177   } // end of switch
00178   
00179   return code;
00180 
00181 }
00182 
00183 
00184 
00185 int SiPixelUtility::computeHistoBin(string & module_path){ 
00186 
00187   int module_bin = 0;
00188 
00189   int module       = 0;
00190   int shell        = 0;   
00191   int layer        = 0;  
00192   int ladder       = 0;  
00193   int halfcylinder = 0;  
00194   int disk         = 0;  
00195   int blade        = 0;  
00196   int panel        = 0;  
00197 
00198   int nbinShell        = 192;
00199   int nbinLayer        = 0;  
00200   int nbinLadder       = 4;
00201 
00202   int nbinHalfcylinder = 168;  
00203   int nbinDisk         = 84;  
00204   int nbinBlade        = 7;  
00205   int nbinPanel        = 0;  
00206 
00207   vector<string> subDirVector;
00208   SiPixelUtility::split(module_path,subDirVector,"/");
00209 
00210   for (vector<string>::const_iterator it = subDirVector.begin();
00211        it != subDirVector.end(); it++) {
00212     if((*it).find("Collector") != string::npos ||
00213        //(*it).find("Collated") != string::npos ||
00214        (*it).find("FU") != string::npos ||
00215        (*it).find("Pixel") != string::npos ||
00216        (*it).find("Barrel") != string::npos ||
00217        (*it).find("Endcap") != string::npos) continue;
00218     
00219     if((*it).find("Module") != string::npos){
00220       module = atoi((*it).substr((*it).find("_")+1).c_str());
00221     }
00222     
00223     if((*it).find("Shell") != string::npos){
00224       if((*it).find("mI") != string::npos) shell = 1;
00225       if((*it).find("mO") != string::npos) shell = 2;
00226       if((*it).find("pI") != string::npos) shell = 3;
00227       if((*it).find("pO") != string::npos) shell = 4;
00228     }
00229     if((*it).find("Layer") != string::npos){
00230       layer = atoi((*it).substr((*it).find("_")+1).c_str());
00231       if(layer==1){
00232         nbinLayer = 0;
00233       }
00234       if(layer==2){
00235         nbinLayer = 40;
00236       }
00237       if(layer==3){
00238         nbinLayer = 40+64;
00239       }
00240     }
00241     if((*it).find("Ladder") != string::npos){
00242       ladder = atoi((*it).substr((*it).find("_")+1,2).c_str()); 
00243     }
00244     if((*it).find("HalfCylinder") != string::npos){
00245       if((*it).find("mI") != string::npos) halfcylinder = 1;
00246       if((*it).find("mO") != string::npos) halfcylinder = 2;
00247       if((*it).find("pI") != string::npos) halfcylinder = 3;
00248       if((*it).find("pO") != string::npos) halfcylinder = 4;
00249     }
00250     if((*it).find("Disk") != string::npos){
00251       disk = atoi((*it).substr((*it).find("_")+1).c_str());
00252     }
00253     if((*it).find("Blade") != string::npos){
00254       blade = atoi((*it).substr((*it).find("_")+1,2).c_str()); 
00255     }
00256     if((*it).find("Panel") != string::npos){
00257       panel = atoi((*it).substr((*it).find("_")+1).c_str()); 
00258       if(panel==1) nbinPanel = 0;
00259       if(panel==2) nbinPanel = 4;
00260     }
00261   }
00262   if(module_path.find("Barrel") != string::npos){
00263     module_bin =  module + 
00264       (ladder-1)*nbinLadder +
00265       nbinLayer +
00266       (shell -1)*nbinShell;
00267   }
00268   if(module_path.find("Endcap") != string::npos){
00269     module_bin =  module +
00270       (panel       -1)*nbinPanel +
00271       (blade       -1)*nbinBlade +
00272       (disk        -1)*nbinDisk +
00273       (halfcylinder-1)*nbinHalfcylinder;
00274   }
00275   
00276   return module_bin;
00277 
00278   //  cout << "leaving SiPixelInformationExtractor::computeHistoBin" << endl;
00279 }
00280 
00281 
00282 void SiPixelUtility::fillPaveText(TPaveText                 * pave,
00283                                   map<string,pair<int,double> >  messages){
00284 
00285   TText* sourceCodeOnCanvas;
00286   for(map<string, pair<int,double> >::iterator it =  messages.begin();
00287                                             it != messages.end();
00288                                             it++){
00289     string message = it->first;
00290     int    color   = (it->second).first;
00291     double size    = (it->second).second;
00292     sourceCodeOnCanvas = pave->AddText(message.c_str());
00293     sourceCodeOnCanvas->SetTextColor(color);
00294     sourceCodeOnCanvas->SetTextSize(size);
00295     sourceCodeOnCanvas->SetTextFont(112);    
00296 
00297   }
00298 }
00299 
00300 map<string,string> SiPixelUtility::sourceCodeMap(){
00301 
00302   map<string,string> sourceCode;
00303   for(int iSource=0; iSource<5;iSource++){
00304     string type;
00305     string    code;
00306     switch(iSource){
00307     case 0: type = "RAW"; code = "1    ";
00308       break;
00309     case 1: type = "DIG"; code = "10   ";
00310       break;
00311     case 2: type = "CLU"; code = "100  ";
00312       break;
00313     case 3: type = "TRK"; code = "1000 ";
00314       break;
00315     case 4: type = "REC"; code = "10000";
00316       break;
00317     } // end of switch
00318     sourceCode[type]=code;
00319   }
00320   return sourceCode;
00321   
00322 }
00323 
00324 void SiPixelUtility::createStatusLegendMessages(map<string,pair<int,double> > & messages){
00325   for(int iStatus=1; iStatus<5;iStatus++){
00326     pair<int,double> color_size;
00327     int color = 1;
00328     double size  = 0.03;
00329     string code;
00330     string type;
00331     color_size.second = size;
00332     switch(iStatus){
00333     case 1: code = "1"; type = "INSUF_STAT"; color = kBlue;
00334       break;
00335     case 2: code = "2"; type = "WARNING(S)"; color = kYellow;
00336       break;
00337     case 3: code = "3"; type = "ERROR(S)  "; color = kRed;
00338       break;
00339     case 4: code = "4"; type = "ERRORS    "; color = kMagenta;
00340       break;
00341     } // end of switch
00342     string messageString = code + ": " + type;
00343     color_size.first = color;
00344     messages[messageString] = color_size;
00345   }
00346 }
00347 
00348 //------------------------------------------------------------------------------
00349 //
00350 // -- Set Drawing Option
00351 //
00352 void SiPixelUtility::setDrawingOption(TH1   * hist, 
00353                                       float   xlow, 
00354                                       float   xhigh) {
00355   if (!hist) return;
00356 
00357   TAxis* xa = hist->GetXaxis();
00358   TAxis* ya = hist->GetYaxis();
00359 
00360   xa->SetTitleOffset(0.7);
00361   xa->SetTitleSize(0.06);
00362   xa->SetLabelSize(0.04);
00363   //  xa->SetLabelColor(0);
00364 
00365   ya->SetTitleOffset(0.7);
00366   ya->SetTitleSize(0.06);
00367 
00368 
00369   if (xlow != -1 &&  xhigh != -1.0) {
00370     xa->SetRangeUser(xlow, xhigh);
00371   }
00372 }

Generated on Tue Jun 9 17:33:21 2009 for CMSSW by  doxygen 1.5.4