CMS 3D CMS Logo

SiStripQualityESProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripQualityESProducer
4 // Class: SiStripQualityESProducer
5 //
13 //
14 // Original Author: Domenico GIORDANO
15 // Created: Wed Oct 3 12:11:10 CEST 2007
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
26 
29 
33 
34 namespace {
35  class ProductAdder {
36  public:
37  virtual ~ProductAdder() = default;
38  virtual void add(const SiStripQualityRcd& iRecord, SiStripQuality& quality) const = 0;
39  };
40 
41  template <typename Product, typename RealRecord>
42  class ProductAdderT : public ProductAdder {
43  public:
44  ProductAdderT(edm::ESConsumesCollector& cc, const std::string& label)
45  : token_{cc.consumesFrom<Product, RealRecord>(edm::ESInputTag{"", label})} {}
46  void add(const SiStripQualityRcd& iRecord, SiStripQuality& quality) const override {
47  quality.add(&iRecord.get(token_));
48  }
49 
50  private:
52  };
53 
54  template <typename Product, typename RealRecord>
55  auto make_ProductAdder(edm::ESConsumesCollector& cc, const std::string& label) {
56  return std::make_unique<ProductAdderT<Product, RealRecord>>(cc, label);
57  }
58 } // namespace
59 
61 public:
64 
65  std::unique_ptr<SiStripQuality> produce(const SiStripQualityRcd&);
66 
67 private:
68  std::vector<std::unique_ptr<const ProductAdder>> productAdders_;
70 
72  const bool printDebugOutput_;
73  const bool useEmptyRunInfo_;
74  const bool reduceGranularity_;
75 };
76 
78  : thresholdForReducedGranularity_{iConfig.getParameter<double>("ThresholdForReducedGranularity")},
79  printDebugOutput_{iConfig.getParameter<bool>("PrintDebugOutput")},
80  useEmptyRunInfo_{iConfig.getParameter<bool>("UseEmptyRunInfo")},
81  reduceGranularity_{iConfig.getParameter<bool>("ReduceGranularity")} {
82  auto cc = setWhatProduced(this);
83 
84  edm::LogInfo("SiStripQualityESProducer") << "ctor";
85 
86  bool doRunInfo = false;
87  std::string runInfoTagName = "";
88 
89  auto toGet = iConfig.getParameter<std::vector<edm::ParameterSet>>("ListOfRecordToMerge");
90 
91  for (const auto& toGetPSet : toGet) {
92  auto tagName = toGetPSet.getParameter<std::string>("tag");
93  auto recordName = toGetPSet.getParameter<std::string>("record");
94 
95  edm::LogInfo("SiStripQualityESProducer")
96  << "[SiStripQualityESProducer::ctor] Going to get data from record " << recordName << " with tag " << tagName;
97 
98  if (recordName == "SiStripBadModuleRcd") {
99  productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadModuleRcd>(cc, tagName));
100  } else if (recordName == "SiStripBadModuleFedErrRcd") {
101  productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadModuleFedErrRcd>(cc, tagName));
102  } else if (recordName == "SiStripBadFiberRcd") {
103  productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadFiberRcd>(cc, tagName));
104  } else if (recordName == "SiStripBadChannelRcd") {
105  productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadChannelRcd>(cc, tagName));
106  } else if (recordName == "SiStripBadStripRcd") {
107  productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadStripRcd>(cc, tagName));
108  } else if (recordName == "SiStripDetCablingRcd") {
109  productAdders_.emplace_back(make_ProductAdder<SiStripDetCabling, SiStripDetCablingRcd>(cc, tagName));
110  } else if (recordName == "SiStripDetVOffRcd") {
111  productAdders_.emplace_back(make_ProductAdder<SiStripDetVOff, SiStripDetVOffRcd>(cc, tagName));
112  } else if (recordName == "RunInfoRcd") {
113  runInfoTagName = tagName;
114  doRunInfo = true;
115  } else {
116  // Would it make sense to elevate this to an exception?
117  edm::LogError("SiStripQualityESProducer")
118  << "[SiStripQualityESProducer::ctor] Skipping the requested data for unexisting record " << recordName
119  << " with tag " << tagName << std::endl;
120  continue;
121  }
122  }
123 
124  if (doRunInfo) {
125  cc.setConsumes(runInfoToken_, edm::ESInputTag{"", runInfoTagName});
126  }
127 }
128 
129 std::unique_ptr<SiStripQuality> SiStripQualityESProducer::produce(const SiStripQualityRcd& iRecord) {
130  auto quality = std::make_unique<SiStripQuality>();
131  edm::LogInfo("SiStripQualityESProducer") << "produce called";
132 
133  // Set the debug output level
134  quality->setPrintDebugOutput(printDebugOutput_);
135  // Set the protection against empty RunInfo objects
136  quality->setUseEmptyRunInfo(useEmptyRunInfo_);
137 
138  for (const auto& adder : productAdders_) {
139  adder->add(iRecord, *quality);
140  }
141 
142  // We do this after all the others so we know it is done after the DetCabling (if any)
144  quality->add(&iRecord.get(runInfoToken_));
145  }
146 
147  quality->cleanUp();
148 
149  if (reduceGranularity_) {
150  quality->ReduceGranularity(thresholdForReducedGranularity_);
151  quality->cleanUp(true);
152  }
153 
154  quality->fillBadComponents();
155 
156  return quality;
157 }
158 
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
void add(const uint32_t &, const SiStripBadStrip::Range &)
auto consumesFrom(ESInputTag const &tag)
char const * label
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::unique_ptr< SiStripQuality > produce(const SiStripQualityRcd &)
edm::ESGetToken< RunInfo, RunInfoRcd > runInfoToken_
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
std::vector< std::unique_ptr< const ProductAdder > > productAdders_
constexpr bool isInitialized() const noexcept
Definition: ESGetToken.h:52
SiStripQualityESProducer(const edm::ParameterSet &)