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:
48  token_{cc.consumesFrom<SiStripApvGain, Record>(edm::ESInputTag{"", recordLabel().second})} {}
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 
SiStripGainESProducer::GainGetter::gain
virtual const SiStripApvGain & gain(const SiStripGainRcd &rcd) const =0
SiStripDependentRecords.h
SiStripGainRcd
Definition: SiStripDependentRecords.h:29
SiStripGainESProducer::GainGetter
Definition: SiStripGainESProducer.cc:31
SiStripGainESProducer::SiStripGainESProducer
SiStripGainESProducer(const edm::ParameterSet &)
Definition: SiStripGainESProducer.cc:66
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:33
edm::ESConsumesCollector
Definition: ESConsumesCollector.h:61
SiStripGain.h
ESProducer.h
SiStripGainESProducer::make_GainGetter
auto make_GainGetter(edm::ESConsumesCollector &cc, std::string record, std::string label)
Definition: SiStripGainESProducer.cc:57
SiStripGainFactor.h
SiStripDetInfoFileReader::read
SiStripDetInfo read(std::string filePath)
Definition: SiStripDetInfoFileReader.cc:11
edm::FileInPath
Definition: FileInPath.h:61
SiStripGainESProducer::GainGetterT::GainGetterT
GainGetterT(edm::ESConsumesCollector &cc, std::string record, std::string label)
Definition: SiStripGainESProducer.cc:46
SiStripGainESProducer::GainGetterT
Definition: SiStripGainESProducer.cc:44
SiStripGainESProducer::factor_
SiStripGainFactor factor_
Definition: SiStripGainESProducer.cc:63
SiStripGainFactor
Definition: SiStripGainFactor.h:9
SiStripDetInfoFileReader.h
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:109
SiStripApvGain.h
SiStripGainESProducer::GainGetterT::token_
edm::ESGetToken< SiStripApvGain, Record > token_
Definition: SiStripGainESProducer.cc:53
SiStripGainESProducer::GainGetter::recordLabel
const auto & recordLabel() const
Definition: SiStripGainESProducer.cc:37
SiStripGainESProducer::GainGetter::~GainGetter
virtual ~GainGetter()=default
SiStripGainESProducer::GainGetter::recordLabel_
std::pair< std::string, std::string > recordLabel_
Definition: SiStripGainESProducer.cc:40
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripCondDataRecords.h
SiStripGainFactor::get
double get(const SiStripApvGain &gain, const int apvGainIndex) const
Definition: SiStripGainFactor.h:28
AlCaHarvesting_cff.record
record
Definition: AlCaHarvesting_cff.py:42
cc
edm::ESGetToken< SiStripApvGain, Record >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripGainESProducer::gainGetters_
std::vector< std::unique_ptr< GainGetter > > gainGetters_
Definition: SiStripGainESProducer.cc:61
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:94
SiStripGainESProducer::~SiStripGainESProducer
~SiStripGainESProducer() override
Definition: SiStripGainESProducer.cc:26
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
Record
SiStripDetInfoFileReader::kDefaultFile
constexpr static char const *const kDefaultFile
Definition: SiStripDetInfoFileReader.h:10
Exception
Definition: hltDiff.cc:245
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:50
SiStripGainESProducer
Definition: SiStripGainESProducer.cc:23