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
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
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
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
00054
00055
00056 void SiStripUtility::split(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters) {
00057
00058 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00059
00060
00061 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
00062
00063 while (std::string::npos != pos || std::string::npos != lastPos) {
00064
00065 tokens.push_back(str.substr(lastPos, pos - lastPos));
00066
00067
00068 lastPos = str.find_first_not_of(delimiters, pos);
00069
00070
00071 pos = str.find_first_of(delimiters, lastPos);
00072 }
00073 }
00074
00075
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
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
00113
00114 void SiStripUtility::getDetectorStatusColor(int status, int& rval, int&gval, int& bval) {
00115
00116 if (status == 0) {
00117 rval = 0; gval = 255;bval = 0;
00118 return;
00119 }
00120
00121 if (((status >> 0) & 0x1) > 0) {
00122 rval = 150; gval = 0; bval = 0;
00123 return;
00124 }
00125
00126 if (((status >> 3) & 0x1) > 0) {
00127 rval = 100; gval = 100; bval = 255;
00128 return;
00129 }
00130
00131 if (((status >> 4) & 0x1) > 0) {
00132 rval = 200; gval = 20; bval = 255;
00133 return;
00134 }
00135
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
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
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
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
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
00206
00207 void SiStripUtility::getMEValue(MonitorElement* me, std::string & val){
00208 val = "";
00209 if (me && ( me->kind()==MonitorElement::DQM_KIND_REAL || me->kind()==MonitorElement::DQM_KIND_INT ) ) {
00210 val = me->valueString();
00211 val = val.substr(val.find("=")+1);
00212 }
00213 }
00214
00215
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) ||
00229 (fname.find("HLT") != std::string::npos) ) 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
00238
00239 void SiStripUtility::getSubDetectorTag(uint32_t det_id, std::string& subdet_tag) {
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 TIDDetId tidId(det_id);
00252 if (tidId.side() == 2) {
00253 subdet_tag = "TIDF";
00254 } else if (tidId.side() == 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 TECDetId tecId(det_id);
00267 if (tecId.side() == 2) {
00268 subdet_tag = "TECF";
00269 } else if (tecId.side() == 1) {
00270 subdet_tag = "TECB";
00271 }
00272 break;
00273 }
00274 }
00275 }
00276
00277
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
00289
00290 void SiStripUtility::getBadModuleStatus(uint16_t flag, std::string & message){
00291 if (flag == 0) message += " No Error";
00292 else {
00293
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
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 }