File indexing completed on 2024-04-06 12:08:19
0001 #include "DQM/SiPixelMonitorClient/interface/SiPixelContinuousPalette.h"
0002 #include "DQM/SiPixelMonitorClient/interface/SiPixelUtility.h"
0003 #include "DQMServices/Core/interface/DQMStore.h"
0004 #include <cstdlib>
0005
0006 using namespace std;
0007
0008
0009
0010 int SiPixelUtility::getMEList(string name, vector<string> &values) {
0011 values.clear();
0012 string prefix_str = name.substr(0, (name.find(':')));
0013 prefix_str += "/";
0014 string temp_str = name.substr(name.find(':') + 1);
0015 split(temp_str, values, ",");
0016 for (vector<string>::iterator it = values.begin(); it != values.end(); it++)
0017 (*it).insert(0, prefix_str);
0018 return values.size();
0019 }
0020
0021
0022
0023 int SiPixelUtility::getMEList(string name, string &dir_path, vector<string> &values) {
0024 values.clear();
0025 dir_path = name.substr(0, (name.find(':')));
0026 dir_path += "/";
0027 string temp_str = name.substr(name.find(':') + 1);
0028 split(temp_str, values, ",");
0029 return values.size();
0030 }
0031
0032
0033 bool SiPixelUtility::checkME(string name, string me_name, string &full_path) {
0034 if (name.find(name) == string::npos)
0035 return false;
0036 string prefix_str = name.substr(0, (name.find(':')));
0037 prefix_str += "/";
0038 string temp_str = name.substr(name.find(':') + 1);
0039 vector<string> values;
0040 split(temp_str, values, ",");
0041 for (vector<string>::iterator it = values.begin(); it != values.end(); it++) {
0042 if ((*it).find(me_name) != string::npos) {
0043 full_path = prefix_str + (*it);
0044 return true;
0045 }
0046 }
0047 return false;
0048 }
0049
0050
0051
0052
0053 void SiPixelUtility::split(const string &str, vector<string> &tokens, const string &delimiters) {
0054
0055 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
0056
0057
0058 string::size_type pos = str.find_first_of(delimiters, lastPos);
0059
0060 while (string::npos != pos || string::npos != lastPos) {
0061
0062 tokens.push_back(str.substr(lastPos, pos - lastPos));
0063
0064
0065 lastPos = str.find_first_not_of(delimiters, pos);
0066
0067
0068 pos = str.find_first_of(delimiters, lastPos);
0069 }
0070 }
0071
0072
0073
0074 void SiPixelUtility::getStatusColor(int status, int &rval, int &gval, int &bval) {
0075 if (status == dqm::qstatus::STATUS_OK) {
0076 rval = 0;
0077 gval = 255;
0078 bval = 0;
0079 } else if (status == dqm::qstatus::WARNING) {
0080 rval = 255;
0081 gval = 255;
0082 bval = 0;
0083 } else if (status == dqm::qstatus::ERROR) {
0084 rval = 255;
0085 gval = 0;
0086 bval = 0;
0087 } else if (status == dqm::qstatus::OTHER) {
0088 rval = 255;
0089 gval = 150;
0090 bval = 0;
0091 } else {
0092 rval = 0;
0093 gval = 0;
0094 bval = 255;
0095 }
0096 }
0097
0098
0099
0100 void SiPixelUtility::getStatusColor(int status, int &icol, string &tag) {
0101 if (status == dqm::qstatus::STATUS_OK) {
0102 tag = "Ok";
0103 icol = 3;
0104 } else if (status == dqm::qstatus::WARNING) {
0105 tag = "Warning";
0106 icol = 5;
0107 } else if (status == dqm::qstatus::ERROR) {
0108 tag = "Error";
0109 icol = 2;
0110 } else if (status == dqm::qstatus::OTHER) {
0111 tag = "Other";
0112 icol = 1;
0113 } else {
0114 tag = " ";
0115 icol = 1;
0116 }
0117 }
0118
0119
0120
0121 void SiPixelUtility::getStatusColor(double status, int &rval, int &gval, int &bval) {
0122 rval = SiPixelContinuousPalette::r[(int)(status * 100)];
0123 gval = SiPixelContinuousPalette::g[(int)(status * 100)];
0124 bval = SiPixelContinuousPalette::b[(int)(status * 100)];
0125 }
0126
0127
0128
0129 int SiPixelUtility::getStatus(MonitorElement *me) {
0130 int status = 0;
0131 if (me->getQReports().empty()) {
0132 status = 0;
0133 } else if (me->hasError()) {
0134 status = dqm::qstatus::ERROR;
0135 } else if (me->hasWarning()) {
0136 status = dqm::qstatus::WARNING;
0137 } else if (me->hasOtherReport()) {
0138 status = dqm::qstatus::OTHER;
0139 } else {
0140 status = dqm::qstatus::STATUS_OK;
0141 }
0142 return status;
0143 }
0144
0145 vector<string> SiPixelUtility::getQTestNameList(MonitorElement *me) {
0146 vector<string> qtestNameList;
0147 return qtestNameList;
0148 }
0149
0150 int SiPixelUtility::computeErrorCode(int status) {
0151 int code = 0;
0152 switch (status) {
0153 case dqm::qstatus::INSUF_STAT:
0154 code = 1;
0155 break;
0156 case dqm::qstatus::WARNING:
0157 code = 2;
0158 break;
0159 case dqm::qstatus::ERROR:
0160 code = 3;
0161 break;
0162 }
0163
0164 return code;
0165 }
0166
0167 int SiPixelUtility::computeHistoBin(string &module_path) {
0168 int module_bin = 0;
0169
0170 int module = 0;
0171 int shell = 0;
0172 int layer = 0;
0173 int ladder = 0;
0174 int halfcylinder = 0;
0175 int disk = 0;
0176 int blade = 0;
0177 int panel = 0;
0178
0179 int nbinShell = 192;
0180 int nbinLayer = 0;
0181 int nbinLadder = 4;
0182
0183 int nbinHalfcylinder = 168;
0184 int nbinDisk = 84;
0185 int nbinBlade = 7;
0186 int nbinPanel = 0;
0187
0188 vector<string> subDirVector;
0189 SiPixelUtility::split(module_path, subDirVector, "/");
0190
0191 for (vector<string>::const_iterator it = subDirVector.begin(); it != subDirVector.end(); it++) {
0192 if ((*it).find("Collector") != string::npos ||
0193
0194 (*it).find("FU") != string::npos || (*it).find("Pixel") != string::npos ||
0195 (*it).find("Barrel") != string::npos || (*it).find("Endcap") != string::npos)
0196 continue;
0197
0198 if ((*it).find("Module") != string::npos) {
0199 module = atoi((*it).substr((*it).find("_") + 1).c_str());
0200 }
0201
0202 if ((*it).find("Shell") != string::npos) {
0203 if ((*it).find("mI") != string::npos)
0204 shell = 1;
0205 if ((*it).find("mO") != string::npos)
0206 shell = 2;
0207 if ((*it).find("pI") != string::npos)
0208 shell = 3;
0209 if ((*it).find("pO") != string::npos)
0210 shell = 4;
0211 }
0212 if ((*it).find("Layer") != string::npos) {
0213 layer = atoi((*it).substr((*it).find("_") + 1).c_str());
0214 if (layer == 1) {
0215 nbinLayer = 0;
0216 }
0217 if (layer == 2) {
0218 nbinLayer = 40;
0219 }
0220 if (layer == 3) {
0221 nbinLayer = 40 + 64;
0222 }
0223 }
0224 if ((*it).find("Ladder") != string::npos) {
0225 ladder = atoi((*it).substr((*it).find("_") + 1, 2).c_str());
0226 }
0227 if ((*it).find("HalfCylinder") != string::npos) {
0228 if ((*it).find("mI") != string::npos)
0229 halfcylinder = 1;
0230 if ((*it).find("mO") != string::npos)
0231 halfcylinder = 2;
0232 if ((*it).find("pI") != string::npos)
0233 halfcylinder = 3;
0234 if ((*it).find("pO") != string::npos)
0235 halfcylinder = 4;
0236 }
0237 if ((*it).find("Disk") != string::npos) {
0238 disk = atoi((*it).substr((*it).find("_") + 1).c_str());
0239 }
0240 if ((*it).find("Blade") != string::npos) {
0241 blade = atoi((*it).substr((*it).find("_") + 1, 2).c_str());
0242 }
0243 if ((*it).find("Panel") != string::npos) {
0244 panel = atoi((*it).substr((*it).find("_") + 1).c_str());
0245 if (panel == 1)
0246 nbinPanel = 0;
0247 if (panel == 2)
0248 nbinPanel = 4;
0249 }
0250 }
0251 if (module_path.find("Barrel") != string::npos) {
0252 module_bin = module + (ladder - 1) * nbinLadder + nbinLayer + (shell - 1) * nbinShell;
0253 }
0254 if (module_path.find("Endcap") != string::npos) {
0255 module_bin = module + (panel - 1) * nbinPanel + (blade - 1) * nbinBlade + (disk - 1) * nbinDisk +
0256 (halfcylinder - 1) * nbinHalfcylinder;
0257 }
0258
0259 return module_bin;
0260
0261
0262 }
0263
0264 void SiPixelUtility::fillPaveText(TPaveText *pave, const map<string, pair<int, double>> &messages) {
0265 TText *sourceCodeOnCanvas;
0266 for (map<string, pair<int, double>>::const_iterator it = messages.begin(); it != messages.end(); it++) {
0267 string message = it->first;
0268 int color = (it->second).first;
0269 double size = (it->second).second;
0270 sourceCodeOnCanvas = pave->AddText(message.c_str());
0271 sourceCodeOnCanvas->SetTextColor(color);
0272 sourceCodeOnCanvas->SetTextSize(size);
0273 sourceCodeOnCanvas->SetTextFont(112);
0274 }
0275 }
0276
0277 map<string, string> SiPixelUtility::sourceCodeMap() {
0278 map<string, string> sourceCode;
0279 for (int iSource = 0; iSource < 5; iSource++) {
0280 string type;
0281 string code;
0282 switch (iSource) {
0283 case 0:
0284 type = "RAW";
0285 code = "1 ";
0286 break;
0287 case 1:
0288 type = "DIG";
0289 code = "10 ";
0290 break;
0291 case 2:
0292 type = "CLU";
0293 code = "100 ";
0294 break;
0295 case 3:
0296 type = "TRK";
0297 code = "1000 ";
0298 break;
0299 case 4:
0300 type = "REC";
0301 code = "10000";
0302 break;
0303 }
0304 sourceCode[type] = code;
0305 }
0306 return sourceCode;
0307 }
0308
0309 void SiPixelUtility::createStatusLegendMessages(map<string, pair<int, double>> &messages) {
0310 for (int iStatus = 1; iStatus < 5; iStatus++) {
0311 pair<int, double> color_size;
0312 int color = 1;
0313 double size = 0.03;
0314 string code;
0315 string type;
0316 color_size.second = size;
0317 switch (iStatus) {
0318 case 1:
0319 code = "1";
0320 type = "INSUF_STAT";
0321 color = kBlue;
0322 break;
0323 case 2:
0324 code = "2";
0325 type = "WARNING(S)";
0326 color = kYellow;
0327 break;
0328 case 3:
0329 code = "3";
0330 type = "ERROR(S) ";
0331 color = kRed;
0332 break;
0333 case 4:
0334 code = "4";
0335 type = "ERRORS ";
0336 color = kMagenta;
0337 break;
0338 }
0339 string messageString = code + ": " + type;
0340 color_size.first = color;
0341 messages[messageString] = color_size;
0342 }
0343 }
0344
0345
0346
0347
0348
0349 void SiPixelUtility::setDrawingOption(TH1 *hist, float xlow, float xhigh) {
0350 if (!hist)
0351 return;
0352
0353 TAxis *xa = hist->GetXaxis();
0354 TAxis *ya = hist->GetYaxis();
0355
0356 xa->SetTitleOffset(0.7);
0357 xa->SetTitleSize(0.06);
0358 xa->SetLabelSize(0.04);
0359
0360
0361 ya->SetTitleOffset(0.7);
0362 ya->SetTitleSize(0.06);
0363
0364 if (xlow != -1 && xhigh != -1.0) {
0365 xa->SetRangeUser(xlow, xhigh);
0366 }
0367 }