CMS 3D CMS Logo

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 using namespace std;
00005 //
00006 // Get a list of MEs in a folder
00007 //
00008 int SiStripUtility::getMEList(string name, vector<string>& values) {
00009   values.clear();
00010   string prefix_str = name.substr(0,(name.find(":")));
00011   prefix_str += "/"; 
00012   string temp_str = name.substr(name.find(":")+1);
00013   split(temp_str, values, ",");
00014   for (vector<string>::iterator it = values.begin();
00015        it != values.end(); it++) (*it).insert(0,prefix_str);
00016   return values.size();
00017 }
00018 //
00019 // Get a list of MEs in a folder and the path name
00020 //
00021 int SiStripUtility::getMEList(string name, string& dir_path, vector<string>& values) {
00022   values.clear();
00023   dir_path = name.substr(0,(name.find(":")));
00024   dir_path += "/"; 
00025   string temp_str = name.substr(name.find(":")+1);
00026   split(temp_str, values, ",");
00027   return values.size();
00028 }
00029 
00030 // Check if the requested ME exists in a folder
00031 bool SiStripUtility::checkME(string name, string me_name, string& full_path) {
00032   if (name.find(name) == string::npos) return false;
00033   string prefix_str = name.substr(0,(name.find(":")));
00034   prefix_str += "/"; 
00035   string temp_str = name.substr(name.find(":")+1);
00036   vector<string> values;
00037   split(temp_str, values, ",");
00038   for (vector<string>::iterator it = values.begin();
00039        it != values.end(); it++) {
00040     if ((*it).find(me_name) != string::npos) {
00041       full_path = prefix_str + (*it);
00042       return true;
00043     }
00044   }
00045   return false;
00046 }
00047 //
00048 // -- Split a given string into a number of strings using given
00049 //    delimiters and fill a vector with splitted strings
00050 //
00051 void SiStripUtility::split(const string& str, vector<string>& tokens, const string& delimiters) {
00052   // Skip delimiters at beginning.
00053   string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00054 
00055   // Find first "non-delimiter".
00056   string::size_type pos = str.find_first_of(delimiters, lastPos);
00057 
00058   while (string::npos != pos || string::npos != lastPos)  {
00059     // Found a token, add it to the vector.
00060     tokens.push_back(str.substr(lastPos, pos - lastPos));
00061 
00062     // Skip delimiters.  Note the "not_of"
00063     lastPos = str.find_first_not_of(delimiters, pos);
00064 
00065     // Find next "non-delimiter"
00066     pos = str.find_first_of(delimiters, lastPos);
00067   }
00068 }
00069 //
00070 // -- Get Color code from Status
00071 //
00072 void SiStripUtility::getMEStatusColor(int status, int& rval, int&gval, int& bval) {
00073   if (status == dqm::qstatus::STATUS_OK) { 
00074     rval = 0;   gval = 255;   bval = 0; 
00075   } else if (status == dqm::qstatus::WARNING) { 
00076     rval = 255; gval = 255; bval = 0;
00077   } else if (status == dqm::qstatus::ERROR) { 
00078     rval = 255; gval = 0;  bval = 0;
00079   } else if (status == dqm::qstatus::OTHER) { 
00080     rval = 255; gval = 150;  bval = 0;
00081   } else {
00082     rval = 0; gval = 0;  bval = 255;
00083   }        
00084 }
00085 //
00086 // -- Get Color code from Status
00087 //
00088 void SiStripUtility::getMEStatusColor(int status, int& icol, string& tag) {
00089   if (status == dqm::qstatus::STATUS_OK) { 
00090     tag = "Ok";
00091     icol = 3;
00092   } else if (status == dqm::qstatus::WARNING) { 
00093     tag = "Warning";
00094     icol = 5;     
00095   } else if (status == dqm::qstatus::ERROR) { 
00096     tag = "Error";
00097     icol = 2;
00098   } else if (status == dqm::qstatus::OTHER) { 
00099     tag = "Other";
00100     icol = 1;
00101   } else {
00102     tag = " ";
00103     icol = 1;
00104   }     
00105 }
00106 //
00107 // -- Get Status of Monitor Element
00108 //
00109 int SiStripUtility::getMEStatus(MonitorElement* me) {
00110   int status = 0; 
00111   if (me->getQReports().size() == 0) {
00112     status = 0;
00113   } else if (me->hasError()) {
00114     status = dqm::qstatus::ERROR;
00115   } else if (me->hasWarning()) {
00116     status = dqm::qstatus::WARNING;
00117   } else if (me->hasOtherReport()) {
00118     status = dqm::qstatus::OTHER;
00119   } else {  
00120     status = dqm::qstatus::STATUS_OK;
00121   }
00122   return status;
00123 }
00124 //
00125 // --  Fill Module Names
00126 // 
00127 void SiStripUtility::getModuleFolderList(DQMStore * dqm_store, vector<string>& mfolders){
00128   string currDir = dqm_store->pwd();
00129   if (currDir.find("module_") != string::npos)  {
00130     string mId = currDir.substr(currDir.find("module_")+7, 9);
00131     mfolders.push_back(mId);
00132   } else {  
00133     vector<string> subdirs = dqm_store->getSubdirs();
00134     for (vector<string>::const_iterator it = subdirs.begin();
00135          it != subdirs.end(); it++) {
00136       dqm_store->cd(*it);
00137       getModuleFolderList(dqm_store, mfolders);
00138       dqm_store->goUp();
00139     }
00140   }
00141 }
00142 //
00143 // -- Get Status of Monitor Element
00144 //
00145 int SiStripUtility::getMEStatus(MonitorElement* me, int& bad_channels) {
00146   int status = 0; 
00147   if (me->getQReports().size() == 0) {
00148     status       = 0;
00149     bad_channels = -1;
00150   } else {
00151     std::vector<QReport *> qreports = me->getQReports();
00152     bad_channels =qreports[0]->getBadChannels().size();
00153     if (me->hasError()) {
00154       status = dqm::qstatus::ERROR;
00155     } else if (me->hasWarning()) {
00156       status = dqm::qstatus::WARNING;
00157     } else if (me->hasOtherReport()) {
00158       status = dqm::qstatus::OTHER;
00159     } else {  
00160       status = dqm::qstatus::STATUS_OK;
00161     }
00162   }
00163   return status;
00164 }

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