Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-28 04:00:52

0001 #include "DQM/GEM/interface/GEMDAQStatusSource.h"
0002 
0003 using namespace std;
0004 using namespace edm;
0005 
0006 GEMDAQStatusSource::GEMDAQStatusSource(const edm::ParameterSet &cfg)
0007     : GEMDQMBase(cfg), gemChMapToken_(esConsumes<GEMChMap, GEMChMapRcd, edm::Transition::BeginRun>()) {
0008   tagVFAT_ = consumes<GEMVFATStatusCollection>(cfg.getParameter<edm::InputTag>("VFATInputLabel"));
0009   tagOH_ = consumes<GEMOHStatusCollection>(cfg.getParameter<edm::InputTag>("OHInputLabel"));
0010   tagAMC_ = consumes<GEMAMCStatusCollection>(cfg.getParameter<edm::InputTag>("AMCInputLabel"));
0011   tagAMC13_ = consumes<GEMAMC13StatusCollection>(cfg.getParameter<edm::InputTag>("AMC13InputLabel"));
0012 
0013   nAMCSlots_ = cfg.getParameter<Int_t>("AMCSlots");
0014 
0015   bWarnedNotFound_ = false;
0016 }
0017 
0018 void GEMDAQStatusSource::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0019   edm::ParameterSetDescription desc;
0020   desc.add<edm::InputTag>("VFATInputLabel", edm::InputTag("muonGEMDigis", "VFATStatus"));
0021   desc.add<edm::InputTag>("OHInputLabel", edm::InputTag("muonGEMDigis", "OHStatus"));
0022   desc.add<edm::InputTag>("AMCInputLabel", edm::InputTag("muonGEMDigis", "AMCStatus"));
0023   desc.add<edm::InputTag>("AMC13InputLabel", edm::InputTag("muonGEMDigis", "AMC13Status"));
0024 
0025   desc.add<Int_t>("AMCSlots", 13);
0026   desc.addUntracked<std::string>("runType", "relval");
0027   desc.addUntracked<std::string>("logCategory", "GEMDAQStatusSource");
0028 
0029   descriptions.add("GEMDAQStatusSource", desc);
0030 }
0031 
0032 void GEMDAQStatusSource::LoadROMap(edm::EventSetup const &iSetup) {
0033   //if (useDBEMap_)
0034   if (true) {
0035     const auto &chMap = iSetup.getData(gemChMapToken_);
0036     auto gemChMap = std::make_unique<GEMChMap>(chMap);
0037 
0038     std::vector<unsigned int> listFEDId;
0039     for (auto const &[ec, dc] : gemChMap->chamberMap()) {
0040       unsigned int fedId = ec.fedId;
0041       uint8_t amcNum = ec.amcNum;
0042       GEMDetId gemChId(dc.detId);
0043 
0044       if (mapFEDIdToRe_.find(fedId) == mapFEDIdToRe_.end()) {
0045         listFEDId.push_back(fedId);
0046       }
0047       mapFEDIdToRe_[fedId] = gemChId.region();
0048       mapFEDIdToSt_[fedId] = gemChId.station();
0049       mapAMC13ToListChamber_[fedId].push_back(gemChId);
0050       mapAMCToListChamber_[{fedId, amcNum}].push_back(gemChId);
0051     }
0052 
0053     Int_t nIdx = 1;
0054     for (auto fedId : listFEDId) {
0055       mapFEDIdToPosition_[fedId] = nIdx++;
0056     }
0057 
0058   } else {
0059     // no EMap in DB, using dummy
0060     auto gemChMap = std::make_unique<GEMChMap>();
0061     gemChMap->setDummy();
0062 
0063     for (auto const &[ec, dc] : gemChMap->chamberMap()) {
0064       unsigned int fedId = ec.fedId;
0065       uint8_t amcNum = ec.amcNum;
0066       GEMDetId gemChId(dc.detId);
0067 
0068       mapFEDIdToRe_[fedId] = gemChId.region();
0069       mapAMC13ToListChamber_[fedId].push_back(gemChId);
0070       mapAMCToListChamber_[{fedId, amcNum}].push_back(gemChId);
0071     }
0072   }
0073 }
0074 
0075 void GEMDAQStatusSource::SetLabelAMC13Status(MonitorElement *h2Status) {
0076   if (h2Status == nullptr) {
0077     return;
0078   }
0079 
0080   unsigned int unBinPos = 1;
0081   h2Status->setBinLabel(unBinPos++, "Good", 2);
0082   h2Status->setBinLabel(unBinPos++, "Invalid AMC", 2);
0083   h2Status->setBinLabel(unBinPos++, "Invalid size", 2);
0084   h2Status->setBinLabel(unBinPos++, "Fail trailer check", 2);
0085   h2Status->setBinLabel(unBinPos++, "Fail fragment length", 2);
0086   h2Status->setBinLabel(unBinPos++, "Fail trailer match", 2);
0087   h2Status->setBinLabel(unBinPos++, "More trailer", 2);
0088   h2Status->setBinLabel(unBinPos++, "CRC modified", 2);
0089   h2Status->setBinLabel(unBinPos++, "S-link error", 2);
0090   h2Status->setBinLabel(unBinPos++, "Wrong FED ID", 2);
0091 
0092   for (auto const &[fedId, nPos] : mapFEDIdToPosition_) {
0093     auto st = mapFEDIdToSt_[fedId];
0094     auto re = (mapFEDIdToRe_[fedId] > 0 ? 'P' : 'M');
0095     h2Status->setBinLabel(nPos, Form("GE%i1-%c", st, re), 1);
0096   }
0097 }
0098 
0099 void GEMDAQStatusSource::SetLabelAMCStatus(MonitorElement *h2Status) {
0100   if (h2Status == nullptr) {
0101     return;
0102   }
0103 
0104   unsigned int unBinPos = 1;
0105   h2Status->setBinLabel(unBinPos++, "Good", 2);
0106   h2Status->setBinLabel(unBinPos++, "Invalid OH", 2);
0107   h2Status->setBinLabel(unBinPos++, "Back pressure", 2);
0108   h2Status->setBinLabel(unBinPos++, "Bad EC", 2);
0109   h2Status->setBinLabel(unBinPos++, "Bad BC", 2);
0110   h2Status->setBinLabel(unBinPos++, "Bad OC", 2);
0111   h2Status->setBinLabel(unBinPos++, "Bad run type", 2);
0112   h2Status->setBinLabel(unBinPos++, "Bad CRC", 2);
0113   h2Status->setBinLabel(unBinPos++, "MMCM locked", 2);
0114   h2Status->setBinLabel(unBinPos++, "DAQ clock locked", 2);
0115   h2Status->setBinLabel(unBinPos++, "DAQ not ready", 2);
0116   h2Status->setBinLabel(unBinPos++, "BC0 not locked", 2);
0117 }
0118 
0119 void GEMDAQStatusSource::SetLabelOHStatus(MonitorElement *h2Status) {
0120   if (h2Status == nullptr) {
0121     return;
0122   }
0123 
0124   unsigned int unBinPos = 1;
0125   h2Status->setBinLabel(unBinPos++, "Good", 2);
0126   h2Status->setBinLabel(unBinPos++, "Event FIFO near full", 2);
0127   h2Status->setBinLabel(unBinPos++, "Input FIFO near full", 2);
0128   h2Status->setBinLabel(unBinPos++, "L1A FIFO near full", 2);
0129   h2Status->setBinLabel(unBinPos++, "Event size warn", 2);
0130   h2Status->setBinLabel(unBinPos++, "Invalid VFAT", 2);
0131   h2Status->setBinLabel(unBinPos++, "Event FIFO full", 2);
0132   h2Status->setBinLabel(unBinPos++, "Input FIFO full", 2);
0133   h2Status->setBinLabel(unBinPos++, "L1A FIFO full", 2);
0134   h2Status->setBinLabel(unBinPos++, "Event size overflow", 2);
0135   h2Status->setBinLabel(unBinPos++, "Invalid event", 2);
0136   h2Status->setBinLabel(unBinPos++, "Out of Sync AMC vs VFAT", 2);
0137   h2Status->setBinLabel(unBinPos++, "Out of Sync VFAT vs VFAT", 2);
0138   h2Status->setBinLabel(unBinPos++, "BX mismatch AMC vs VFAT", 2);
0139   h2Status->setBinLabel(unBinPos++, "BX mismatch VFAT vs VFAT", 2);
0140   h2Status->setBinLabel(unBinPos++, "Input FIFO underflow", 2);
0141   h2Status->setBinLabel(unBinPos++, "Bad VFAT count", 2);
0142 }
0143 
0144 void GEMDAQStatusSource::SetLabelVFATStatus(MonitorElement *h2Status) {
0145   if (h2Status == nullptr) {
0146     return;
0147   }
0148 
0149   unsigned int unBinPos = 1;
0150   h2Status->setBinLabel(unBinPos++, "Good", 2);
0151   h2Status->setBinLabel(unBinPos++, "Basic overflow", 2);
0152   h2Status->setBinLabel(unBinPos++, "Zero-sup overflow", 2);
0153   h2Status->setBinLabel(unBinPos++, "VFAT CRC error", 2);
0154   h2Status->setBinLabel(unBinPos++, "Invalid header", 2);
0155   h2Status->setBinLabel(unBinPos++, "AMC EC mismatch", 2);
0156   h2Status->setBinLabel(unBinPos++, "AMC BC mismatch", 2);
0157 }
0158 
0159 void GEMDAQStatusSource::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &iSetup) {
0160   LoadROMap(iSetup);
0161   if (mapAMC13ToListChamber_.empty() || mapAMCToListChamber_.empty())
0162     return;
0163   initGeometry(iSetup);
0164   if (GEMGeometry_ == nullptr)
0165     return;
0166   loadChambers();
0167 
0168   strFolderMain_ = "GEM/DAQStatus";
0169 
0170   nBXMin_ = -10;
0171   nBXMax_ = 10;
0172 
0173   ibooker.cd();
0174   ibooker.setCurrentFolder(strFolderMain_);
0175 
0176   h2AMC13Status_ = nullptr;
0177 
0178   bFillAMC_ = false;
0179 
0180   //if (nRunType_ != GEMDQM_RUNTYPE_RELVAL)
0181   if (nRunType_ == GEMDQM_RUNTYPE_ALLPLOTS || nRunType_ == GEMDQM_RUNTYPE_ONLINE) {
0182     Int_t nNumAMC13 = (Int_t)mapFEDIdToRe_.size();
0183     h2AMC13Status_ = ibooker.book2D(
0184         "amc13_status", "AMC13 Status;AMC13;", nNumAMC13, 0.5, nNumAMC13 + 0.5, nBitAMC13_, 0.5, nBitAMC13_ + 0.5);
0185     SetLabelAMC13Status(h2AMC13Status_);
0186 
0187     for (auto &[fedId, nIdx] : mapFEDIdToPosition_) {
0188       auto st = mapFEDIdToSt_[fedId];
0189       auto re = (mapFEDIdToRe_[fedId] > 0 ? 'P' : 'M');
0190       auto strName = Form("amc_status_GE%i1-%c", st, re);
0191       auto strTitle = Form("AMC Status GE%i1-%c;AMC slot;", st, re);
0192       mapFEDIdToAMCStatus_[fedId] =
0193           ibooker.book2D(strName, strTitle, nAMCSlots_, -0.5, nAMCSlots_ - 0.5, nBitAMC_, 0.5, nBitAMC_ + 0.5);
0194       SetLabelAMCStatus(mapFEDIdToAMCStatus_[fedId]);
0195     }
0196 
0197     bFillAMC_ = true;
0198   }
0199 
0200   mapStatusOH_ =
0201       MEMap3Inf(this, "oh_status", "OptoHybrid Status", 36, 0.5, 36.5, nBitOH_, 0.5, nBitOH_ + 0.5, "Chamber");
0202 
0203   mapStatusWarnVFATPerLayer_ = MEMap3Inf(
0204       this, "vfat_statusWarnSum", "VFAT reporting warnings", 36, 0.5, 36.5, 24, -0.5, 24 - 0.5, "Chamber", "VFAT");
0205   mapStatusErrVFATPerLayer_ = MEMap3Inf(
0206       this, "vfat_statusErrSum", "VFAT reporting errors", 36, 0.5, 36.5, 24, -0.5, 24 - 0.5, "Chamber", "VFAT");
0207   mapStatusVFATPerCh_ =
0208       MEMap4Inf(this, "vfat_status", "VFAT Status", 24, -0.5, 24 - 0.5, nBitVFAT_, 0.5, nBitVFAT_ + 0.5, "VFAT");
0209 
0210   if (nRunType_ == GEMDQM_RUNTYPE_OFFLINE || nRunType_ == GEMDQM_RUNTYPE_RELVAL) {
0211     mapStatusOH_.TurnOff();
0212     mapStatusWarnVFATPerLayer_.TurnOff();
0213     mapStatusErrVFATPerLayer_.TurnOff();
0214     mapStatusVFATPerCh_.TurnOff();
0215   }
0216 
0217   GenerateMEPerChamber(ibooker);
0218 
0219   if (nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0220     h2SummaryStatusAll = CreateSummaryHist(ibooker, "chamberAllStatus");
0221     h2SummaryStatusWarning = CreateSummaryHist(ibooker, "chamberWarnings");
0222     h2SummaryStatusError = CreateSummaryHist(ibooker, "chamberErrors");
0223   }
0224 
0225   if (nRunType_ == GEMDQM_RUNTYPE_ALLPLOTS || nRunType_ == GEMDQM_RUNTYPE_ONLINE) {
0226     h2SummaryStatusVFATWarning = CreateSummaryHist(ibooker, "chamberVFATWarnings");
0227     h2SummaryStatusVFATError = CreateSummaryHist(ibooker, "chamberVFATErrors");
0228     h2SummaryStatusOHWarning = CreateSummaryHist(ibooker, "chamberOHWarnings");
0229     h2SummaryStatusOHError = CreateSummaryHist(ibooker, "chamberOHErrors");
0230     h2SummaryStatusAMCWarning = CreateSummaryHist(ibooker, "chamberAMCWarnings");
0231     h2SummaryStatusAMCError = CreateSummaryHist(ibooker, "chamberAMCErrors");
0232     h2SummaryStatusAMC13Error = CreateSummaryHist(ibooker, "chamberAMC13Errors");
0233 
0234     h2SummaryStatusAll->setTitle("Summary of all number of OH or VFAT status of each chambers");
0235     h2SummaryStatusWarning->setTitle("Summary of all warnings of each chambers");
0236     h2SummaryStatusError->setTitle("Summary of all errors of each chambers");
0237     h2SummaryStatusVFATWarning->setTitle("Summary of VFAT warnings of each chambers");
0238     h2SummaryStatusVFATError->setTitle("Summary of VFAT errors of each chambers");
0239     h2SummaryStatusOHWarning->setTitle("Summary of OH warnings of each chambers");
0240     h2SummaryStatusOHError->setTitle("Summary of OH errors of each chambers");
0241     h2SummaryStatusAMCWarning->setTitle("Summary of AMC warnings of each chambers");
0242     h2SummaryStatusAMCError->setTitle("Summary of AMC errors of each chambers");
0243     h2SummaryStatusAMC13Error->setTitle("Summary of AMC13 errors of each chambers");
0244   }
0245 }
0246 
0247 int GEMDAQStatusSource::ProcessWithMEMap3(BookingHelper &bh, ME3IdsKey key) {
0248   MEStationInfo &stationInfo = mapStationInfo_[key];
0249 
0250   Int_t nNewNumCh = stationInfo.nMaxIdxChamber_ - stationInfo.nMinIdxChamber_ + 1;
0251   Int_t nNewMinIdxChamber = stationInfo.nNumModules_ * (stationInfo.nMinIdxChamber_ - 1) + 1;
0252   Int_t nNewMaxIdxChamber = stationInfo.nNumModules_ * stationInfo.nMaxIdxChamber_;
0253 
0254   nNewNumCh *= stationInfo.nNumModules_;
0255 
0256   mapStatusOH_.SetBinConfX(nNewNumCh, nNewMinIdxChamber - 0.5, nNewMaxIdxChamber + 0.5);
0257   mapStatusOH_.bookND(bh, key);
0258   mapStatusOH_.SetLabelForChambers(key, 1, -1, nNewMinIdxChamber, stationInfo.nNumModules_);
0259 
0260   if (mapStatusOH_.isOperating()) {
0261     SetLabelOHStatus(mapStatusOH_.FindHist(key));
0262   }
0263 
0264   Int_t nNumVFATPerModule = stationInfo.nMaxVFAT_ / stationInfo.nNumModules_;
0265 
0266   mapStatusWarnVFATPerLayer_.SetBinConfX(nNewNumCh, nNewMinIdxChamber - 0.5, nNewMaxIdxChamber + 0.5);
0267   mapStatusWarnVFATPerLayer_.SetBinConfY(nNumVFATPerModule, -0.5);
0268   mapStatusWarnVFATPerLayer_.bookND(bh, key);
0269   mapStatusWarnVFATPerLayer_.SetLabelForChambers(key, 1, -1, nNewMinIdxChamber, stationInfo.nNumModules_);
0270   mapStatusWarnVFATPerLayer_.SetLabelForVFATs(key, stationInfo.nNumEtaPartitions_, 2);
0271 
0272   mapStatusErrVFATPerLayer_.SetBinConfX(nNewNumCh, nNewMinIdxChamber - 0.5, nNewMaxIdxChamber + 0.5);
0273   mapStatusErrVFATPerLayer_.SetBinConfY(nNumVFATPerModule, -0.5);
0274   mapStatusErrVFATPerLayer_.bookND(bh, key);
0275   mapStatusErrVFATPerLayer_.SetLabelForChambers(key, 1, -1, nNewMinIdxChamber, stationInfo.nNumModules_);
0276   mapStatusErrVFATPerLayer_.SetLabelForVFATs(key, stationInfo.nNumEtaPartitions_, 2);
0277 
0278   return 0;
0279 }
0280 
0281 int GEMDAQStatusSource::ProcessWithMEMap3WithChamber(BookingHelper &bh, ME4IdsKey key) {
0282   ME3IdsKey key3 = key4Tokey3(key);
0283   MEStationInfo &stationInfo = mapStationInfo_[key3];
0284 
0285   bh.getBooker()->setCurrentFolder(strFolderMain_ + "/VFATStatus_" + getNameDirLayer(key3));
0286 
0287   mapStatusVFATPerCh_.SetBinConfX(stationInfo.nMaxVFAT_, -0.5);
0288   mapStatusVFATPerCh_.bookND(bh, key);
0289   mapStatusVFATPerCh_.SetLabelForVFATs(key, stationInfo.nNumEtaPartitions_, 1);
0290   if (mapStatusVFATPerCh_.isOperating()) {
0291     SetLabelVFATStatus(mapStatusVFATPerCh_.FindHist(key));
0292   }
0293 
0294   bh.getBooker()->setCurrentFolder(strFolderMain_);
0295 
0296   return 0;
0297 }
0298 
0299 void GEMDAQStatusSource::analyze(edm::Event const &event, edm::EventSetup const &eventSetup) {
0300   edm::Handle<GEMVFATStatusCollection> gemVFAT;
0301   edm::Handle<GEMOHStatusCollection> gemOH;
0302   edm::Handle<GEMAMCStatusCollection> gemAMC;
0303   edm::Handle<GEMAMC13StatusCollection> gemAMC13;
0304 
0305   event.getByToken(tagVFAT_, gemVFAT);
0306   event.getByToken(tagOH_, gemOH);
0307   event.getByToken(tagAMC_, gemAMC);
0308   event.getByToken(tagAMC13_, gemAMC13);
0309 
0310   if (!(gemVFAT.isValid() && gemOH.isValid() && gemAMC.isValid() && gemAMC13.isValid())) {
0311     if (!bWarnedNotFound_) {
0312       edm::LogWarning(log_category_) << "DAQ sources from muonGEMDigis are not found";
0313       bWarnedNotFound_ = true;
0314     }
0315     return;
0316   }
0317 
0318   std::map<ME4IdsKey, bool> mapChamberAll;
0319   std::map<ME4IdsKey, bool> mapChamberWarning;
0320   std::map<ME4IdsKey, bool> mapChamberError;
0321   std::map<ME4IdsKey, bool> mapChamberVFATWarning;
0322   std::map<ME4IdsKey, bool> mapChamberVFATError;
0323   std::map<ME4IdsKey, bool> mapChamberOHWarning;
0324   std::map<ME4IdsKey, bool> mapChamberOHError;
0325   std::map<ME4IdsKey, bool> mapChamberAMCWarning;
0326   std::map<ME4IdsKey, bool> mapChamberAMCError;
0327   std::map<ME4IdsKey, bool> mapChamberAMC13Error;
0328 
0329   for (auto amc13It = gemAMC13->begin(); amc13It != gemAMC13->end(); ++amc13It) {
0330     int fedId = (*amc13It).first;
0331     if (mapFEDIdToPosition_.find(fedId) == mapFEDIdToPosition_.end()) {
0332       continue;
0333     }
0334     int nXBin = mapFEDIdToPosition_[fedId];
0335 
0336     const auto &range = (*amc13It).second;
0337     for (auto amc13 = range.first; amc13 != range.second; ++amc13) {
0338       Bool_t bWarn = false;
0339       Bool_t bErr = false;
0340 
0341       GEMAMC13Status::Warnings warnings{amc13->warnings()};
0342       GEMAMC13Status::Errors errors{amc13->errors()};
0343 
0344       if (bFillAMC_) {
0345         if (nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0346           if (warnings.InValidAMC)
0347             FillWithRiseErr(h2AMC13Status_, nXBin, 2, bWarn);
0348         }
0349 
0350         if (nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0351           if (errors.InValidSize)
0352             FillWithRiseErr(h2AMC13Status_, nXBin, 3, bErr);
0353           if (errors.failTrailerCheck)
0354             FillWithRiseErr(h2AMC13Status_, nXBin, 4, bErr);
0355           if (errors.failFragmentLength)
0356             FillWithRiseErr(h2AMC13Status_, nXBin, 5, bErr);
0357           if (errors.failTrailerMatch)
0358             FillWithRiseErr(h2AMC13Status_, nXBin, 6, bErr);
0359           if (errors.moreTrailers)
0360             FillWithRiseErr(h2AMC13Status_, nXBin, 7, bErr);
0361           if (errors.crcModified)
0362             FillWithRiseErr(h2AMC13Status_, nXBin, 8, bErr);
0363           if (errors.slinkError)
0364             FillWithRiseErr(h2AMC13Status_, nXBin, 9, bErr);
0365           if (errors.wrongFedId)
0366             FillWithRiseErr(h2AMC13Status_, nXBin, 10, bErr);
0367         }
0368       }
0369 
0370       if (!bWarn && !bErr) {
0371         if (bFillAMC_ && nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0372           h2AMC13Status_->Fill(nXBin, 1);
0373         }
0374       } else {
0375         auto &listChamber = mapAMC13ToListChamber_[fedId];
0376         for (auto gid : listChamber) {
0377           ME4IdsKey key4Ch{gid.region(), gid.station(), gid.layer(), gid.chamber()};
0378           if (bErr)
0379             mapChamberAMC13Error[key4Ch] = false;
0380         }
0381       }
0382     }
0383   }
0384 
0385   MonitorElement *h2AMCStatus = nullptr;
0386 
0387   for (auto amcIt = gemAMC->begin(); amcIt != gemAMC->end(); ++amcIt) {
0388     int fedId = (*amcIt).first;
0389     if (mapFEDIdToAMCStatus_.find(fedId) == mapFEDIdToAMCStatus_.end()) {
0390       continue;
0391     }
0392     h2AMCStatus = mapFEDIdToAMCStatus_[fedId];
0393 
0394     const GEMAMCStatusCollection::Range &range = (*amcIt).second;
0395     for (auto amc = range.first; amc != range.second; ++amc) {
0396       Bool_t bWarn = false;
0397       Bool_t bErr = false;
0398 
0399       Int_t nAMCNum = amc->amcNumber();
0400 
0401       GEMAMCStatus::Warnings warnings{amc->warnings()};
0402       GEMAMCStatus::Errors errors{amc->errors()};
0403 
0404       if (bFillAMC_) {
0405         if (nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0406           if (warnings.InValidOH)
0407             FillWithRiseErr(h2AMCStatus, nAMCNum, 2, bWarn);
0408           if (warnings.backPressure)
0409             FillWithRiseErr(h2AMCStatus, nAMCNum, 3, bWarn);
0410         }
0411 
0412         if (nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0413           if (errors.badEC)
0414             FillWithRiseErr(h2AMCStatus, nAMCNum, 4, bErr);
0415           if (errors.badBC)
0416             FillWithRiseErr(h2AMCStatus, nAMCNum, 5, bErr);
0417           if (errors.badOC)
0418             FillWithRiseErr(h2AMCStatus, nAMCNum, 6, bErr);
0419           if (errors.badRunType)
0420             FillWithRiseErr(h2AMCStatus, nAMCNum, 7, bErr);
0421           if (errors.badCRC)
0422             FillWithRiseErr(h2AMCStatus, nAMCNum, 8, bErr);
0423           if (errors.MMCMlocked)
0424             FillWithRiseErr(h2AMCStatus, nAMCNum, 9, bErr);
0425           if (errors.DAQclocklocked)
0426             FillWithRiseErr(h2AMCStatus, nAMCNum, 10, bErr);
0427           if (errors.DAQnotReday)
0428             FillWithRiseErr(h2AMCStatus, nAMCNum, 11, bErr);
0429           if (errors.BC0locked)
0430             FillWithRiseErr(h2AMCStatus, nAMCNum, 12, bErr);
0431         }
0432       }
0433 
0434       if (!bWarn && !bErr) {
0435         if (bFillAMC_ && nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0436           h2AMCStatus->Fill(nAMCNum, 1);
0437         }
0438       } else {
0439         auto &listChamber = mapAMCToListChamber_[{fedId, nAMCNum}];
0440         for (auto gid : listChamber) {
0441           ME4IdsKey key4Ch{gid.region(), gid.station(), gid.layer(), gid.chamber()};
0442           if (bErr)
0443             mapChamberAMCError[key4Ch] = false;
0444           if (bWarn)
0445             mapChamberAMCWarning[key4Ch] = false;
0446         }
0447       }
0448     }
0449   }
0450 
0451   for (auto ohIt = gemOH->begin(); ohIt != gemOH->end(); ++ohIt) {
0452     GEMDetId gid = (*ohIt).first;
0453     ME3IdsKey key3{gid.region(), gid.station(), gid.layer()};
0454     ME4IdsKey key4{gid.region(), gid.station(), gid.layer(), gid.chamber()};  // WARNING: Chamber, not iEta
0455     MEStationInfo &stationInfo = mapStationInfo_[key3];
0456 
0457     const GEMOHStatusCollection::Range &range = (*ohIt).second;
0458     for (auto OHStatus = range.first; OHStatus != range.second; ++OHStatus) {
0459       Int_t nIdxModule = getIdxModule(gid.station(), OHStatus->chamberType());
0460       Int_t nCh = (gid.chamber() - 1) * stationInfo.nNumModules_ + nIdxModule;
0461       ME4IdsKey key4Mod{gid.region(), gid.station(), gid.layer(), nCh};  // WARNING: Chamber+Module, not iEta
0462 
0463       GEMOHStatus::Warnings warnings{OHStatus->warnings()};
0464       if (warnings.EvtNF)
0465         mapStatusOH_.Fill(key3, nCh, 2);
0466       if (warnings.InNF)
0467         mapStatusOH_.Fill(key3, nCh, 3);
0468       if (warnings.L1aNF)
0469         mapStatusOH_.Fill(key3, nCh, 4);
0470       if (warnings.EvtSzW)
0471         mapStatusOH_.Fill(key3, nCh, 5);
0472       if (warnings.InValidVFAT)
0473         mapStatusOH_.Fill(key3, nCh, 6);
0474 
0475       GEMOHStatus::Errors errors{OHStatus->errors()};
0476       if (errors.EvtF)
0477         mapStatusOH_.Fill(key3, nCh, 7);
0478       if (errors.InF)
0479         mapStatusOH_.Fill(key3, nCh, 8);
0480       if (errors.L1aF)
0481         mapStatusOH_.Fill(key3, nCh, 9);
0482       if (errors.EvtSzOFW)
0483         mapStatusOH_.Fill(key3, nCh, 10);
0484       if (errors.Inv)
0485         mapStatusOH_.Fill(key3, nCh, 11);
0486       if (errors.OOScAvV)
0487         mapStatusOH_.Fill(key3, nCh, 12);
0488       if (errors.OOScVvV)
0489         mapStatusOH_.Fill(key3, nCh, 13);
0490       if (errors.BxmAvV)
0491         mapStatusOH_.Fill(key3, nCh, 14);
0492       if (errors.BxmVvV)
0493         mapStatusOH_.Fill(key3, nCh, 15);
0494       if (errors.InUfw)
0495         mapStatusOH_.Fill(key3, nCh, 16);
0496       if (errors.badVFatCount)
0497         mapStatusOH_.Fill(key3, nCh, 17);
0498 
0499       Bool_t bWarn = warnings.wcodes != 0;
0500       Bool_t bErr = errors.codes != 0;
0501       if (!bWarn && !bErr)
0502         mapStatusOH_.Fill(key3, nCh, 1);
0503       if (bWarn)
0504         mapChamberOHWarning[key4Mod] = false;
0505       if (bErr)
0506         mapChamberOHError[key4Mod] = false;
0507       mapChamberAll[key4Mod] = true;
0508     }
0509   }
0510 
0511   for (auto vfatIt = gemVFAT->begin(); vfatIt != gemVFAT->end(); ++vfatIt) {
0512     GEMDetId gid = (*vfatIt).first;
0513     ME3IdsKey key3{gid.region(), gid.station(), gid.layer()};
0514     ME4IdsKey key4Ch{gid.region(), gid.station(), gid.layer(), gid.chamber()};  // WARNING: Chamber, not iEta
0515     MEStationInfo &stationInfo = mapStationInfo_[key3];
0516     Int_t nNumVFATPerModule = stationInfo.nMaxVFAT_ / stationInfo.nNumModules_;
0517 
0518     const GEMVFATStatusCollection::Range &range = (*vfatIt).second;
0519 
0520     for (auto vfatStat = range.first; vfatStat != range.second; ++vfatStat) {
0521       Int_t nIdxModule = getIdxModule(gid.station(), vfatStat->chamberType());
0522       Int_t nCh = (gid.chamber() - 1) * stationInfo.nNumModules_ + nIdxModule;
0523       ME4IdsKey key4Mod{gid.region(), gid.station(), gid.layer(), nCh};  // WARNING: Chamber+Module, not iEta
0524 
0525       Int_t nIdxVFAT = vfatStat->vfatPosition();
0526       Int_t nIdxVFATMod = nIdxVFAT;
0527       if (stationInfo.nNumModules_ > 1) {
0528         nIdxVFATMod = nIdxVFAT + nNumVFATPerModule * (nIdxModule - 1);
0529       }
0530 
0531       GEMVFATStatus::Warnings warnings{vfatStat->warnings()};
0532       if (warnings.basicOFW)
0533         mapStatusVFATPerCh_.Fill(key4Ch, nIdxVFATMod, 2);
0534       if (warnings.zeroSupOFW)
0535         mapStatusVFATPerCh_.Fill(key4Ch, nIdxVFATMod, 3);
0536 
0537       GEMVFATStatus::Errors errors{(uint8_t)vfatStat->errors()};
0538       if (errors.vc)
0539         mapStatusVFATPerCh_.Fill(key4Ch, nIdxVFATMod, 4);
0540       if (errors.InValidHeader)
0541         mapStatusVFATPerCh_.Fill(key4Ch, nIdxVFATMod, 5);
0542       if (errors.EC)
0543         mapStatusVFATPerCh_.Fill(key4Ch, nIdxVFATMod, 6);
0544       if (errors.BC)
0545         mapStatusVFATPerCh_.Fill(key4Ch, nIdxVFATMod, 7);
0546 
0547       Bool_t bWarn = warnings.wcodes != 0;
0548       Bool_t bErr = errors.codes != 0;
0549       if (!bWarn && !bErr)
0550         mapStatusVFATPerCh_.Fill(key4Ch, nIdxVFATMod, 1);
0551       if (bWarn)
0552         mapChamberVFATWarning[key4Mod] = false;
0553       if (bErr)
0554         mapChamberVFATError[key4Mod] = false;
0555       if (bWarn)
0556         mapStatusWarnVFATPerLayer_.Fill(key3, nCh, nIdxVFAT);
0557       if (bErr)
0558         mapStatusErrVFATPerLayer_.Fill(key3, nCh, nIdxVFAT);
0559       mapChamberAll[key4Mod] = true;
0560     }
0561   }
0562 
0563   if (nRunType_ == GEMDQM_RUNTYPE_ALLPLOTS || nRunType_ == GEMDQM_RUNTYPE_ONLINE) {
0564     // Summarizing all presence of status of each chamber
0565     for (auto const &[key4, bErr] : mapChamberAll) {
0566       ME3IdsKey key3 = key4Tokey3(key4);
0567       Int_t nChamber = keyToChamber(key4);
0568       h2SummaryStatusAll->Fill(nChamber, mapStationToIdx_[key3]);
0569     }
0570 
0571     // Summarizing all presence of status of each chamber
0572     FillStatusSummaryPlot(mapChamberAll, h2SummaryStatusAll);
0573     // Summarizing all the error and warning occupancy
0574     FillStatusSummaryPlot(mapChamberVFATWarning, h2SummaryStatusVFATWarning, &mapChamberWarning);
0575     FillStatusSummaryPlot(mapChamberVFATError, h2SummaryStatusVFATError, &mapChamberError);
0576     FillStatusSummaryPlot(mapChamberOHWarning, h2SummaryStatusOHWarning, &mapChamberWarning);
0577     FillStatusSummaryPlot(mapChamberOHError, h2SummaryStatusOHError, &mapChamberError);
0578     FillStatusSummaryPlot(mapChamberAMCWarning, h2SummaryStatusAMCWarning, &mapChamberWarning);
0579     FillStatusSummaryPlot(mapChamberAMCError, h2SummaryStatusAMCError, &mapChamberError);
0580     FillStatusSummaryPlot(mapChamberAMC13Error, h2SummaryStatusAMC13Error, &mapChamberError);
0581 
0582     FillStatusSummaryPlot(mapChamberWarning, h2SummaryStatusWarning);
0583     FillStatusSummaryPlot(mapChamberError, h2SummaryStatusError);
0584   }
0585 }
0586 
0587 DEFINE_FWK_MODULE(GEMDAQStatusSource);