CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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:
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  }
90  factor_.resetIfBadNorm();
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 
SiStripGainESProducer::GainGetter::gain
virtual const SiStripApvGain & gain(const SiStripGainRcd &rcd) const =0
SiStripDependentRecords.h
SiStripGainRcd
Definition: SiStripDependentRecords.h:29
SiStripGainESProducer::GainGetter
Definition: SiStripGainESProducer.cc:30
SiStripGainESProducer::SiStripGainESProducer
SiStripGainESProducer(const edm::ParameterSet &)
Definition: SiStripGainESProducer.cc:65
mps_fire.i
i
Definition: mps_fire.py:428
edm::ESInputTag
Definition: ESInputTag.h:87
MessageLogger.h
SiStripGainESProducer::GainGetter::GainGetter
GainGetter(std::string record, std::string label)
Definition: SiStripGainESProducer.cc:32
edm::ESConsumesCollector
Definition: ESConsumesCollector.h:61
SiStripGain.h
ESProducer.h
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
SiStripGainESProducer::make_GainGetter
auto make_GainGetter(edm::ESConsumesCollector &cc, std::string record, std::string label)
Definition: SiStripGainESProducer.cc:56
SiStripGainFactor.h
SiStripGainESProducer::GainGetterT::GainGetterT
GainGetterT(edm::ESConsumesCollector &cc, std::string record, std::string label)
Definition: SiStripGainESProducer.cc:45
SiStripGainESProducer::GainGetterT
Definition: SiStripGainESProducer.cc:43
SiStripGainESProducer::factor_
SiStripGainFactor factor_
Definition: SiStripGainESProducer.cc:62
SiStripGainFactor
Definition: SiStripGainFactor.h:9
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:103
SiStripApvGain.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripGainESProducer::GainGetterT::token_
edm::ESGetToken< SiStripApvGain, Record > token_
Definition: SiStripGainESProducer.cc:52
SiStripGainESProducer::GainGetter::recordLabel
const auto & recordLabel() const
Definition: SiStripGainESProducer.cc:36
SiStripGainESProducer::GainGetter::~GainGetter
virtual ~GainGetter()=default
SiStripGainESProducer::GainGetter::recordLabel_
std::pair< std::string, std::string > recordLabel_
Definition: SiStripGainESProducer.cc:39
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripCondDataRecords.h
SiStripGainFactor::get
double get(const SiStripApvGain &gain, const int apvGainIndex) const
Definition: SiStripGainFactor.h:28
cc
edm::ESGetToken< SiStripApvGain, Record >
SiStripGainESProducer::gainGetters_
std::vector< std::unique_ptr< GainGetter > > gainGetters_
Definition: SiStripGainESProducer.cc:60
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
ModuleFactory.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
SiStripGainESProducer::produce
std::unique_ptr< SiStripGain > produce(const SiStripGainRcd &)
Definition: SiStripGainESProducer.cc:93
SiStripGainESProducer::~SiStripGainESProducer
~SiStripGainESProducer() override
Definition: SiStripGainESProducer.cc:25
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
Record
Exception
Definition: hltDiff.cc:246
edm::ESProducer
Definition: ESProducer.h:104
ParameterSet.h
SiStripApvGain
Definition: SiStripApvGain.h:25
label
const char * label
Definition: PFTauDecayModeTools.cc:11
SiStripGainESProducer::GainGetterT::gain
const SiStripApvGain & gain(const SiStripGainRcd &rcd) const override
Definition: SiStripGainESProducer.cc:49
SiStripGainESProducer
Definition: SiStripGainESProducer.cc:22