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 
16 
17 #include "SiStripGainFactor.h"
18 
19 //
20 // class declaration
21 //
23 public:
25  ~SiStripGainESProducer() override{};
26 
27  std::unique_ptr<SiStripGain> produce(const SiStripGainRcd&);
28 
29 private:
30  class GainGetter {
31  public:
33  virtual ~GainGetter() = default;
34  virtual const SiStripApvGain& gain(const SiStripGainRcd& rcd) const = 0;
35 
36  const auto& recordLabel() const { return recordLabel_; }
37 
38  private:
39  std::pair<std::string, std::string> recordLabel_;
40  };
41 
42  template <typename Record>
43  class GainGetterT : public GainGetter {
44  public:
46  : GainGetter(std::move(record), std::move(label)),
47  token_{cc.consumesFrom<SiStripApvGain, Record>(edm::ESInputTag{"", recordLabel().second})} {}
48 
49  const SiStripApvGain& gain(const SiStripGainRcd& rcd) const override { return rcd.get(token_); }
50 
51  private:
53  };
54 
55  template <typename Record>
57  return std::make_unique<GainGetterT<Record>>(cc, std::move(record), std::move(label));
58  }
59 
60  std::vector<std::unique_ptr<GainGetter>> gainGetters_;
61 
63 };
64 
66  auto cc = setWhatProduced(this);
67 
68  auto apvGainLabels = iConfig.getParameter<std::vector<edm::ParameterSet>>("APVGain");
69  if (apvGainLabels.empty()) {
70  throw cms::Exception("Configuration") << "Got empty APVGain vector, but need at least one entry";
71  }
72 
73  // Fill the vector of apv labels
74  for (const auto& gainPSet : apvGainLabels) {
75  // Shouldn't all these parameters be tracked?
76  auto record = gainPSet.getParameter<std::string>("Record");
77  auto label = gainPSet.getUntrackedParameter<std::string>("Label", "");
78  if (record == "SiStripApvGainRcd")
79  gainGetters_.emplace_back(make_GainGetter<SiStripApvGainRcd>(cc, record, label));
80  else if (record == "SiStripApvGain2Rcd")
81  gainGetters_.emplace_back(make_GainGetter<SiStripApvGain2Rcd>(cc, record, label));
82  else if (record == "SiStripApvGain3Rcd")
83  gainGetters_.emplace_back(make_GainGetter<SiStripApvGain3Rcd>(cc, record, label));
84  else
85  throw cms::Exception("Configuration")
86  << "SiStripGainESProducer::ctor ERROR: unrecognized record name " << record << std::endl
87  << "please specify one of: SiStripApvGainRcd, SiStripApvGain2Rcd, SiStripApvGain3Rcd";
88  factor_.push_back_norm(gainPSet.getUntrackedParameter<double>("NormalizationFactor", 1.));
89  }
91 }
92 
93 std::unique_ptr<SiStripGain> SiStripGainESProducer::produce(const SiStripGainRcd& iRecord) {
94  const auto& apvGain = gainGetters_[0]->gain(iRecord);
95  // Create a new gain object and insert the ApvGain
96  auto gain = std::make_unique<SiStripGain>(apvGain, factor_.get(apvGain, 0), gainGetters_[0]->recordLabel());
97 
98  for (unsigned int i = 1; i < gainGetters_.size(); ++i) {
99  const auto& apvGain = gainGetters_[i]->gain(iRecord);
100  // Add the new ApvGain to the gain object
101  gain->multiply(apvGain, factor_.get(apvGain, i), gainGetters_[i]->recordLabel());
102  }
103 
104  return gain;
105 }
106 
108 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
std::unique_ptr< SiStripGain > produce(const SiStripGainRcd &)
JetCorrectorParameters::Record record
Definition: classes.h:7
virtual const SiStripApvGain & gain(const SiStripGainRcd &rcd) const =0
GainGetter(std::string record, std::string label)
auto consumesFrom(ESInputTag const &tag)
void push_back_norm(double norm)
SiStripGainESProducer(const edm::ParameterSet &)
std::pair< std::string, std::string > recordLabel_
char const * label
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::vector< std::unique_ptr< GainGetter > > gainGetters_
edm::ESGetToken< SiStripApvGain, Record > token_
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
const SiStripApvGain & gain(const SiStripGainRcd &rcd) const override
double get(const SiStripApvGain &gain, const int apvGainIndex) const
GainGetterT(edm::ESConsumesCollector &cc, std::string record, std::string label)
auto make_GainGetter(edm::ESConsumesCollector &cc, std::string record, std::string label)
def move(src, dest)
Definition: eostools.py:511