CMS 3D CMS Logo

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