Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
#include "DQMOffline/JetMET/interface/JetMETDQMDCSFilter.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/FEDRawData/interface/FEDNumbering.h"
#include "DataFormats/FEDRawData/interface/FEDRawData.h"
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "DataFormats/Scalers/interface/DcsStatus.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

//
// -- Constructor
//
JetMETDQMDCSFilter::JetMETDQMDCSFilter(const edm::ParameterSet& pset, edm::ConsumesCollector& iC) {
  verbose_ = pset.getUntrackedParameter<bool>("DebugOn", false);
  detectorTypes_ = pset.getUntrackedParameter<std::string>("DetectorTypes", "ecal:hcal");
  filter_ = !pset.getUntrackedParameter<bool>("alwaysPass", false);
  scalarsToken_ = iC.consumes<DcsStatusCollection>(std::string("scalersRawToDigi"));
  dcsRecordToken_ = iC.consumes<DCSRecord>(std::string("onlineMetaDataDigis"));

  detectorOn_ = false;
  if (verbose_)
    edm::LogPrint("JetMETDQMDCSFilter") << " constructor: " << detectorTypes_ << std::endl;

  // initialize variables
  initializeVars();
}

JetMETDQMDCSFilter::JetMETDQMDCSFilter(const std::string& detectorTypes,
                                       edm::ConsumesCollector& iC,
                                       const bool verbose,
                                       const bool alwaysPass) {
  verbose_ = verbose;
  detectorTypes_ = detectorTypes;
  filter_ = !alwaysPass;
  scalarsToken_ = iC.consumes<DcsStatusCollection>(std::string("scalersRawToDigi"));
  dcsRecordToken_ = iC.consumes<DCSRecord>(std::string("onlineMetaDataDigis"));

  detectorOn_ = false;
  if (verbose_)
    edm::LogPrint("JetMETDQMDCSFilter") << " constructor: " << detectorTypes_ << std::endl;

  // initialize variables
  initializeVars();
}

// initialize
void JetMETDQMDCSFilter::initializeVars() {
  passPIX = false, passSiStrip = false;
  passECAL = false, passES = false;
  passHBHE = false, passHF = false, passHO = false;
  passMuon = false;

  passPerDet_ = {{"pixel", false},
                 {"sistrip", false},
                 {"ecal", false},
                 {"hbhe", false},
                 {"hf", false},
                 {"ho", false},
                 {"es", false},
                 {"muon", false}};
}

//
// -- Destructor
//
JetMETDQMDCSFilter::~JetMETDQMDCSFilter() {
  if (verbose_)
    edm::LogPrint("JetMETDQMDCSFilter") << " destructor: " << std::endl;
}

template <typename T>
void JetMETDQMDCSFilter::checkDCSInfoPerPartition(const T& DCS) {
  if (associationMap_.empty()) {
    associationMap_ = {{"pixel", {T::BPIX, T::FPIX}},
                       {"sistrip", {T::TIBTID, T::TOB, T::TECp, T::TECm}},
                       {"ecal", {T::EBp, T::EBm, T::EEp, T::EEm}},
                       {"hbhe", {T::HBHEa, T::HBHEb, T::HBHEc}},
                       {"hf", {T::HF}},
                       {"ho", {T::HO}},
                       {"es", {T::ESp, T::ESm}},
                       {"muon", {T::RPC, T::DT0, T::DTp, T::DTm, T::CSCp, T::CSCm}}};
  }

  for (const auto& [detName, listOfParts] : associationMap_) {
    if (detectorTypes_.find(detName) != std::string::npos) {
      bool ANDofParts{true};
      for (const auto& part : listOfParts) {
        if constexpr (std::is_same_v<T, DcsStatus>) {
          ANDofParts &= DCS.ready(part);
        } else if constexpr (std::is_same_v<T, DCSRecord>) {
          ANDofParts &= DCS.highVoltageReady(part);
        } else {
          edm::LogError("JetMETDQMDCSFilter")
              << __FILE__ << " " << __LINE__ << " passed a wrong object type, cannot deduce DCS information.\n"
              << " returning true" << std::endl;
          ANDofParts &= true;
        }
      }

      if (ANDofParts) {
        if (verbose_) {
          edm::LogPrint("JetMETDQMDCSFilter") << detName << " on" << std::endl;
        }
        passPerDet_[detName] = true;
      } else {
        detectorOn_ = false;
      }
    }  // if it matches the requested detname
  }  // loop on partitions
}

bool JetMETDQMDCSFilter::filter(const edm::Event& evt, const edm::EventSetup& es) {
  detectorOn_ = true;

  if (!evt.isRealData())
    return detectorOn_;
  if (!filter_)
    return detectorOn_;

  edm::Handle<DcsStatusCollection> dcsStatus;
  evt.getByToken(scalarsToken_, dcsStatus);

  edm::Handle<DCSRecord> dcsRecord;
  evt.getByToken(dcsRecordToken_, dcsRecord);

  if (dcsStatus.isValid() && !dcsStatus->empty()) {
    checkDCSInfoPerPartition((*dcsStatus)[0]);
  } else if (dcsRecord.isValid()) {
    checkDCSInfoPerPartition(*dcsRecord);
  } else {
    edm::LogError("JetMETDQMDCSFilter")
        << "Error! can't get the product, neither DCSRecord, nor scalersRawToDigi: accept in any case!";
  }

  // assign the values
  passPIX = passPerDet_["pixel"];
  passSiStrip = passPerDet_["sistrip"];
  passECAL = passPerDet_["ecal"];
  passES = passPerDet_["es"];
  passHBHE = passPerDet_["hbhe"];
  passHF = passPerDet_["hf"];
  passHO = passPerDet_["ho"];
  passMuon = passPerDet_["muon"];

  if (verbose_) {
    if (detectorOn_)
      edm::LogPrint("JetMETDQMDCSFilter") << "event pass!";

    std::stringstream ss;
    for (const auto& [detName, result] : passPerDet_) {
      if (detectorTypes_.find(detName) != std::string::npos) {
        ss << "Passes " << detName << ": " << (result ? "True\n" : "False\n");
      }
    }

    edm::LogPrint("JetMETDQMDCSFilter") << ss.str();
  }

  return detectorOn_;
}