CMS 3D CMS Logo

SiStripGainESProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <utility>
4 
5 // user include files
8 
11 
17 
18 #include "SiStripGainFactor.h"
19 
20 //
21 // class declaration
22 //
24 public:
26  ~SiStripGainESProducer() override{};
27 
28  std::unique_ptr<SiStripGain> produce(const SiStripGainRcd&);
29 
30 private:
31  class GainGetter {
32  public:
34  virtual ~GainGetter() = default;
35  virtual const SiStripApvGain& gain(const SiStripGainRcd& rcd) const = 0;
36 
37  const auto& recordLabel() const { return recordLabel_; }
38 
39  private:
40  std::pair<std::string, std::string> recordLabel_;
41  };
42 
43  template <typename Record>
44  class GainGetterT : public GainGetter {
45  public:
49 
50  const SiStripApvGain& gain(const SiStripGainRcd& rcd) const override { return rcd.get(token_); }
51 
52  private:
54  };
55 
56  template <typename Record>
58  return std::make_unique<GainGetterT<Record>>(cc, std::move(record), std::move(label));
59  }
60 
61  std::vector<std::unique_ptr<GainGetter>> gainGetters_;
62 
64 };
65 
67  auto cc = setWhatProduced(this);
68 
69  auto apvGainLabels = iConfig.getParameter<std::vector<edm::ParameterSet>>("APVGain");
70  if (apvGainLabels.empty()) {
71  throw cms::Exception("Configuration") << "Got empty APVGain vector, but need at least one entry";
72  }
73 
74  // Fill the vector of apv labels
75  for (const auto& gainPSet : apvGainLabels) {
76  // Shouldn't all these parameters be tracked?
77  auto record = gainPSet.getParameter<std::string>("Record");
78  auto label = gainPSet.getUntrackedParameter<std::string>("Label", "");
79  if (record == "SiStripApvGainRcd")
80  gainGetters_.emplace_back(make_GainGetter<SiStripApvGainRcd>(cc, record, label));
81  else if (record == "SiStripApvGain2Rcd")
82  gainGetters_.emplace_back(make_GainGetter<SiStripApvGain2Rcd>(cc, record, label));
83  else if (record == "SiStripApvGain3Rcd")
84  gainGetters_.emplace_back(make_GainGetter<SiStripApvGain3Rcd>(cc, record, label));
85  else
86  throw cms::Exception("Configuration")
87  << "SiStripGainESProducer::ctor ERROR: unrecognized record name " << record << std::endl
88  << "please specify one of: SiStripApvGainRcd, SiStripApvGain2Rcd, SiStripApvGain3Rcd";
89  factor_.push_back_norm(gainPSet.getUntrackedParameter<double>("NormalizationFactor", 1.));
90  }
91  factor_.resetIfBadNorm();
92 }
93 
94 std::unique_ptr<SiStripGain> SiStripGainESProducer::produce(const SiStripGainRcd& iRecord) {
95  const auto detInfo =
97 
98  const auto& apvGain = gainGetters_[0]->gain(iRecord);
99  // Create a new gain object and insert the ApvGain
100  auto gain = std::make_unique<SiStripGain>(apvGain, factor_.get(apvGain, 0), gainGetters_[0]->recordLabel(), detInfo);
101 
102  for (unsigned int i = 1; i < gainGetters_.size(); ++i) {
103  const auto& apvGain = gainGetters_[i]->gain(iRecord);
104  // Add the new ApvGain to the gain object
105  gain->multiply(apvGain, factor_.get(apvGain, i), gainGetters_[i]->recordLabel(), detInfo);
106  }
107 
108  return gain;
109 }
110 
112 
std::unique_ptr< SiStripGain > produce(const SiStripGainRcd &)
const SiStripApvGain & gain(const SiStripGainRcd &rcd) const override
GainGetter(std::string record, std::string label)
auto consumesFrom(ESInputTag const &tag)
SiStripGainESProducer(const edm::ParameterSet &)
std::pair< std::string, std::string > recordLabel_
char const * label
std::vector< std::unique_ptr< GainGetter > > gainGetters_
SiStripDetInfo read(std::string filePath)
edm::ESGetToken< SiStripApvGain, Record > token_
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
double get(const SiStripApvGain &gain, const int apvGainIndex) const
static constexpr char const *const kDefaultFile
GainGetterT(edm::ESConsumesCollector &cc, std::string record, std::string label)
virtual const SiStripApvGain & gain(const SiStripGainRcd &rcd) const =0
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
auto make_GainGetter(edm::ESConsumesCollector &cc, std::string record, std::string label)
def move(src, dest)
Definition: eostools.py:511