Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-24 22:51:50

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