CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/SiStripMonitorClient/src/SiStripUtility.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
00002 #include "DQMServices/Core/interface/MonitorElement.h"
00003 #include "DQMServices/Core/interface/DQMStore.h"
00004 
00005 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00006 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00007 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00008 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00009 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00010 //
00011 // Get a list of MEs in a folder
00012 //
00013 int SiStripUtility::getMEList(std::string name, std::vector<std::string>& values) {
00014   values.clear();
00015   std::string prefix_str = name.substr(0,(name.find(":")));
00016   prefix_str += "/"; 
00017   std::string temp_str = name.substr(name.find(":")+1);
00018   split(temp_str, values, ",");
00019   for (std::vector<std::string>::iterator it = values.begin();
00020        it != values.end(); it++) (*it).insert(0,prefix_str);
00021   return values.size();
00022 }
00023 //
00024 // Get a list of MEs in a folder and the path name
00025 //
00026 int SiStripUtility::getMEList(std::string name, std::string& dir_path, std::vector<std::string>& values) {
00027   values.clear();
00028   dir_path = name.substr(0,(name.find(":")));
00029   dir_path += "/"; 
00030   std::string temp_str = name.substr(name.find(":")+1);
00031   split(temp_str, values, ",");
00032   return values.size();
00033 }
00034 
00035 // Check if the requested ME exists in a folder
00036 bool SiStripUtility::checkME(std::string name, std::string me_name, std::string& full_path) {
00037   if (name.find(name) == std::string::npos) return false;
00038   std::string prefix_str = name.substr(0,(name.find(":")));
00039   prefix_str += "/"; 
00040   std::string temp_str = name.substr(name.find(":")+1);
00041   std::vector<std::string> values;
00042   split(temp_str, values, ",");
00043   for (std::vector<std::string>::iterator it = values.begin();
00044        it != values.end(); it++) {
00045     if ((*it).find(me_name) != std::string::npos) {
00046       full_path = prefix_str + (*it);
00047       return true;
00048     }
00049   }
00050   return false;
00051 }
00052 //
00053 // -- Split a given string into a number of strings using given
00054 //    delimiters and fill a vector with splitted strings
00055 //
00056 void SiStripUtility::split(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters) {
00057   // Skip delimiters at beginning.
00058   std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00059 
00060   // Find first "non-delimiter".
00061   std::string::size_type pos = str.find_first_of(delimiters, lastPos);
00062 
00063   while (std::string::npos != pos || std::string::npos != lastPos)  {
00064     // Found a token, add it to the std::vector.
00065     tokens.push_back(str.substr(lastPos, pos - lastPos));
00066 
00067     // Skip delimiters.  Note the "not_of"
00068     lastPos = str.find_first_not_of(delimiters, pos);
00069 
00070     // Find next "non-delimiter"
00071     pos = str.find_first_of(delimiters, lastPos);
00072   }
00073 }
00074 //
00075 // -- Get Color code from Status
00076 //
00077 void SiStripUtility::getMEStatusColor(int status, int& rval, int&gval, int& bval) {
00078   if (status == dqm::qstatus::STATUS_OK) { 
00079     rval = 0;   gval = 255;   bval = 0; 
00080   } else if (status == dqm::qstatus::WARNING) { 
00081     rval = 255; gval = 255; bval = 0;
00082   } else if (status == dqm::qstatus::ERROR) { 
00083     rval = 255; gval = 0;  bval = 0;
00084   } else if (status == dqm::qstatus::OTHER) { 
00085     rval = 255; gval = 150;  bval = 0;
00086   } else {
00087     rval = 0; gval = 0;  bval = 255;
00088   }        
00089 }
00090 //
00091 // -- Get Color code from Status
00092 //
00093 void SiStripUtility::getMEStatusColor(int status, int& icol, std::string& tag) {
00094   if (status == dqm::qstatus::STATUS_OK) { 
00095     tag = "Ok";
00096     icol = 3;
00097   } else if (status == dqm::qstatus::WARNING) { 
00098     tag = "Warning";
00099     icol = 5;     
00100   } else if (status == dqm::qstatus::ERROR) { 
00101     tag = "Error";
00102     icol = 2;
00103   } else if (status == dqm::qstatus::OTHER) { 
00104     tag = "Other";
00105     icol = 1;
00106   } else {
00107     tag = " ";
00108     icol = 1;
00109   }     
00110 }
00111 //
00112 // -- Get Color code from Status
00113 //
00114 void SiStripUtility::getDetectorStatusColor(int status, int& rval, int&gval, int& bval) {
00115   // No Error
00116   if (status == 0) {
00117     rval = 0; gval = 255;bval = 0;
00118     return;
00119   }
00120   // Error detected in FED Channel
00121   if (((status >> 0) & 0x1) > 0) { 
00122     rval = 150; gval = 0; bval = 0; 
00123     return;
00124   }
00125   // Excluded FED Channel 
00126   if (((status >> 3) & 0x1) > 0) {
00127     rval = 255; gval = 255; bval = 255; 
00128     return;
00129   }
00130   // DCS Error
00131   if (((status >> 4) & 0x1) > 0) {
00132     rval = 200; gval = 20; bval = 255; 
00133     return;
00134   } 
00135   // Digi and Cluster Problem   
00136   if (((status >> 1) & 0x1) > 0) {
00137     rval = 255; bval = 0;
00138     if (((status >> 2) & 0x1) > 0) gval = 0;
00139     else gval = 100;
00140   } else {
00141     rval = 251; gval = 0; bval = 100;   
00142   }
00143 }
00144 
00145 //
00146 // -- Get Status of Monitor Element
00147 //
00148 int SiStripUtility::getMEStatus(MonitorElement* me) {
00149   int status = 0; 
00150   if (me->getQReports().size() == 0) {
00151     status = 0;
00152   } else if (me->hasError()) {
00153     status = dqm::qstatus::ERROR;
00154   } else if (me->hasWarning()) {
00155     status = dqm::qstatus::WARNING;
00156   } else if (me->hasOtherReport()) {
00157     status = dqm::qstatus::OTHER;
00158   } else {  
00159     status = dqm::qstatus::STATUS_OK;
00160   }
00161   return status;
00162 }
00163 //
00164 // --  Fill Module Names
00165 // 
00166 void SiStripUtility::getModuleFolderList(DQMStore * dqm_store, std::vector<std::string>& mfolders){
00167   std::string currDir = dqm_store->pwd();
00168   if (currDir.find("module_") != std::string::npos)  {
00169     //    std::string mId = currDir.substr(currDir.find("module_")+7, 9);
00170     mfolders.push_back(currDir);
00171   } else {  
00172     std::vector<std::string> subdirs = dqm_store->getSubdirs();
00173     for (std::vector<std::string>::const_iterator it = subdirs.begin();
00174          it != subdirs.end(); it++) {
00175       dqm_store->cd(*it);
00176       getModuleFolderList(dqm_store, mfolders);
00177       dqm_store->goUp();
00178     }
00179   }
00180 }
00181 //
00182 // -- Get Status of Monitor Element
00183 //
00184 int SiStripUtility::getMEStatus(MonitorElement* me, int& bad_channels) {
00185   int status = 0; 
00186   if (me->getQReports().size() == 0) {
00187     status       = 0;
00188     bad_channels = -1;
00189   } else {
00190     std::vector<QReport *> qreports = me->getQReports();
00191     bad_channels =qreports[0]->getBadChannels().size();
00192     if (me->hasError()) {
00193       status = dqm::qstatus::ERROR;
00194     } else if (me->hasWarning()) {
00195       status = dqm::qstatus::WARNING;
00196     } else if (me->hasOtherReport()) {
00197       status = dqm::qstatus::OTHER;
00198     } else {  
00199       status = dqm::qstatus::STATUS_OK;
00200     }
00201   }
00202   return status;
00203 }
00204 //
00205 // -- Get Status of Monitor Element
00206 //
00207 void SiStripUtility::getMEValue(MonitorElement* me, std::string & val){
00208   val = "";
00209   if (me &&  me->kind()==MonitorElement::DQM_KIND_REAL) {
00210     val = me->valueString();
00211     val = val.substr(val.find("=")+1);
00212   }
00213 }
00214 //
00215 // -- go to a given Directory
00216 //
00217 bool SiStripUtility::goToDir(DQMStore * dqm_store, std::string name) {
00218   std::string currDir = dqm_store->pwd();
00219   std::string dirName = currDir.substr(currDir.find_last_of("/")+1);
00220   if (dirName.find(name) == 0) {
00221     return true;
00222   }
00223   std::vector<std::string> subDirVec = dqm_store->getSubdirs();
00224   for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
00225        ic != subDirVec.end(); ic++) {
00226     std::string fname = (*ic);
00227     if ((fname.find("Reference") != std::string::npos) ||
00228          (fname.find("AlCaReco") != std::string::npos)) continue;
00229     dqm_store->cd(fname);
00230     if (!goToDir(dqm_store, name))  dqm_store->goUp();
00231     else return true;
00232   }
00233   return false;  
00234 }
00235 //
00236 // -- Get Sub Detector tag from DetId
00237 //
00238 void SiStripUtility::getSubDetectorTag(uint32_t det_id, std::string& subdet_tag) {
00239   StripSubdetector subdet(det_id);
00240   subdet_tag = "";
00241   switch (subdet.subdetId()) 
00242     {
00243     case StripSubdetector::TIB:
00244       {
00245         subdet_tag = "TIB";
00246         break;
00247       }
00248     case StripSubdetector::TID:
00249       {
00250         TIDDetId tidId(det_id);
00251         if (tidId.side() == 2) {
00252           subdet_tag = "TIDF";
00253         }  else if (tidId.side() == 1) {
00254           subdet_tag = "TIDB";
00255         }
00256         break;       
00257       }
00258     case StripSubdetector::TOB:
00259       {
00260         subdet_tag = "TOB";
00261         break;
00262       }
00263     case StripSubdetector::TEC:
00264       {
00265         TECDetId tecId(det_id);
00266         if (tecId.side() == 2) {
00267           subdet_tag = "TECF";
00268         }  else if (tecId.side() == 1) {
00269           subdet_tag = "TECB";  
00270         }
00271         break;       
00272       }
00273     }
00274 }
00275 //
00276 // -- Set Bad Channel Flag from hname
00277 // 
00278 void SiStripUtility::setBadModuleFlag(std::string & hname, uint16_t& flg){
00279   
00280   if (hname.find("FractionOfBadChannels")   != std::string::npos) flg |= (1<<0);
00281   else if (hname.find("NumberOfDigi")       != std::string::npos) flg |= (1<<1);
00282   else if (hname.find("NumberOfCluster")    != std::string::npos) flg |= (1<<2);
00283   else if (hname.find("ExcludedFedChannel") != std::string::npos) flg |= (1<<3);
00284   else if (hname.find("DCSError")           != std::string::npos) flg |= (1<<4); 
00285 }  
00286 //
00287 // -- Get the Status Message from Bad Module Flag
00288 //
00289 void SiStripUtility::getBadModuleStatus(uint16_t flag, std::string & message){
00290   if (flag == 0) message += "No Error";
00291   else {
00292     message += " Error from :: "; 
00293     if (((flag >> 0) & 0x1) > 0) message += " Fed BadChannel : ";
00294     if (((flag >> 1) & 0x1) > 0) message += " # of Digi : ";  
00295     if (((flag >> 2) & 0x1) > 0) message += " # of Clusters :";
00296     if (((flag >> 3) & 0x1) > 0) message += " Excluded FED Channel ";
00297     if (((flag >> 4) & 0x1) > 0) message += " DCSError "; 
00298   }
00299 }
00300 //
00301 // -- Set Event Info Folder
00302 //
00303 void SiStripUtility::getTopFolderPath(DQMStore * dqm_store, std::string type, std::string& path) {
00304   if (type != "SiStrip" && type != "Tracking") return;
00305   path = ""; 
00306   dqm_store->cd();
00307   if (type == "SiStrip") {
00308     if (dqm_store->dirExists(type)) {
00309       dqm_store->cd(type);
00310       path = dqm_store->pwd();
00311     } else {
00312       if (SiStripUtility::goToDir(dqm_store, type)) {
00313         std::string mdir = "MechanicalView";
00314         if (SiStripUtility::goToDir(dqm_store, mdir)) {
00315           path = dqm_store->pwd(); 
00316           path = path.substr(0, path.find(mdir)-1);
00317         }
00318       }
00319     }
00320   } else if (type == "Tracking") {
00321     std::string top_dir = "Tracking";
00322     if (dqm_store->dirExists(top_dir)) {
00323       dqm_store->cd(top_dir);
00324       path = dqm_store->pwd();
00325     } else {
00326       if (SiStripUtility::goToDir(dqm_store, top_dir)) {
00327         std::string tdir = "TrackParameters";
00328         if (SiStripUtility::goToDir(dqm_store, tdir)) {
00329           path = dqm_store->pwd(); 
00330           path = path.substr(0, path.find(tdir)-1);
00331         }
00332       } 
00333     }
00334   }
00335 }