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
16 
17 #include "CLHEP/Random/RandFlat.h"
18 #include "CLHEP/Random/RandGauss.h"
19 
21 public:
22  explicit SiStripApvGainBuilder(const edm::ParameterSet& iConfig);
23 
24  ~SiStripApvGainBuilder() override = default;
25 
26  void analyze(const edm::Event&, const edm::EventSetup&) override;
27 
28 private:
30  const bool printdebug_;
31 };
32 
34  : fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
36  printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)) {}
37 
39  unsigned int run = evt.id().run();
40 
41  edm::LogInfo("SiStripApvGainBuilder") << "... creating dummy SiStripApvGain Data for Run " << run << "\n "
42  << std::endl;
43 
45 
47  const auto& DetInfos = reader.getAllData();
48 
49  int count = -1;
50  for (const auto& it : DetInfos) {
51  const auto& nAPVs = it.second.nApvs;
52  count++;
53  //Generate Gain for det detid
54  std::vector<float> theSiStripVector;
55  for (unsigned short j = 0; j < nAPVs; j++) {
56  float gain = (j + 1) * 1000 + (CLHEP::RandFlat::shoot(1.) * 100);
57  if (count < printdebug_)
58  edm::LogInfo("SiStripApvGainBuilder") << "detid " << it.first << " \t"
59  << " apv " << j << " \t" << gain << " \t" << std::endl;
60  theSiStripVector.push_back(gain);
61  }
62 
63  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
64  if (!obj.put(it.first, range))
65  edm::LogError("SiStripApvGainBuilder") << "[SiStripApvGainBuilder::analyze] detid already exists" << std::endl;
66  }
67 
68  //End now write sistripnoises data in DB
70 
71  if (mydbservice.isAvailable()) {
72  if (mydbservice->isNewTagRequest("SiStripApvGainRcd")) {
73  mydbservice->createOneIOV<SiStripApvGain>(obj, mydbservice->beginOfTime(), "SiStripApvGainRcd");
74  } else {
75  mydbservice->appendOneIOV<SiStripApvGain>(obj, mydbservice->currentTime(), "SiStripApvGainRcd");
76  }
77  } else {
78  edm::LogError("SiStripApvGainBuilder") << "Service is unavailable" << std::endl;
79  }
80 }
81 
84 
std::string fullPath() const
Definition: FileInPath.cc:161
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EventID id() const
Definition: EventBase.h:63
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_