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 
35 
36 namespace {
37  class ProductAdder {
38  public:
39  virtual ~ProductAdder() = default;
40  virtual void add(const SiStripQualityRcd& iRecord, SiStripQuality& quality) const = 0;
41  };
42 
43  template <typename Product, typename RealRecord>
44  class ProductAdderT : public ProductAdder {
45  public:
46  ProductAdderT(edm::ESConsumesCollector& cc, const std::string& label)
47  : token_{cc.consumesFrom<Product, RealRecord>(edm::ESInputTag{"", label})} {}
48  void add(const SiStripQualityRcd& iRecord, SiStripQuality& quality) const override {
49  quality.add(&iRecord.get(token_));
50  }
51 
52  private:
54  };
55 
56  template <typename Product, typename RealRecord>
57  auto make_ProductAdder(edm::ESConsumesCollector& cc, const std::string& label) {
58  return std::make_unique<ProductAdderT<Product, RealRecord>>(cc, label);
59  }
60 } // namespace
61 
63 public:
66 
67  std::unique_ptr<SiStripQuality> produce(const SiStripQualityRcd&);
68 
69 private:
70  std::vector<std::unique_ptr<const ProductAdder>> productAdders_;
72 
74  const bool printDebugOutput_;
75  const bool useEmptyRunInfo_;
76  const bool reduceGranularity_;
77 };
78 
80  : thresholdForReducedGranularity_{iConfig.getParameter<double>("ThresholdForReducedGranularity")},
81  printDebugOutput_{iConfig.getParameter<bool>("PrintDebugOutput")},
82  useEmptyRunInfo_{iConfig.getParameter<bool>("UseEmptyRunInfo")},
83  reduceGranularity_{iConfig.getParameter<bool>("ReduceGranularity")} {
84  auto cc = setWhatProduced(this);
85 
86  edm::LogInfo("SiStripQualityESProducer") << "ctor";
87 
88  bool doRunInfo = false;
89  std::string runInfoTagName = "";
90 
91  auto toGet = iConfig.getParameter<std::vector<edm::ParameterSet>>("ListOfRecordToMerge");
92 
93  for (const auto& toGetPSet : toGet) {
94  auto tagName = toGetPSet.getParameter<std::string>("tag");
95  auto recordName = toGetPSet.getParameter<std::string>("record");
96 
97  edm::LogInfo("SiStripQualityESProducer")
98  << "[SiStripQualityESProducer::ctor] Going to get data from record " << recordName << " with tag " << tagName;
99 
100  if (recordName == "SiStripBadModuleRcd") {
101  productAdders_.emplace_back(make_ProductAdder<SiStripBadStrip, SiStripBadModuleRcd>(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  runInfoToken_ = cc.consumes(edm::ESInputTag{"", runInfoTagName});
126  }
127 }
128 
129 std::unique_ptr<SiStripQuality> SiStripQualityESProducer::produce(const SiStripQualityRcd& iRecord) {
130  const auto detInfo =
132  auto quality = std::make_unique<SiStripQuality>(detInfo);
133  edm::LogInfo("SiStripQualityESProducer") << "produce called";
134 
135  // Set the debug output level
136  quality->setPrintDebugOutput(printDebugOutput_);
137  // Set the protection against empty RunInfo objects
138  quality->setUseEmptyRunInfo(useEmptyRunInfo_);
139 
140  for (const auto& adder : productAdders_) {
141  adder->add(iRecord, *quality);
142  }
143 
144  // We do this after all the others so we know it is done after the DetCabling (if any)
146  quality->add(&iRecord.get(runInfoToken_));
147  }
148 
149  quality->cleanUp();
150 
151  if (reduceGranularity_) {
152  quality->ReduceGranularity(thresholdForReducedGranularity_);
153  quality->cleanUp(true);
154  }
155 
156  quality->fillBadComponents();
157 
158  return quality;
159 }
160 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
auto consumesFrom(ESInputTag const &tag)
Log< level::Error, false > LogError
char const * label
constexpr bool isInitialized() const noexcept
Definition: ESGetToken.h:72
std::unique_ptr< SiStripQuality > produce(const SiStripQualityRcd &)
SiStripDetInfo read(std::string filePath)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
edm::ESGetToken< RunInfo, RunInfoRcd > runInfoToken_
Log< level::Info, false > LogInfo
std::vector< std::unique_ptr< const ProductAdder > > productAdders_
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
static constexpr char const *const kDefaultFile
string quality
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
SiStripQualityESProducer(const edm::ParameterSet &)