Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:31

0001 #include "DQMOffline/JetMET/interface/JetMETDQMDCSFilter.h"
0002 #include "DataFormats/Common/interface/Handle.h"
0003 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0004 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0005 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0006 #include "DataFormats/Scalers/interface/DcsStatus.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 
0011 //
0012 // -- Constructor
0013 //
0014 JetMETDQMDCSFilter::JetMETDQMDCSFilter(const edm::ParameterSet& pset, edm::ConsumesCollector& iC) {
0015   verbose_ = pset.getUntrackedParameter<bool>("DebugOn", false);
0016   detectorTypes_ = pset.getUntrackedParameter<std::string>("DetectorTypes", "ecal:hcal");
0017   filter_ = !pset.getUntrackedParameter<bool>("alwaysPass", false);
0018   scalarsToken_ = iC.consumes<DcsStatusCollection>(std::string("scalersRawToDigi"));
0019   dcsRecordToken_ = iC.consumes<DCSRecord>(std::string("onlineMetaDataDigis"));
0020 
0021   detectorOn_ = false;
0022   if (verbose_)
0023     edm::LogPrint("JetMETDQMDCSFilter") << " constructor: " << detectorTypes_ << std::endl;
0024 
0025   // initialize variables
0026   initializeVars();
0027 }
0028 
0029 JetMETDQMDCSFilter::JetMETDQMDCSFilter(const std::string& detectorTypes,
0030                                        edm::ConsumesCollector& iC,
0031                                        const bool verbose,
0032                                        const bool alwaysPass) {
0033   verbose_ = verbose;
0034   detectorTypes_ = detectorTypes;
0035   filter_ = !alwaysPass;
0036   scalarsToken_ = iC.consumes<DcsStatusCollection>(std::string("scalersRawToDigi"));
0037   dcsRecordToken_ = iC.consumes<DCSRecord>(std::string("onlineMetaDataDigis"));
0038 
0039   detectorOn_ = false;
0040   if (verbose_)
0041     edm::LogPrint("JetMETDQMDCSFilter") << " constructor: " << detectorTypes_ << std::endl;
0042 
0043   // initialize variables
0044   initializeVars();
0045 }
0046 
0047 // initialize
0048 void JetMETDQMDCSFilter::initializeVars() {
0049   passPIX = false, passSiStrip = false;
0050   passECAL = false, passES = false;
0051   passHBHE = false, passHF = false, passHO = false;
0052   passMuon = false;
0053 
0054   passPerDet_ = {{"pixel", false},
0055                  {"sistrip", false},
0056                  {"ecal", false},
0057                  {"hbhe", false},
0058                  {"hf", false},
0059                  {"ho", false},
0060                  {"es", false},
0061                  {"muon", false}};
0062 }
0063 
0064 //
0065 // -- Destructor
0066 //
0067 JetMETDQMDCSFilter::~JetMETDQMDCSFilter() {
0068   if (verbose_)
0069     edm::LogPrint("JetMETDQMDCSFilter") << " destructor: " << std::endl;
0070 }
0071 
0072 template <typename T>
0073 void JetMETDQMDCSFilter::checkDCSInfoPerPartition(const T& DCS) {
0074   if (associationMap_.empty()) {
0075     associationMap_ = {{"pixel", {T::BPIX, T::FPIX}},
0076                        {"sistrip", {T::TIBTID, T::TOB, T::TECp, T::TECm}},
0077                        {"ecal", {T::EBp, T::EBm, T::EEp, T::EEm}},
0078                        {"hbhe", {T::HBHEa, T::HBHEb, T::HBHEc}},
0079                        {"hf", {T::HF}},
0080                        {"ho", {T::HO}},
0081                        {"es", {T::ESp, T::ESm}},
0082                        {"muon", {T::RPC, T::DT0, T::DTp, T::DTm, T::CSCp, T::CSCm}}};
0083   }
0084 
0085   for (const auto& [detName, listOfParts] : associationMap_) {
0086     if (detectorTypes_.find(detName) != std::string::npos) {
0087       bool ANDofParts{true};
0088       for (const auto& part : listOfParts) {
0089         if constexpr (std::is_same_v<T, DcsStatus>) {
0090           ANDofParts &= DCS.ready(part);
0091         } else if constexpr (std::is_same_v<T, DCSRecord>) {
0092           ANDofParts &= DCS.highVoltageReady(part);
0093         } else {
0094           edm::LogError("JetMETDQMDCSFilter")
0095               << __FILE__ << " " << __LINE__ << " passed a wrong object type, cannot deduce DCS information.\n"
0096               << " returning true" << std::endl;
0097           ANDofParts &= true;
0098         }
0099       }
0100 
0101       if (ANDofParts) {
0102         if (verbose_) {
0103           edm::LogPrint("JetMETDQMDCSFilter") << detName << " on" << std::endl;
0104         }
0105         passPerDet_[detName] = true;
0106       } else {
0107         detectorOn_ = false;
0108       }
0109     }  // if it matches the requested detname
0110   }    // loop on partitions
0111 }
0112 
0113 bool JetMETDQMDCSFilter::filter(const edm::Event& evt, const edm::EventSetup& es) {
0114   detectorOn_ = true;
0115 
0116   if (!evt.isRealData())
0117     return detectorOn_;
0118   if (!filter_)
0119     return detectorOn_;
0120 
0121   edm::Handle<DcsStatusCollection> dcsStatus;
0122   evt.getByToken(scalarsToken_, dcsStatus);
0123 
0124   edm::Handle<DCSRecord> dcsRecord;
0125   evt.getByToken(dcsRecordToken_, dcsRecord);
0126 
0127   if (dcsStatus.isValid() && !dcsStatus->empty()) {
0128     checkDCSInfoPerPartition((*dcsStatus)[0]);
0129   } else if (dcsRecord.isValid()) {
0130     checkDCSInfoPerPartition(*dcsRecord);
0131   } else {
0132     edm::LogError("JetMETDQMDCSFilter")
0133         << "Error! can't get the product, neither DCSRecord, nor scalersRawToDigi: accept in any case!";
0134   }
0135 
0136   // assign the values
0137   passPIX = passPerDet_["pixel"];
0138   passSiStrip = passPerDet_["sistrip"];
0139   passECAL = passPerDet_["ecal"];
0140   passES = passPerDet_["es"];
0141   passHBHE = passPerDet_["hbhe"];
0142   passHF = passPerDet_["hf"];
0143   passHO = passPerDet_["ho"];
0144   passMuon = passPerDet_["muon"];
0145 
0146   if (verbose_) {
0147     if (detectorOn_)
0148       edm::LogPrint("JetMETDQMDCSFilter") << "event pass!";
0149 
0150     std::stringstream ss;
0151     for (const auto& [detName, result] : passPerDet_) {
0152       if (detectorTypes_.find(detName) != std::string::npos) {
0153         ss << "Passes " << detName << ": " << (result ? "True\n" : "False\n");
0154       }
0155     }
0156 
0157     edm::LogPrint("JetMETDQMDCSFilter") << ss.str();
0158   }
0159 
0160   return detectorOn_;
0161 }