Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:42:01

0001 #include "DQM/EcalCommon/interface/StatusManager.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 
0005 #include "CondFormats/EcalObjects/interface/EcalDQMStatusHelper.h"
0006 
0007 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0008 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0009 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
0010 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0011 
0012 #include "TObjArray.h"
0013 #include "TPRegexp.h"
0014 #include "TString.h"
0015 
0016 namespace ecaldqm {
0017 
0018   StatusManager::StatusManager() : dictionary_(), status_() {
0019     dictionary_["CH_ID_ERROR"] = 0x1 << EcalDQMStatusHelper::CH_ID_ERROR;
0020     dictionary_["CH_GAIN_ZERO_ERROR"] = 0x1 << EcalDQMStatusHelper::CH_GAIN_ZERO_ERROR;
0021     dictionary_["CH_GAIN_SWITCH_ERROR"] = 0x1 << EcalDQMStatusHelper::CH_GAIN_SWITCH_ERROR;
0022     dictionary_["TT_ID_ERROR"] = 0x1 << EcalDQMStatusHelper::TT_ID_ERROR;
0023     dictionary_["TT_SIZE_ERROR"] = 0x1 << EcalDQMStatusHelper::TT_SIZE_ERROR;
0024 
0025     dictionary_["PEDESTAL_LOW_GAIN_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::PEDESTAL_LOW_GAIN_MEAN_ERROR;
0026     dictionary_["PEDESTAL_MIDDLE_GAIN_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::PEDESTAL_MIDDLE_GAIN_MEAN_ERROR;
0027     dictionary_["PEDESTAL_HIGH_GAIN_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::PEDESTAL_HIGH_GAIN_MEAN_ERROR;
0028     dictionary_["PEDESTAL_LOW_GAIN_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::PEDESTAL_LOW_GAIN_RMS_ERROR;
0029     dictionary_["PEDESTAL_MIDDLE_GAIN_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::PEDESTAL_MIDDLE_GAIN_RMS_ERROR;
0030     dictionary_["PEDESTAL_HIGH_GAIN_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::PEDESTAL_HIGH_GAIN_RMS_ERROR;
0031 
0032     dictionary_["PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR"] = 0x1
0033                                                           << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR;
0034     dictionary_["PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR"] = 0x1
0035                                                          << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR;
0036 
0037     dictionary_["TESTPULSE_LOW_GAIN_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_MEAN_ERROR;
0038     dictionary_["TESTPULSE_MIDDLE_GAIN_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::TESTPULSE_MIDDLE_GAIN_MEAN_ERROR;
0039     dictionary_["TESTPULSE_HIGH_GAIN_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_MEAN_ERROR;
0040     dictionary_["TESTPULSE_LOW_GAIN_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_RMS_ERROR;
0041     dictionary_["TESTPULSE_MIDDLE_GAIN_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::TESTPULSE_MIDDLE_GAIN_RMS_ERROR;
0042     dictionary_["TESTPULSE_HIGH_GAIN_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_RMS_ERROR;
0043 
0044     dictionary_["LASER_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::LASER_MEAN_ERROR;
0045     dictionary_["LASER_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::LASER_RMS_ERROR;
0046     dictionary_["LASER_TIMING_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::LASER_TIMING_MEAN_ERROR;
0047     dictionary_["LASER_TIMING_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::LASER_TIMING_RMS_ERROR;
0048 
0049     dictionary_["LED_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::LED_MEAN_ERROR;
0050     dictionary_["LED_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::LED_RMS_ERROR;
0051     dictionary_["LED_TIMING_MEAN_ERROR"] = 0x1 << EcalDQMStatusHelper::LED_TIMING_MEAN_ERROR;
0052     dictionary_["LED_TIMING_RMS_ERROR"] = 0x1 << EcalDQMStatusHelper::LED_TIMING_RMS_ERROR;
0053 
0054     dictionary_["STATUS_FLAG_ERROR"] = 0x1 << EcalDQMStatusHelper::STATUS_FLAG_ERROR;
0055 
0056     dictionary_["PHYSICS_BAD_CHANNEL_WARNING"] = 0x1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_WARNING;
0057     dictionary_["PHYSICS_BAD_CHANNEL_ERROR"] = 0x1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_ERROR;
0058 
0059     dictionary_["disabled_channel"] =
0060         0x1 << EcalDQMStatusHelper::TT_SIZE_ERROR | 0x1 << EcalDQMStatusHelper::PEDESTAL_LOW_GAIN_MEAN_ERROR |
0061         0x1 << EcalDQMStatusHelper::PEDESTAL_MIDDLE_GAIN_MEAN_ERROR |
0062         0x1 << EcalDQMStatusHelper::PEDESTAL_HIGH_GAIN_MEAN_ERROR |
0063         0x1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR |
0064         0x1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_MEAN_ERROR |
0065         0x1 << EcalDQMStatusHelper::TESTPULSE_MIDDLE_GAIN_MEAN_ERROR |
0066         0x1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_MEAN_ERROR | 0x1 << EcalDQMStatusHelper::LASER_MEAN_ERROR |
0067         0x1 << EcalDQMStatusHelper::LED_MEAN_ERROR | 0x1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_WARNING |
0068         0x1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_ERROR;
0069 
0070     dictionary_["dead_channel"] =
0071         0x1 << EcalDQMStatusHelper::PEDESTAL_LOW_GAIN_MEAN_ERROR |
0072         0x1 << EcalDQMStatusHelper::PEDESTAL_LOW_GAIN_RMS_ERROR |
0073         0x1 << EcalDQMStatusHelper::PEDESTAL_MIDDLE_GAIN_MEAN_ERROR |
0074         0x1 << EcalDQMStatusHelper::PEDESTAL_MIDDLE_GAIN_RMS_ERROR |
0075         0x1 << EcalDQMStatusHelper::PEDESTAL_HIGH_GAIN_MEAN_ERROR |
0076         0x1 << EcalDQMStatusHelper::PEDESTAL_HIGH_GAIN_RMS_ERROR |
0077         0x1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR |
0078         0x1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR |
0079         0x1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_MEAN_ERROR |
0080         0x1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_RMS_ERROR |
0081         0x1 << EcalDQMStatusHelper::TESTPULSE_MIDDLE_GAIN_MEAN_ERROR |
0082         0x1 << EcalDQMStatusHelper::TESTPULSE_MIDDLE_GAIN_RMS_ERROR |
0083         0x1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_MEAN_ERROR |
0084         0x1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_RMS_ERROR | 0x1 << EcalDQMStatusHelper::LASER_MEAN_ERROR |
0085         0x1 << EcalDQMStatusHelper::LASER_RMS_ERROR | 0x1 << EcalDQMStatusHelper::LASER_TIMING_MEAN_ERROR |
0086         0x1 << EcalDQMStatusHelper::LASER_TIMING_RMS_ERROR | 0x1 << EcalDQMStatusHelper::LED_MEAN_ERROR |
0087         0x1 << EcalDQMStatusHelper::LED_RMS_ERROR | 0x1 << EcalDQMStatusHelper::LED_TIMING_MEAN_ERROR |
0088         0x1 << EcalDQMStatusHelper::LED_TIMING_RMS_ERROR | 0x1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_WARNING |
0089         0x1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_ERROR;
0090 
0091     dictionary_["pedestal_problem"] = 0x1 << EcalDQMStatusHelper::PEDESTAL_LOW_GAIN_MEAN_ERROR |
0092                                       0x1 << EcalDQMStatusHelper::PEDESTAL_LOW_GAIN_RMS_ERROR |
0093                                       0x1 << EcalDQMStatusHelper::PEDESTAL_MIDDLE_GAIN_MEAN_ERROR |
0094                                       0x1 << EcalDQMStatusHelper::PEDESTAL_MIDDLE_GAIN_RMS_ERROR |
0095                                       0x1 << EcalDQMStatusHelper::PEDESTAL_HIGH_GAIN_MEAN_ERROR |
0096                                       0x1 << EcalDQMStatusHelper::PEDESTAL_HIGH_GAIN_RMS_ERROR |
0097                                       0x1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR |
0098                                       0x1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR;
0099 
0100     dictionary_["testpulse_problem"] = 0x1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_MEAN_ERROR |
0101                                        0x1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_RMS_ERROR |
0102                                        0x1 << EcalDQMStatusHelper::TESTPULSE_MIDDLE_GAIN_MEAN_ERROR |
0103                                        0x1 << EcalDQMStatusHelper::TESTPULSE_MIDDLE_GAIN_RMS_ERROR |
0104                                        0x1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_MEAN_ERROR |
0105                                        0x1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_RMS_ERROR;
0106 
0107     dictionary_["laser_problem"] =
0108         0x1 << EcalDQMStatusHelper::LASER_MEAN_ERROR | 0x1 << EcalDQMStatusHelper::LASER_RMS_ERROR |
0109         0x1 << EcalDQMStatusHelper::LASER_TIMING_MEAN_ERROR | 0x1 << EcalDQMStatusHelper::LASER_TIMING_RMS_ERROR;
0110 
0111     dictionary_["led_problem"] =
0112         0x1 << EcalDQMStatusHelper::LED_MEAN_ERROR | 0x1 << EcalDQMStatusHelper::LED_RMS_ERROR |
0113         0x1 << EcalDQMStatusHelper::LED_TIMING_MEAN_ERROR | 0x1 << EcalDQMStatusHelper::LED_TIMING_RMS_ERROR;
0114 
0115     dictionary_["noise_problem"] = 0x1 << EcalDQMStatusHelper::PEDESTAL_LOW_GAIN_RMS_ERROR |
0116                                    0x1 << EcalDQMStatusHelper::PEDESTAL_MIDDLE_GAIN_RMS_ERROR |
0117                                    0x1 << EcalDQMStatusHelper::PEDESTAL_HIGH_GAIN_RMS_ERROR |
0118                                    0x1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR |
0119                                    0x1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_ERROR;
0120   }
0121 
0122   void StatusManager::readFromStream(std::istream &_input, const EcalElectronicsMapping *electronicsMap) {
0123     TPRegexp linePat(
0124         "^[ ]*(Crystal|TT|PN)[ ]+(EB[0-9+-]*|EE[0-9+-]*|[0-9]+)[ "
0125         "]+([0-9]+)[ ]([a-zA-Z_]+)");
0126 
0127     std::string line;
0128     while (true) {
0129       std::getline(_input, line);
0130       if (!_input.good())
0131         break;
0132 
0133       if (!linePat.MatchB(line))
0134         continue;
0135 
0136       TObjArray *matches(linePat.MatchS(line));
0137       TString channelType(matches->At(1)->GetName());
0138       TString module(matches->At(2)->GetName());
0139       unsigned channel(TString(matches->At(3)->GetName()).Atoi());
0140       TString statusName(matches->At(4)->GetName());
0141       delete matches;
0142 
0143       std::map<std::string, uint32_t>::const_iterator dItr(dictionary_.find(statusName.Data()));
0144       if (dItr == dictionary_.end())
0145         continue;
0146       uint32_t statusVal(dItr->second);
0147 
0148       if (channelType == "Crystal") {
0149         // module: Subdetector name, channel: dense ID
0150         // Store using EBDetId and EEDetId as keys (following
0151         // EcalDQMChannelStatus)
0152 
0153         if (module == "EB") {
0154           if (!EBDetId::validDenseIndex(channel))
0155             continue;
0156           status_.insert(std::pair<uint32_t, uint32_t>(EBDetId::unhashIndex(channel).rawId(), statusVal));
0157         } else if (module == "EE") {
0158           if (!EEDetId::validDenseIndex(channel))
0159             continue;
0160           status_.insert(std::pair<uint32_t, uint32_t>(EEDetId::unhashIndex(channel).rawId(), statusVal));
0161         }
0162       } else if (channelType == "TT") {
0163         // module: Supermodule name, channel: RU ID (electronics ID tower)
0164         // Store using EcalTrigTowerDetId and EcalScDetId as keys (following
0165         // EcalDQMTowerStatus)
0166 
0167         if (module.Contains("EB")) {
0168           /* TODO CHECK THIS */
0169 
0170           int iEta((channel - 1) / 4 + 1);
0171           int zside(0);
0172           int iPhi(0);
0173           std::string smName = module.Data();
0174           unsigned smNumber(std::atoi(smName.substr(3).c_str()));
0175 
0176           if (module(2) == '-') {
0177             zside = -1;
0178             iPhi = 4 * (smNumber - 1) + (channel - 1) % 4 - 1;
0179           } else {
0180             zside = 1;
0181             iPhi = 4 * (smNumber - 1) + (68 - channel) % 4 - 1;
0182           }
0183 
0184           status_.insert(
0185               std::pair<uint32_t, uint32_t>(EcalTrigTowerDetId(zside, EcalBarrel, iEta, iPhi).rawId(), statusVal));
0186         } else if (module.Contains("EE")) {
0187           std::vector<EcalScDetId> scIds(electronicsMap->getEcalScDetId(dccId(module.Data()), channel, false));
0188           for (unsigned iS(0); iS != scIds.size(); ++iS)
0189             status_.insert(std::pair<uint32_t, uint32_t>(scIds[iS].rawId(), statusVal));
0190         }
0191       } else if (channelType == "PN") {
0192         // module: DCC ID, channel: iPN
0193         // Store using EcalPnDiodeDetId as keys
0194         unsigned iDCC(module.Atoi() - 1);
0195         int subdet(iDCC <= kEEmHigh || iDCC >= kEEpLow ? EcalEndcap : EcalBarrel);
0196         status_.insert(std::pair<uint32_t, uint32_t>(EcalPnDiodeDetId(subdet, iDCC + 1, channel).rawId(), statusVal));
0197       }
0198     }
0199   }
0200 
0201   void StatusManager::readFromObj(EcalDQMChannelStatus const &_channelStatus, EcalDQMTowerStatus const &_towerStatus) {
0202     EcalDQMChannelStatus::Items const &barrelChStatus(_channelStatus.barrelItems());
0203     for (unsigned iC(0); iC != EBDetId::kSizeForDenseIndexing; ++iC)
0204       status_.insert(
0205           std::pair<uint32_t, uint32_t>(EBDetId::unhashIndex(iC).rawId(), barrelChStatus[iC].getStatusCode()));
0206 
0207     EcalDQMChannelStatus::Items const &endcapChStatus(_channelStatus.endcapItems());
0208     for (unsigned iC(0); iC != EEDetId::kSizeForDenseIndexing; ++iC)
0209       status_.insert(
0210           std::pair<uint32_t, uint32_t>(EEDetId::unhashIndex(iC).rawId(), endcapChStatus[iC].getStatusCode()));
0211 
0212     EcalDQMTowerStatus::Items const &barrelTowStatus(_towerStatus.barrelItems());
0213     for (unsigned iC(0); iC != EcalTrigTowerDetId::kEBTotalTowers; ++iC)
0214       status_.insert(std::pair<uint32_t, uint32_t>(EcalTrigTowerDetId::detIdFromDenseIndex(iC).rawId(),
0215                                                    barrelTowStatus[iC].getStatusCode()));
0216 
0217     EcalDQMTowerStatus::Items const &endcapTowStatus(_towerStatus.endcapItems());
0218     for (unsigned iC(0); iC != EcalScDetId::kSizeForDenseIndexing; ++iC)
0219       status_.insert(
0220           std::pair<uint32_t, uint32_t>(EcalScDetId::unhashIndex(iC).rawId(), endcapTowStatus[iC].getStatusCode()));
0221   }
0222 
0223   void StatusManager::writeToStream(std::ostream &_output) const {}
0224 
0225   void StatusManager::writeToObj(EcalDQMChannelStatus &_channelStatus, EcalDQMTowerStatus &_towerStatus) const {
0226     for (unsigned iC(0); iC != EBDetId::kSizeForDenseIndexing; ++iC) {
0227       uint32_t key(EBDetId::unhashIndex(iC).rawId());
0228       _channelStatus.setValue(key, EcalDQMStatusCode(getStatus(key)));
0229     }
0230 
0231     for (unsigned iC(0); iC != EEDetId::kSizeForDenseIndexing; ++iC) {
0232       uint32_t key(EEDetId::unhashIndex(iC).rawId());
0233       _channelStatus.setValue(key, EcalDQMStatusCode(getStatus(key)));
0234     }
0235 
0236     for (unsigned iC(0); iC != EcalTrigTowerDetId::kEBTotalTowers; ++iC) {
0237       uint32_t key(EcalTrigTowerDetId::detIdFromDenseIndex(iC));
0238       _towerStatus.setValue(key, EcalDQMStatusCode(getStatus(key)));
0239     }
0240 
0241     for (unsigned iC(0); iC != EcalScDetId::kSizeForDenseIndexing; ++iC) {
0242       uint32_t key(EcalScDetId::unhashIndex(iC));
0243       _towerStatus.setValue(key, EcalDQMStatusCode(getStatus(key)));
0244     }
0245   }
0246 
0247   uint32_t StatusManager::getStatus(uint32_t _key) const {
0248     std::map<uint32_t, uint32_t>::const_iterator itr(status_.find(_key));
0249     if (itr == status_.end())
0250       return 0;
0251     return itr->second;
0252   }
0253 
0254 }  // namespace ecaldqm