CMS 3D CMS Logo

SiStripApvGainBuilder.cc
Go to the documentation of this file.
1 // system include files
2 #include <fstream>
3 #include <iostream>
4 
5 // user include files
14 
15 #include "CLHEP/Random/RandFlat.h"
16 #include "CLHEP/Random/RandGauss.h"
17 
19 public:
20  explicit SiStripApvGainBuilder(const edm::ParameterSet& iConfig);
21 
22  ~SiStripApvGainBuilder() override = default;
23 
24  void analyze(const edm::Event&, const edm::EventSetup&) override;
25 
26 private:
28  const bool printdebug_;
29 };
30 
32  : fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
34  printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)) {}
35 
37  unsigned int run = evt.id().run();
38 
39  edm::LogInfo("SiStripApvGainBuilder") << "... creating dummy SiStripApvGain Data for Run " << run << "\n "
40  << std::endl;
41 
43 
45  const auto& DetInfos = reader.getAllData();
46 
47  int count = -1;
48  for (const auto& it : DetInfos) {
49  const auto& nAPVs = it.second.nApvs;
50  count++;
51  //Generate Gain for det detid
52  std::vector<float> theSiStripVector;
53  for (unsigned short j = 0; j < nAPVs; j++) {
54  float gain = (j + 1) * 1000 + (CLHEP::RandFlat::shoot(1.) * 100);
55  if (count < printdebug_)
56  edm::LogInfo("SiStripApvGainBuilder") << "detid " << it.first << " \t"
57  << " apv " << j << " \t" << gain << " \t" << std::endl;
58  theSiStripVector.push_back(gain);
59  }
60 
61  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
62  if (!obj.put(it.first, range))
63  edm::LogError("SiStripApvGainBuilder") << "[SiStripApvGainBuilder::analyze] detid already exists" << std::endl;
64  }
65 
66  //End now write sistripnoises data in DB
68 
69  if (mydbservice.isAvailable()) {
70  if (mydbservice->isNewTagRequest("SiStripApvGainRcd")) {
71  mydbservice->createOneIOV<SiStripApvGain>(obj, mydbservice->beginOfTime(), "SiStripApvGainRcd");
72  } else {
73  mydbservice->appendOneIOV<SiStripApvGain>(obj, mydbservice->currentTime(), "SiStripApvGainRcd");
74  }
75  } else {
76  edm::LogError("SiStripApvGainBuilder") << "Service is unavailable" << std::endl;
77  }
78 }
79 
82 
std::string fullPath() const
Definition: FileInPath.cc:161
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &, const edm::EventSetup &) override
reader
Definition: DQM.py:105
Log< level::Error, false > LogError
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
bool isNewTagRequest(const std::string &recordName)
~SiStripApvGainBuilder() override=default
std::pair< ContainerIterator, ContainerIterator > Range
edm::EventID id() const
Definition: EventBase.h:59
SiStripDetInfo read(std::string filePath)
Log< level::Info, false > LogInfo
RunNumber_t run() const
Definition: EventID.h:38
HLT enums.
static constexpr char const *const kDefaultFile
bool isAvailable() const
Definition: Service.h:40
SiStripApvGainBuilder(const edm::ParameterSet &iConfig)
const edm::FileInPath fp_