Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:32

0001 // -*- C++ -*-
0002 //
0003 // Package:    HcalTasks
0004 // Class:      HcalFEDIntegrityTask
0005 // Original Author: Long Wang - University of Maryland
0006 //
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 
0013 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0014 #include "DQMServices/Core/interface/DQMStore.h"
0015 
0016 #include "DQM/HcalCommon/interface/HcalCommonHeaders.h"
0017 
0018 #include <vector>
0019 #include <string>
0020 
0021 using namespace std;
0022 using namespace edm;
0023 
0024 class HcalFEDIntegrityTask : public DQMEDAnalyzer {
0025 public:
0026   HcalFEDIntegrityTask(const edm::ParameterSet &ps);
0027   ~HcalFEDIntegrityTask() override;
0028 
0029   void dqmBeginRun(const edm::Run &, edm::EventSetup const &) override;
0030   void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0031   void analyze(const edm::Event &, const edm::EventSetup &) override;
0032 
0033   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0034 
0035 private:
0036   void labelBins(MonitorElement *me);
0037 
0038   edm::EDGetTokenT<FEDRawDataCollection> tokFEDs_;
0039   edm::EDGetTokenT<HcalUnpackerReport> tokReport_;
0040 
0041   int numOfFED_, minFEDNum_, maxFEDNum_;
0042   std::string dirName_;
0043   MonitorElement *meFEDEntries_;
0044   MonitorElement *meFEDFatal_;
0045   MonitorElement *meFEDNonFatal_;
0046 };
0047 
0048 HcalFEDIntegrityTask::HcalFEDIntegrityTask(const edm::ParameterSet &ps)
0049     : tokFEDs_(consumes<FEDRawDataCollection>(
0050           ps.getUntrackedParameter<edm::InputTag>("tagFEDs", edm::InputTag("rawDataCollector")))),
0051       tokReport_(consumes<HcalUnpackerReport>(
0052           ps.getUntrackedParameter<edm::InputTag>("tagReport", edm::InputTag("hcalDigis")))),
0053       minFEDNum_(ps.getUntrackedParameter<int>("MinHcalFEDID", FEDNumbering::MINHCALuTCAFEDID)),
0054       maxFEDNum_(ps.getUntrackedParameter<int>("MaxHcalFEDID", FEDNumbering::MAXHCALuTCAFEDID)),
0055       dirName_(ps.getUntrackedParameter<std::string>("DirName", "Hcal/FEDIntegrity/")) {
0056   LogInfo("HcalDQM") << "HcalFEDIntegrityTask::HcalFEDIntegrityTask: Constructor Initialization" << endl;
0057   numOfFED_ = maxFEDNum_ - minFEDNum_ + 1;
0058 }
0059 
0060 HcalFEDIntegrityTask::~HcalFEDIntegrityTask() {
0061   LogInfo("HcalDQM") << "HcalFEDIntegrityTask::~HcalFEDIntegrityTask: Destructor" << endl;
0062 }
0063 
0064 void HcalFEDIntegrityTask::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {}
0065 
0066 void HcalFEDIntegrityTask::bookHistograms(DQMStore::IBooker &iBooker,
0067                                           edm::Run const &iRun,
0068                                           edm::EventSetup const &iSetup) {
0069   iBooker.cd();
0070   iBooker.setCurrentFolder(dirName_);
0071 
0072   meFEDEntries_ = iBooker.book1D("FEDEntries", "FED Entries", numOfFED_, minFEDNum_, maxFEDNum_ + 1);
0073   this->labelBins(meFEDEntries_);
0074   meFEDFatal_ = iBooker.book1D("FEDFatal", "FED Fatal Errors", numOfFED_, minFEDNum_, maxFEDNum_ + 1);
0075   this->labelBins(meFEDFatal_);
0076   meFEDNonFatal_ = iBooker.book1D("FEDNonFatal", "FED NON Fatal Errors", numOfFED_, minFEDNum_, maxFEDNum_ + 1);
0077   this->labelBins(meFEDNonFatal_);
0078 }
0079 
0080 void HcalFEDIntegrityTask::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0081   edm::Handle<FEDRawDataCollection> raw;
0082   edm::Handle<HcalUnpackerReport> report;
0083   iEvent.getByToken(tokFEDs_, raw);
0084   iEvent.getByToken(tokReport_, report);
0085 
0086   // FEDs with unpacking errors: https://github.com/cms-sw/cmssw/blob/master/EventFilter/HcalRawToDigi/plugins/HcalRawToDigi.cc#L235-L262
0087   const std::vector<int> FedsError = (*report).getFedsError();
0088   for (auto &fed : FedsError) {
0089     if (fed < 1000)
0090       LogWarning("HcalDQM") << "HcalFEDIntegrityTask::analyze: obsoleteVME FEDs from HcalUnpackerReport" << endl;
0091     meFEDFatal_->Fill(fed);
0092   }
0093 
0094   ///////////////////////////////////////////
0095   // Same checks as the RawTask Summary map
0096   ///////////////////////////////////////////
0097   for (int fed = FEDNumbering::MINHCALuTCAFEDID; fed <= FEDNumbering::MAXHCALuTCAFEDID; fed++) {
0098     const FEDRawData &fedRawData = raw->FEDData(fed);
0099     if (fedRawData.size() != 0) {
0100       meFEDEntries_->Fill(fed);
0101     }
0102 
0103     hcal::AMC13Header const *amc13 = (hcal::AMC13Header const *)fedRawData.data();
0104     if (!amc13) {
0105       continue;
0106     }
0107 
0108     uint32_t bcn = amc13->bunchId();
0109     uint32_t orn = amc13->orbitNumber() & 0xFFFF;  // LS 16bits only
0110     uint32_t evn = amc13->l1aNumber();
0111     int namc = amc13->NAMC();
0112 
0113     // looping over AMC in this packet
0114     for (int iamc = 0; iamc < namc; iamc++) {
0115       if (!amc13->AMCEnabled(iamc) || !amc13->AMCDataPresent(iamc) || !amc13->AMCCRCOk(iamc) ||
0116           amc13->AMCSegmented(iamc)) {
0117         LogWarning("HcalDQM") << "HcalFEDIntegrityTask::analyze: AMC issue on iamc" << iamc << endl;
0118         continue;
0119       }
0120 
0121       HcalUHTRData uhtr(amc13->AMCPayload(iamc), amc13->AMCSize(iamc));
0122       uint32_t uhtr_evn = uhtr.l1ANumber();
0123       uint32_t uhtr_bcn = uhtr.bunchNumber();
0124       uint32_t uhtr_orn = uhtr.orbitNumber();
0125 
0126       if (uhtr_evn != evn || uhtr_bcn != bcn || uhtr_orn != orn) {
0127         if (std::find(FedsError.begin(), FedsError.end(), fed) ==
0128             FedsError.end())  // FED not already in the error list from unpacker report
0129           meFEDFatal_->Fill(fed);
0130         break;  // one mismatch is sufficient enough to determine it's a bad data
0131       }
0132     }
0133 
0134   }  // end of Hcal FED looping
0135 }
0136 
0137 void HcalFEDIntegrityTask::labelBins(MonitorElement *me) {
0138   int xbins = me->getNbinsX();
0139 
0140   if (xbins != numOfFED_)
0141     return;
0142 
0143   for (int i = 0; i < xbins; i++) {
0144     const std::string xLabel = fmt::format("{}", minFEDNum_ + i);
0145     me->setBinLabel(i + 1, xLabel, 1);
0146   }
0147 }
0148 
0149 void HcalFEDIntegrityTask::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0150   edm::ParameterSetDescription desc;
0151   desc.addUntracked<std::string>("name", "HcalFEDIntegrityTask");
0152   desc.addUntracked<int>("debug", 0);
0153   desc.addUntracked<edm::InputTag>("tagFEDs", edm::InputTag("rawDataCollector"));
0154   desc.addUntracked<edm::InputTag>("tagReport", edm::InputTag("hcalDigis"));
0155   desc.addUntracked<int>(
0156       "MinHcalFEDID",
0157       FEDNumbering::MINHCALuTCAFEDID);  // Assuming no more VME FEDs after LS2, according to Hcal Phase1 upgrade.
0158   desc.addUntracked<int>("MaxHcalFEDID", FEDNumbering::MAXHCALuTCAFEDID);
0159   desc.addUntracked<std::string>("DirName", "Hcal/FEDIntegrity/");
0160   descriptions.addWithDefaultLabel(desc);
0161 }
0162 
0163 DEFINE_FWK_MODULE(HcalFEDIntegrityTask);