CMS 3D CMS Logo

DummyCondDBWriter.h
Go to the documentation of this file.
1 #ifndef CalibTracker_SiStripESProducer_DummyCondDBWriter_h
2 #define CalibTracker_SiStripESProducer_DummyCondDBWriter_h
3 
4 // user include files
13 
15 
16 #include <string>
17 
18 template <typename TObject, typename TObjectO, typename TRecord>
20 public:
21  explicit DummyCondDBWriter(const edm::ParameterSet& iConfig);
22  ~DummyCondDBWriter() override;
23  void analyze(const edm::Event& e, const edm::EventSetup& es) override{};
24 
25  void endRun(const edm::Run& run, const edm::EventSetup& es) override;
26 
27 private:
29  unsigned long long cacheID;
30 };
31 
32 template <typename TObject, typename TObjectO, typename TRecord>
34  : iConfig_(iConfig), cacheID(0) {
35  edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter constructor for typename " << typeid(TObject).name()
36  << " and record " << typeid(TRecord).name() << std::endl;
37 }
38 
39 template <typename TObject, typename TObjectO, typename TRecord>
41  edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter::~DummyCondDBWriter()" << std::endl;
42 }
43 
44 template <typename TObject, typename TObjectO, typename TRecord>
46  std::string rcdName = iConfig_.getParameter<std::string>("record");
47  std::string labelName = iConfig_.getUntrackedParameter<std::string>("label", "");
48 
49  if (cacheID == es.get<TRecord>().cacheIdentifier()) {
50  edm::LogInfo("DummyCondDBWriter") << "not needed to store objects with Record " << rcdName << " at run "
51  << run.run() << std::endl;
52  return;
53  }
54  cacheID = es.get<TRecord>().cacheIdentifier();
55 
57  es.get<TRecord>().get(labelName, esobj);
58  TObjectO* obj = new TObjectO(*(esobj.product()));
59  cond::Time_t Time_;
60 
61  //And now write data in DB
63  if (dbservice.isAvailable()) {
64  std::string openIovAt = iConfig_.getUntrackedParameter<std::string>("OpenIovAt", "beginOfTime");
65  if (openIovAt == "beginOfTime")
66  Time_ = dbservice->beginOfTime();
67  else if (openIovAt == "currentTime")
68  Time_ = dbservice->currentTime();
69  else
70  Time_ = iConfig_.getUntrackedParameter<uint32_t>("OpenIovAtTime", 1);
71 
72  dbservice->writeOne(obj, Time_, rcdName);
73  } else {
74  edm::LogError("SiStripFedCablingBuilder") << "Service is unavailable" << std::endl;
75  }
76 }
77 
78 #endif
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
RunNumber_t run() const
Definition: RunBase.h:40
DummyCondDBWriter(const edm::ParameterSet &iConfig)
unsigned long long Time_t
Definition: Time.h:14
bool isAvailable() const
Definition: Service.h:40
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
unsigned long long cacheID
edm::ParameterSet iConfig_
T get() const
Definition: EventSetup.h:73
void endRun(const edm::Run &run, const edm::EventSetup &es) override
~DummyCondDBWriter() override
void analyze(const edm::Event &e, const edm::EventSetup &es) override
T const * product() const
Definition: ESHandle.h:86
Definition: Run.h:45