CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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/TrackerCommon/interface/TrackerTopology.h"
00007 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00008 //
00009 // Get a list of MEs in a folder
00010 //
00011 int SiStripUtility::getMEList(std::string name, std::vector<std::string>& values) {
00012   values.clear();
00013   std::string prefix_str = name.substr(0,(name.find(":")));
00014   prefix_str += "/"; 
00015   std::string temp_str = name.substr(name.find(":")+1);
00016   split(temp_str, values, ",");
00017   for (std::vector<std::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 SiStripUtility::getMEList(std::string name, std::string& dir_path, std::vector<std::string>& values) {
00025   values.clear();
00026   dir_path = name.substr(0,(name.find(":")));
00027   dir_path += "/"; 
00028   std::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 SiStripUtility::checkME(std::string name, std::string me_name, std::string& full_path) {
00035   if (name.find(name) == std::string::npos) return false;
00036   std::string prefix_str = name.substr(0,(name.find(":")));
00037   prefix_str += "/"; 
00038   std::string temp_str = name.substr(name.find(":")+1);
00039   std::vector<std::string> values;
00040   split(temp_str, values, ",");
00041   for (std::vector<std::string>::iterator it = values.begin();
00042        it != values.end(); it++) {
00043     if ((*it).find(me_name) != std::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 SiStripUtility::split(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters) {
00055   // Skip delimiters at beginning.
00056   std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00057 
00058   // Find first "non-delimiter".
00059   std::string::size_type pos = str.find_first_of(delimiters, lastPos);
00060 
00061   while (std::string::npos != pos || std::string::npos != lastPos)  {
00062     // Found a token, add it to the std::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 SiStripUtility::getMEStatusColor(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 SiStripUtility::getMEStatusColor(int status, int& icol, std::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 SiStripUtility::getDetectorStatusColor(int status, int& rval, int&gval, int& bval) {
00113   // No Error
00114   if (status == 0) {
00115     rval = 0; gval = 255;bval = 0;
00116     return;
00117   }
00118   // Error detected in FED Channel
00119   if (((status >> 0) & 0x1) > 0) { 
00120     rval = 150; gval = 0; bval = 0; 
00121     return;
00122   }
00123   // Excluded FED Channel 
00124   if (((status >> 3) & 0x1) > 0) {
00125     rval = 100; gval = 100; bval = 255; 
00126     return;
00127   }
00128   // DCS Error
00129   if (((status >> 4) & 0x1) > 0) {
00130     rval = 200; gval = 20; bval = 255; 
00131     return;
00132   } 
00133   // Digi and Cluster Problem   
00134   if (((status >> 1) & 0x1) > 0) {
00135     rval = 255; bval = 0;
00136     if (((status >> 2) & 0x1) > 0) gval = 0;
00137     else gval = 100;
00138   } else {
00139     rval = 251; gval = 0; bval = 100;   
00140   }
00141 }
00142 
00143 //
00144 // -- Get Status of Monitor Element
00145 //
00146 int SiStripUtility::getMEStatus(MonitorElement* me) {
00147   int status = 0; 
00148   if (me->getQReports().size() == 0) {
00149     status = 0;
00150   } else if (me->hasError()) {
00151     status = dqm::qstatus::ERROR;
00152   } else if (me->hasWarning()) {
00153     status = dqm::qstatus::WARNING;
00154   } else if (me->hasOtherReport()) {
00155     status = dqm::qstatus::OTHER;
00156   } else {  
00157     status = dqm::qstatus::STATUS_OK;
00158   }
00159   return status;
00160 }
00161 //
00162 // --  Fill Module Names
00163 // 
00164 void SiStripUtility::getModuleFolderList(DQMStore * dqm_store, std::vector<std::string>& mfolders){
00165   std::string currDir = dqm_store->pwd();
00166   if (currDir.find("module_") != std::string::npos)  {
00167     //    std::string mId = currDir.substr(currDir.find("module_")+7, 9);
00168     mfolders.push_back(currDir);
00169   } else {  
00170     std::vector<std::string> subdirs = dqm_store->getSubdirs();
00171     for (std::vector<std::string>::const_iterator it = subdirs.begin();
00172          it != subdirs.end(); it++) {
00173       dqm_store->cd(*it);
00174       getModuleFolderList(dqm_store, mfolders);
00175       dqm_store->goUp();
00176     }
00177   }
00178 }
00179 //
00180 // -- Get Status of Monitor Element
00181 //
00182 int SiStripUtility::getMEStatus(MonitorElement* me, int& bad_channels) {
00183   int status = 0; 
00184   if (me->getQReports().size() == 0) {
00185     status       = 0;
00186     bad_channels = -1;
00187   } else {
00188     std::vector<QReport *> qreports = me->getQReports();
00189     bad_channels =qreports[0]->getBadChannels().size();
00190     if (me->hasError()) {
00191       status = dqm::qstatus::ERROR;
00192     } else if (me->hasWarning()) {
00193       status = dqm::qstatus::WARNING;
00194     } else if (me->hasOtherReport()) {
00195       status = dqm::qstatus::OTHER;
00196     } else {  
00197       status = dqm::qstatus::STATUS_OK;
00198     }
00199   }
00200   return status;
00201 }
00202 //
00203 // -- Get Status of Monitor Element
00204 //
00205 void SiStripUtility::getMEValue(MonitorElement* me, std::string & val){
00206   val = "";
00207   if ( me && ( me->kind()==MonitorElement::DQM_KIND_REAL || me->kind()==MonitorElement::DQM_KIND_INT ) ) {
00208     val = me->valueString();
00209     val = val.substr(val.find("=")+1);
00210   }
00211 }
00212 //
00213 // -- go to a given Directory
00214 //
00215 bool SiStripUtility::goToDir(DQMStore * dqm_store, std::string name) {
00216   std::string currDir = dqm_store->pwd();
00217   std::string dirName = currDir.substr(currDir.find_last_of("/")+1);
00218   if (dirName.find(name) == 0) {
00219     return true;
00220   }
00221   std::vector<std::string> subDirVec = dqm_store->getSubdirs();
00222   for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
00223        ic != subDirVec.end(); ic++) {
00224     std::string fname = (*ic);
00225     if (
00226         (fname.find("Reference") != std::string::npos) ||
00227         (fname.find("AlCaReco")  != std::string::npos) ||
00228         (fname.find("HLT")       != std::string::npos) 
00229         ) continue;
00230     dqm_store->cd(fname);
00231     if (!goToDir(dqm_store, name))  dqm_store->goUp();
00232     else return true;
00233   }
00234   return false;  
00235 }
00236 //
00237 // -- Get Sub Detector tag from DetId
00238 //
00239 void SiStripUtility::getSubDetectorTag(uint32_t det_id, std::string& subdet_tag, const TrackerTopology* tTopo) {
00240   StripSubdetector subdet(det_id);
00241   subdet_tag = "";
00242   switch (subdet.subdetId()) 
00243     {
00244     case StripSubdetector::TIB:
00245       {
00246         subdet_tag = "TIB";
00247         break;
00248       }
00249     case StripSubdetector::TID:
00250       {
00251         
00252         if (tTopo->tidSide(det_id) == 2) {
00253           subdet_tag = "TIDF";
00254         }  else if (tTopo->tidSide(det_id) == 1) {
00255           subdet_tag = "TIDB";
00256         }
00257         break;       
00258       }
00259     case StripSubdetector::TOB:
00260       {
00261         subdet_tag = "TOB";
00262         break;
00263       }
00264     case StripSubdetector::TEC:
00265       {
00266         
00267         if (tTopo->tecSide(det_id) == 2) {
00268           subdet_tag = "TECF";
00269         }  else if (tTopo->tecSide(det_id) == 1) {
00270           subdet_tag = "TECB";  
00271         }
00272         break;       
00273       }
00274     }
00275 }
00276 //
00277 // -- Set Bad Channel Flag from hname
00278 // 
00279 void SiStripUtility::setBadModuleFlag(std::string & hname, uint16_t& flg){
00280   
00281   if (hname.find("FractionOfBadChannels")   != std::string::npos) flg |= (1<<0);
00282   else if (hname.find("NumberOfDigi")       != std::string::npos) flg |= (1<<1);
00283   else if (hname.find("NumberOfCluster")    != std::string::npos) flg |= (1<<2);
00284   else if (hname.find("ExcludedFedChannel") != std::string::npos) flg |= (1<<3);
00285   else if (hname.find("DCSError")           != std::string::npos) flg |= (1<<4); 
00286 }  
00287 //
00288 // -- Get the Status Message from Bad Module Flag
00289 //
00290 void SiStripUtility::getBadModuleStatus(uint16_t flag, std::string & message){
00291   if (flag == 0) message += " No Error";
00292   else {
00293     //    message += " Error from :: "; 
00294     if (((flag >> 0) & 0x1) > 0) message += " Fed BadChannel : ";
00295     if (((flag >> 1) & 0x1) > 0) message += " # of Digi : ";  
00296     if (((flag >> 2) & 0x1) > 0) message += " # of Clusters :";
00297     if (((flag >> 3) & 0x1) > 0) message += " Excluded FED Channel ";
00298     if (((flag >> 4) & 0x1) > 0) message += " DCSError "; 
00299   }
00300 }
00301 //
00302 // -- Set Event Info Folder
00303 //
00304 void SiStripUtility::getTopFolderPath(DQMStore * dqm_store, std::string type, std::string& path) {
00305   if (type != "SiStrip" && type != "Tracking") return;
00306   path = ""; 
00307   dqm_store->cd();
00308   if (type == "SiStrip") {
00309     if (dqm_store->dirExists(type)) {
00310       dqm_store->cd(type);
00311       path = dqm_store->pwd();
00312     } else {
00313       if (SiStripUtility::goToDir(dqm_store, type)) {
00314         std::string mdir = "MechanicalView";
00315         if (SiStripUtility::goToDir(dqm_store, mdir)) {
00316           path = dqm_store->pwd(); 
00317           path = path.substr(0, path.find(mdir)-1);
00318         }
00319       }
00320     }
00321   } else if (type == "Tracking") {
00322     std::string top_dir = "Tracking";
00323     if (dqm_store->dirExists(top_dir)) {
00324       dqm_store->cd(top_dir);
00325       path = dqm_store->pwd();
00326     } else {
00327       if (SiStripUtility::goToDir(dqm_store, top_dir)) {
00328         std::string tdir = "TrackParameters";
00329         if (SiStripUtility::goToDir(dqm_store, tdir)) {
00330           path = dqm_store->pwd(); 
00331           path = path.substr(0, path.find(tdir)-1);
00332         }
00333       } 
00334     }
00335   }
00336 }