File indexing completed on 2024-09-07 04:35:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/ModuleFactory.h"
0024 #include "FWCore/Framework/interface/ESProducer.h"
0025 #include "FWCore/Framework/interface/ModuleFactory.h"
0026
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029
0030 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0031 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0032 #include "CalibTracker/Records/interface/SiStripDependentRecords.h"
0033 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0034 #include "CondFormats/RunInfo/interface/RunInfo.h"
0035
0036 namespace {
0037 class ProductAdder {
0038 public:
0039 virtual ~ProductAdder() = default;
0040 virtual void add(const SiStripQualityRcd& iRecord, SiStripQuality& quality) const = 0;
0041 };
0042
0043 template <typename Product, typename RealRecord>
0044 class ProductAdderT : public ProductAdder {
0045 public:
0046 ProductAdderT(edm::ESConsumesCollector& cc, const std::string& label)
0047 : token_{cc.consumesFrom<Product, RealRecord>(edm::ESInputTag{"", label})} {}
0048 void add(const SiStripQualityRcd& iRecord, SiStripQuality& quality) const override {
0049 quality.add(&iRecord.get(token_));
0050 }
0051
0052 private:
0053 edm::ESGetToken<Product, RealRecord> token_;
0054 };
0055
0056 template <typename Product, typename RealRecord>
0057 auto make_ProductAdder(edm::ESConsumesCollector& cc, const std::string& label) {
0058 return std::make_unique<ProductAdderT<Product, RealRecord>>(cc, label);
0059 }
0060 }
0061
0062 class SiStripQualityESProducer : public edm::ESProducer {
0063 public:
0064 SiStripQualityESProducer(const edm::ParameterSet&);
0065 ~SiStripQualityESProducer() override {}
0066
0067 std::unique_ptr<SiStripQuality> produce(const SiStripQualityRcd&);
0068
0069 private:
0070 std::vector<std::unique_ptr<const ProductAdder>> productAdders_;
0071 edm::ESGetToken<RunInfo, RunInfoRcd> runInfoToken_;
0072
0073 const double thresholdForReducedGranularity_;
0074 const bool printDebugOutput_;
0075 const bool useEmptyRunInfo_;
0076 const bool reduceGranularity_;
0077 };
0078
0079 SiStripQualityESProducer::SiStripQualityESProducer(const edm::ParameterSet& iConfig)
0080 : thresholdForReducedGranularity_{iConfig.getParameter<double>("ThresholdForReducedGranularity")},
0081 printDebugOutput_{iConfig.getParameter<bool>("PrintDebugOutput")},
0082 useEmptyRunInfo_{iConfig.getParameter<bool>("UseEmptyRunInfo")},
0083 reduceGranularity_{iConfig.getParameter<bool>("ReduceGranularity")} {
0084 auto cc = setWhatProduced(this);
0085
0086 edm::LogInfo("SiStripQualityESProducer") << "ctor";
0087
0088 bool doRunInfo = false;
0089 std::string runInfoTagName = "";
0090
0091 auto toGet = iConfig.getParameter<std::vector<edm::ParameterSet>>("ListOfRecordToMerge");
0092
0093 for (const auto& toGetPSet : toGet) {
0094 auto tagName = toGetPSet.getParameter<std::string>("tag");
0095 auto recordName = toGetPSet.getParameter<std::string>("record");
0096
0097 edm::LogInfo("SiStripQualityESProducer")
0098 << "[SiStripQualityESProducer::ctor] Going to get data from record " << recordName << " with tag " << tagName;
0099
0100 if (recordName == "SiStripBadModuleRcd") {
0101 productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadModuleRcd>(cc, tagName));
0102 } else if (recordName == "SiStripBadFiberRcd") {
0103 productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadFiberRcd>(cc, tagName));
0104 } else if (recordName == "SiStripBadChannelRcd") {
0105 productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadChannelRcd>(cc, tagName));
0106 } else if (recordName == "SiStripBadStripRcd") {
0107 productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadStripRcd>(cc, tagName));
0108 } else if (recordName == "SiStripDetCablingRcd") {
0109 productAdders_.emplace_back(make_ProductAdder<SiStripDetCabling, SiStripDetCablingRcd>(cc, tagName));
0110 } else if (recordName == "SiStripDetVOffRcd") {
0111 productAdders_.emplace_back(make_ProductAdder<SiStripDetVOff, SiStripDetVOffRcd>(cc, tagName));
0112 } else if (recordName == "RunInfoRcd") {
0113 runInfoTagName = tagName;
0114 doRunInfo = true;
0115 } else {
0116
0117 edm::LogError("SiStripQualityESProducer")
0118 << "[SiStripQualityESProducer::ctor] Skipping the requested data for unexisting record " << recordName
0119 << " with tag " << tagName << std::endl;
0120 continue;
0121 }
0122 }
0123
0124 if (doRunInfo) {
0125 runInfoToken_ = cc.consumes(edm::ESInputTag{"", runInfoTagName});
0126 }
0127 }
0128
0129 std::unique_ptr<SiStripQuality> SiStripQualityESProducer::produce(const SiStripQualityRcd& iRecord) {
0130 const auto detInfo =
0131 SiStripDetInfoFileReader::read(edm::FileInPath{SiStripDetInfoFileReader::kDefaultFile}.fullPath());
0132 auto quality = std::make_unique<SiStripQuality>(detInfo);
0133 edm::LogInfo("SiStripQualityESProducer") << "produce called";
0134
0135
0136 quality->setPrintDebugOutput(printDebugOutput_);
0137
0138 quality->setUseEmptyRunInfo(useEmptyRunInfo_);
0139
0140 for (const auto& adder : productAdders_) {
0141 adder->add(iRecord, *quality);
0142 }
0143
0144
0145 if (runInfoToken_.isInitialized()) {
0146 quality->add(&iRecord.get(runInfoToken_));
0147 }
0148
0149 quality->cleanUp();
0150
0151 if (reduceGranularity_) {
0152 quality->ReduceGranularity(thresholdForReducedGranularity_);
0153 quality->cleanUp(true);
0154 }
0155
0156 quality->fillBadComponents();
0157
0158 return quality;
0159 }
0160
0161 DEFINE_FWK_EVENTSETUP_MODULE(SiStripQualityESProducer);