File indexing completed on 2024-04-06 12:09:10
0001 #include "DQM/TrackingMonitorClient/interface/TrackingUtility.h"
0002 #include "DQMServices/Core/interface/DQMStore.h"
0003
0004 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0005
0006
0007
0008 int TrackingUtility::getMEList(std::string name, std::vector<std::string>& values) {
0009 values.clear();
0010 std::string prefix_str = name.substr(0, (name.find(':')));
0011 prefix_str += "/";
0012 std::string temp_str = name.substr(name.find(':') + 1);
0013 split(temp_str, values, ",");
0014 for (std::vector<std::string>::iterator it = values.begin(); it != values.end(); it++)
0015 (*it).insert(0, prefix_str);
0016 return values.size();
0017 }
0018
0019
0020
0021 int TrackingUtility::getMEList(std::string name, std::string& dir_path, std::vector<std::string>& values) {
0022 values.clear();
0023 dir_path = name.substr(0, (name.find(':')));
0024 dir_path += "/";
0025 std::string temp_str = name.substr(name.find(':') + 1);
0026 split(temp_str, values, ",");
0027 return values.size();
0028 }
0029
0030
0031 bool TrackingUtility::checkME(std::string name, std::string me_name, std::string& full_path) {
0032 if (name.find(name) == std::string::npos)
0033 return false;
0034 std::string prefix_str = name.substr(0, (name.find(':')));
0035 prefix_str += "/";
0036 std::string temp_str = name.substr(name.find(':') + 1);
0037 std::vector<std::string> values;
0038 split(temp_str, values, ",");
0039 for (std::vector<std::string>::iterator it = values.begin(); it != values.end(); it++) {
0040 if ((*it).find(me_name) != std::string::npos) {
0041 full_path = prefix_str + (*it);
0042 return true;
0043 }
0044 }
0045 return false;
0046 }
0047
0048
0049
0050
0051 void TrackingUtility::split(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters) {
0052
0053 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
0054
0055
0056 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
0057
0058 while (std::string::npos != pos || std::string::npos != lastPos) {
0059
0060 tokens.push_back(str.substr(lastPos, pos - lastPos));
0061
0062
0063 lastPos = str.find_first_not_of(delimiters, pos);
0064
0065
0066 pos = str.find_first_of(delimiters, lastPos);
0067 }
0068 }
0069
0070
0071
0072 void TrackingUtility::getMEStatusColor(int status, int& rval, int& gval, int& bval) {
0073 if (status == dqm::qstatus::STATUS_OK) {
0074 rval = 0;
0075 gval = 255;
0076 bval = 0;
0077 } else if (status == dqm::qstatus::WARNING) {
0078 rval = 255;
0079 gval = 255;
0080 bval = 0;
0081 } else if (status == dqm::qstatus::ERROR) {
0082 rval = 255;
0083 gval = 0;
0084 bval = 0;
0085 } else if (status == dqm::qstatus::OTHER) {
0086 rval = 255;
0087 gval = 150;
0088 bval = 0;
0089 } else {
0090 rval = 0;
0091 gval = 0;
0092 bval = 255;
0093 }
0094 }
0095
0096
0097
0098 void TrackingUtility::getMEStatusColor(int status, int& icol, std::string& tag) {
0099 if (status == dqm::qstatus::STATUS_OK) {
0100 tag = "Ok";
0101 icol = 3;
0102 } else if (status == dqm::qstatus::WARNING) {
0103 tag = "Warning";
0104 icol = 5;
0105 } else if (status == dqm::qstatus::ERROR) {
0106 tag = "Error";
0107 icol = 2;
0108 } else if (status == dqm::qstatus::OTHER) {
0109 tag = "Other";
0110 icol = 1;
0111 } else {
0112 tag = " ";
0113 icol = 1;
0114 }
0115 }
0116
0117
0118
0119
0120 int TrackingUtility::getMEStatus(MonitorElement* me) {
0121 int status = 0;
0122 if (me->getQReports().empty()) {
0123 status = 0;
0124 } else if (me->hasError()) {
0125 status = dqm::qstatus::ERROR;
0126 } else if (me->hasWarning()) {
0127 status = dqm::qstatus::WARNING;
0128 } else if (me->hasOtherReport()) {
0129 status = dqm::qstatus::OTHER;
0130 } else {
0131 status = dqm::qstatus::STATUS_OK;
0132 }
0133 return status;
0134 }
0135
0136
0137
0138 void TrackingUtility::getModuleFolderList(DQMStore::IBooker& ibooker,
0139 DQMStore::IGetter& igetter,
0140 std::vector<std::string>& mfolders) {
0141 std::string currDir = ibooker.pwd();
0142 if (currDir.find("module_") != std::string::npos) {
0143
0144 mfolders.push_back(currDir);
0145 } else {
0146 std::vector<std::string> subdirs = igetter.getSubdirs();
0147 for (std::vector<std::string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
0148 ibooker.cd(*it);
0149 getModuleFolderList(ibooker, igetter, mfolders);
0150 ibooker.goUp();
0151 }
0152 }
0153 }
0154
0155
0156
0157 int TrackingUtility::getMEStatus(MonitorElement* me, int& bad_channels) {
0158 int status = 0;
0159 if (me->getQReports().empty()) {
0160 status = 0;
0161 bad_channels = -1;
0162 } else {
0163 std::vector<QReport*> qreports = me->getQReports();
0164 bad_channels = qreports[0]->getBadChannels().size();
0165 if (me->hasError()) {
0166 status = dqm::qstatus::ERROR;
0167 } else if (me->hasWarning()) {
0168 status = dqm::qstatus::WARNING;
0169 } else if (me->hasOtherReport()) {
0170 status = dqm::qstatus::OTHER;
0171 } else {
0172 status = dqm::qstatus::STATUS_OK;
0173 }
0174 }
0175 return status;
0176 }
0177
0178
0179
0180 void TrackingUtility::getMEValue(MonitorElement* me, std::string& val) {
0181 val = "";
0182 if (me) {
0183 if (me->kind() == MonitorElement::Kind::REAL) {
0184 val = std::to_string(me->getFloatValue());
0185 } else if (me->kind() == MonitorElement::Kind::INT) {
0186 val = std::to_string(me->getIntValue());
0187 }
0188 }
0189 }
0190
0191
0192
0193 bool TrackingUtility::goToDir(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, std::string name) {
0194 std::string currDir = ibooker.pwd();
0195 std::string dirName = currDir.substr(currDir.find_last_of('/') + 1);
0196 if (dirName.find(name) == 0) {
0197 return true;
0198 }
0199 std::vector<std::string> subDirVec = igetter.getSubdirs();
0200 for (std::vector<std::string>::const_iterator ic = subDirVec.begin(); ic != subDirVec.end(); ic++) {
0201 const std::string& fname = (*ic);
0202 if ((fname.find("Reference") != std::string::npos) || (fname.find("AlCaReco") != std::string::npos) ||
0203 (fname.find("HLT") != std::string::npos))
0204 continue;
0205 igetter.cd(fname);
0206 if (!goToDir(ibooker, igetter, name))
0207 ibooker.goUp();
0208 else
0209 return true;
0210 }
0211 return false;
0212 }
0213
0214
0215
0216 void TrackingUtility::setBadModuleFlag(std::string& hname, uint16_t& flg) {
0217 if (hname.find("FractionOfBadChannels") != std::string::npos)
0218 flg |= (1 << 0);
0219 else if (hname.find("NumberOfDigi") != std::string::npos)
0220 flg |= (1 << 1);
0221 else if (hname.find("NumberOfCluster") != std::string::npos)
0222 flg |= (1 << 2);
0223 else if (hname.find("ExcludedFedChannel") != std::string::npos)
0224 flg |= (1 << 3);
0225 else if (hname.find("DCSError") != std::string::npos)
0226 flg |= (1 << 4);
0227 }
0228
0229
0230
0231 void TrackingUtility::getBadModuleStatus(uint16_t flag, std::string& message) {
0232 if (flag == 0)
0233 message += " No Error";
0234 else {
0235
0236 if (((flag >> 0) & 0x1) > 0)
0237 message += " Fed BadChannel : ";
0238 if (((flag >> 1) & 0x1) > 0)
0239 message += " # of Digi : ";
0240 if (((flag >> 2) & 0x1) > 0)
0241 message += " # of Clusters :";
0242 if (((flag >> 3) & 0x1) > 0)
0243 message += " Excluded FED Channel ";
0244 if (((flag >> 4) & 0x1) > 0)
0245 message += " DCSError ";
0246 }
0247 }
0248
0249
0250
0251 void TrackingUtility::getTopFolderPath(DQMStore::IBooker& ibooker,
0252 DQMStore::IGetter& igetter,
0253 std::string top_dir,
0254 std::string& path) {
0255 path = "";
0256 ibooker.cd();
0257 if (igetter.dirExists(top_dir)) {
0258 ibooker.cd(top_dir);
0259 path = ibooker.pwd();
0260 } else {
0261 if (TrackingUtility::goToDir(ibooker, igetter, top_dir)) {
0262 std::string tdir = "TrackParameters";
0263 if (TrackingUtility::goToDir(ibooker, igetter, tdir)) {
0264 path = ibooker.pwd();
0265 path = path.substr(0, path.find(tdir) - 1);
0266 }
0267 }
0268 }
0269 }