Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:44

0001 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
0002 #include "DQMServices/Core/interface/DQMStore.h"
0003 
0004 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0005 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0006 
0007 //
0008 // Get a list of MEs in a folder
0009 //
0010 int SiStripUtility::getMEList(std::string const& name, std::vector<std::string>& values) {
0011   values.clear();
0012   auto prefix_str = name.substr(0, (name.find(':')));
0013   prefix_str += "/";
0014   auto const temp_str = name.substr(name.find(':') + 1);
0015   split(temp_str, values, ",");
0016   for (auto& value : values) {
0017     value.insert(0, prefix_str);
0018   }
0019   return values.size();
0020 }
0021 //
0022 // Get a list of MEs in a folder and the path name
0023 //
0024 int SiStripUtility::getMEList(std::string const& name, std::string& dir_path, std::vector<std::string>& values) {
0025   values.clear();
0026   dir_path = name.substr(0, (name.find(':')));
0027   dir_path += "/";
0028   auto const temp_str = name.substr(name.find(':') + 1);
0029   split(temp_str, values, ",");
0030   return values.size();
0031 }
0032 
0033 // Check if the requested ME exists in a folder
0034 bool SiStripUtility::checkME(std::string const& name, std::string const& me_name, std::string& full_path) {
0035   if (name.find(name) == std::string::npos)
0036     return false;
0037   auto prefix_str = name.substr(0, (name.find(':')));
0038   prefix_str += "/";
0039   auto const temp_str = name.substr(name.find(':') + 1);
0040   std::vector<std::string> values;
0041   split(temp_str, values, ",");
0042   for (auto const& value : values) {
0043     if (value.find(me_name) != std::string::npos) {
0044       full_path = prefix_str + value;
0045       return true;
0046     }
0047   }
0048   return false;
0049 }
0050 //
0051 // -- Split a given string into a number of strings using given
0052 //    delimiters and fill a vector with splitted strings
0053 //
0054 void SiStripUtility::split(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters) {
0055   // Skip delimiters at beginning.
0056   std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
0057 
0058   // Find first "non-delimiter".
0059   std::string::size_type pos = str.find_first_of(delimiters, lastPos);
0060 
0061   while (std::string::npos != pos || std::string::npos != lastPos) {
0062     // Found a token, add it to the std::vector.
0063     tokens.push_back(str.substr(lastPos, pos - lastPos));
0064 
0065     // Skip delimiters.  Note the "not_of"
0066     lastPos = str.find_first_not_of(delimiters, pos);
0067 
0068     // Find next "non-delimiter"
0069     pos = str.find_first_of(delimiters, lastPos);
0070   }
0071 }
0072 //
0073 // -- Get Color code from Status
0074 //
0075 void SiStripUtility::getMEStatusColor(int status, int& rval, int& gval, int& bval) {
0076   if (status == dqm::qstatus::STATUS_OK) {
0077     rval = 0;
0078     gval = 255;
0079     bval = 0;
0080   } else if (status == dqm::qstatus::WARNING) {
0081     rval = 255;
0082     gval = 255;
0083     bval = 0;
0084   } else if (status == dqm::qstatus::ERROR) {
0085     rval = 255;
0086     gval = 0;
0087     bval = 0;
0088   } else if (status == dqm::qstatus::OTHER) {
0089     rval = 255;
0090     gval = 150;
0091     bval = 0;
0092   } else {
0093     rval = 0;
0094     gval = 0;
0095     bval = 255;
0096   }
0097 }
0098 //
0099 // -- Get Color code from Status
0100 //
0101 void SiStripUtility::getMEStatusColor(int status, int& icol, std::string& tag) {
0102   if (status == dqm::qstatus::STATUS_OK) {
0103     tag = "Ok";
0104     icol = 3;
0105   } else if (status == dqm::qstatus::WARNING) {
0106     tag = "Warning";
0107     icol = 5;
0108   } else if (status == dqm::qstatus::ERROR) {
0109     tag = "Error";
0110     icol = 2;
0111   } else if (status == dqm::qstatus::OTHER) {
0112     tag = "Other";
0113     icol = 1;
0114   } else {
0115     tag = " ";
0116     icol = 1;
0117   }
0118 }
0119 //
0120 // -- Get Color code from Status
0121 //
0122 void SiStripUtility::getDetectorStatusColor(int status, int& rval, int& gval, int& bval) {
0123   // No Error
0124   if (status == 0) {
0125     rval = 0;
0126     gval = 255;
0127     bval = 0;
0128     return;
0129   }
0130   // Error detected in FED Channel
0131   if (((status >> 0) & 0x1) > 0) {
0132     rval = 150;
0133     gval = 0;
0134     bval = 0;
0135     return;
0136   }
0137   // Excluded FED Channel
0138   if (((status >> 3) & 0x1) > 0) {
0139     rval = 100;
0140     gval = 100;
0141     bval = 255;
0142     return;
0143   }
0144   // DCS Error
0145   if (((status >> 4) & 0x1) > 0) {
0146     rval = 200;
0147     gval = 20;
0148     bval = 255;
0149     return;
0150   }
0151   // Digi and Cluster Problem
0152   if (((status >> 1) & 0x1) > 0) {
0153     rval = 255;
0154     bval = 0;
0155     if (((status >> 2) & 0x1) > 0)
0156       gval = 0;
0157     else
0158       gval = 100;
0159   } else {
0160     rval = 251;
0161     gval = 0;
0162     bval = 100;
0163   }
0164 }
0165 
0166 //
0167 // -- Get Status of Monitor Element
0168 //
0169 int SiStripUtility::getMEStatus(MonitorElement const* me) {
0170   int status = 0;
0171   if (me->getQReports().empty()) {
0172     return status;
0173   } else if (me->hasError()) {
0174     status = dqm::qstatus::ERROR;
0175   } else if (me->hasWarning()) {
0176     status = dqm::qstatus::WARNING;
0177   } else if (me->hasOtherReport()) {
0178     status = dqm::qstatus::OTHER;
0179   } else {
0180     status = dqm::qstatus::STATUS_OK;
0181   }
0182   return status;
0183 }
0184 //
0185 // --  Fill Module Names
0186 //
0187 void SiStripUtility::getModuleFolderList(DQMStore& dqm_store, std::vector<std::string>& mfolders) {
0188   if (auto currDir = dqm_store.pwd(); currDir.find("module_") != std::string::npos) {
0189     mfolders.push_back(currDir);
0190   } else {
0191     auto const subdirs = dqm_store.getSubdirs();
0192     for (auto const& subdir : subdirs) {
0193       dqm_store.cd(subdir);
0194       getModuleFolderList(dqm_store, mfolders);
0195       dqm_store.goUp();
0196     }
0197   }
0198 }
0199 
0200 void SiStripUtility::getModuleFolderList(DQMStore::IBooker& ibooker,
0201                                          DQMStore::IGetter& igetter,
0202                                          std::vector<std::string>& mfolders) {
0203   if (auto currDir = ibooker.pwd(); currDir.find("module_") != std::string::npos) {
0204     mfolders.push_back(currDir);
0205   } else {
0206     auto const subdirs = igetter.getSubdirs();
0207     for (auto const& subdir : subdirs) {
0208       ibooker.cd(subdir);
0209       getModuleFolderList(ibooker, igetter, mfolders);
0210       ibooker.goUp();
0211     }
0212   }
0213 }
0214 //
0215 // -- Get Status of Monitor Element
0216 //
0217 int SiStripUtility::getMEStatus(MonitorElement const* me, int& bad_channels) {
0218   int status = 0;
0219   if (me->getQReports().empty()) {
0220     bad_channels = -1;
0221   } else {
0222     std::vector<QReport*> qreports = me->getQReports();
0223     bad_channels = qreports[0]->getBadChannels().size();
0224     if (me->hasError()) {
0225       status = dqm::qstatus::ERROR;
0226     } else if (me->hasWarning()) {
0227       status = dqm::qstatus::WARNING;
0228     } else if (me->hasOtherReport()) {
0229       status = dqm::qstatus::OTHER;
0230     } else {
0231       status = dqm::qstatus::STATUS_OK;
0232     }
0233   }
0234   return status;
0235 }
0236 //
0237 // -- Get Status of Monitor Element
0238 //
0239 void SiStripUtility::getMEValue(MonitorElement const* me, std::string& val) {
0240   val = "";
0241   if (me) {
0242     if (me->kind() == MonitorElement::Kind::REAL) {
0243       val = std::to_string(me->getFloatValue());
0244     } else if (me->kind() == MonitorElement::Kind::INT) {
0245       val = std::to_string(me->getIntValue());
0246     }
0247   }
0248 }
0249 //
0250 // -- go to a given Directory
0251 //
0252 bool SiStripUtility::goToDir(DQMStore& dqm_store, std::string const& name) {
0253   std::string currDir = dqm_store.pwd();
0254   std::string dirName = currDir.substr(currDir.find_last_of('/') + 1);
0255   if (dirName.find(name) == 0) {
0256     return true;
0257   }
0258   auto const subdirs = dqm_store.getSubdirs();
0259   for (auto const& fname : subdirs) {
0260     if ((fname.find("Reference") != std::string::npos) || (fname.find("AlCaReco") != std::string::npos) ||
0261         (fname.find("HLT") != std::string::npos) || (fname.find("IsolatedBunches") != std::string::npos))
0262       continue;
0263     dqm_store.cd(fname);
0264     if (!goToDir(dqm_store, name)) {
0265       dqm_store.goUp();
0266     } else {
0267       return true;
0268     }
0269   }
0270   return false;
0271 }
0272 
0273 bool SiStripUtility::goToDir(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, std::string const& name) {
0274   std::string currDir = ibooker.pwd();
0275   std::string dirName = currDir.substr(currDir.find_last_of('/') + 1);
0276   if (dirName.find(name) == 0) {
0277     return true;
0278   }
0279   auto const subdirs = igetter.getSubdirs();
0280   for (auto const& fname : subdirs) {
0281     if ((fname.find("Reference") != std::string::npos) || (fname.find("AlCaReco") != std::string::npos) ||
0282         (fname.find("HLT") != std::string::npos) || (fname.find("IsolatedBunches") != std::string::npos))
0283       continue;
0284     igetter.cd(fname);
0285     if (!goToDir(ibooker, igetter, name)) {
0286       ibooker.goUp();
0287     } else
0288       return true;
0289   }
0290   return false;
0291 }
0292 
0293 //
0294 // -- Get Sub Detector tag from DetId
0295 //
0296 void SiStripUtility::getSubDetectorTag(uint32_t const det_id, std::string& subdet_tag, const TrackerTopology* tTopo) {
0297   StripSubdetector const subdet(det_id);
0298   subdet_tag = "";
0299   switch (subdet.subdetId()) {
0300     case StripSubdetector::TIB: {
0301       subdet_tag = "TIB";
0302       return;
0303     }
0304     case StripSubdetector::TID: {
0305       if (tTopo->tidSide(det_id) == 2) {
0306         subdet_tag = "TIDF";
0307       } else if (tTopo->tidSide(det_id) == 1) {
0308         subdet_tag = "TIDB";
0309       }
0310       return;
0311     }
0312     case StripSubdetector::TOB: {
0313       subdet_tag = "TOB";
0314       return;
0315     }
0316     case StripSubdetector::TEC: {
0317       if (tTopo->tecSide(det_id) == 2) {
0318         subdet_tag = "TECF";
0319       } else if (tTopo->tecSide(det_id) == 1) {
0320         subdet_tag = "TECB";
0321       }
0322     }
0323   }
0324 }
0325 //
0326 // -- Set Bad Channel Flag from hname
0327 //
0328 void SiStripUtility::setBadModuleFlag(std::string& hname, uint16_t& flg) {
0329   if (hname.find("FractionOfBadChannels") != std::string::npos)
0330     flg |= (1 << 0);
0331   else if (hname.find("NumberOfDigi") != std::string::npos)
0332     flg |= (1 << 1);
0333   else if (hname.find("NumberOfCluster") != std::string::npos)
0334     flg |= (1 << 2);
0335   else if (hname.find("ExcludedFedChannel") != std::string::npos)
0336     flg |= (1 << 3);
0337   else if (hname.find("DCSError") != std::string::npos)
0338     flg |= (1 << 4);
0339 }
0340 //
0341 // -- Get the Status Message from Bad Module Flag
0342 //
0343 void SiStripUtility::getBadModuleStatus(uint16_t flag, std::string& message) {
0344   if (flag == 0)
0345     message += " No Error";
0346   else {
0347     if (((flag >> 0) & 0x1) > 0)
0348       message += " Fed BadChannel : ";
0349     if (((flag >> 1) & 0x1) > 0)
0350       message += " # of Digi : ";
0351     if (((flag >> 2) & 0x1) > 0)
0352       message += " # of Clusters :";
0353     if (((flag >> 3) & 0x1) > 0)
0354       message += " Excluded FED Channel ";
0355     if (((flag >> 4) & 0x1) > 0)
0356       message += " DCSError ";
0357   }
0358 }
0359 //
0360 // -- Set Event Info Folder
0361 //
0362 void SiStripUtility::getTopFolderPath(DQMStore& dqm_store, std::string const& top_dir, std::string& path) {
0363   path = "";
0364   dqm_store.cd();
0365   if (dqm_store.dirExists(top_dir)) {
0366     dqm_store.cd(top_dir);
0367     path = dqm_store.pwd();
0368   } else {
0369     if (SiStripUtility::goToDir(dqm_store, top_dir)) {
0370       std::string mdir = "MechanicalView";
0371       if (SiStripUtility::goToDir(dqm_store, mdir)) {
0372         path = dqm_store.pwd();
0373         path = path.substr(0, path.find(mdir) - 1);
0374       }
0375     }
0376   }
0377 }
0378 
0379 void SiStripUtility::getTopFolderPath(DQMStore::IBooker& ibooker,
0380                                       DQMStore::IGetter& igetter,
0381                                       std::string const& top_dir,
0382                                       std::string& path) {
0383   path = "";
0384   ibooker.cd();
0385   if (igetter.dirExists(top_dir)) {
0386     ibooker.cd(top_dir);
0387     path = ibooker.pwd();
0388   } else {
0389     if (SiStripUtility::goToDir(ibooker, igetter, top_dir)) {
0390       std::string tdir = "MechanicalView";
0391       if (SiStripUtility::goToDir(ibooker, igetter, tdir)) {
0392         path = ibooker.pwd();
0393         path = path.substr(0, path.find(tdir) - 1);
0394       }
0395     }
0396   }
0397 }