CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>
19 class DummyCondDBWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
20 public:
22  ~DummyCondDBWriter() override;
23  void analyze(const edm::Event& e, const edm::EventSetup& es) override{};
24  void beginRun(const edm::Run& run, const edm::EventSetup& es) override{};
25  void endRun(const edm::Run& run, const edm::EventSetup& es) override;
26 
27 private:
31 };
32 
33 template <typename TObject, typename TObjectO, typename TRecord>
35  : iConfig_(iConfig),
36  token_(esConsumes<edm::Transition::EndRun>(
37  edm::ESInputTag{"", iConfig.getUntrackedParameter<std::string>("label", "")})) {
38  edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter constructor for typename " << typeid(TObject).name()
39  << " and record " << typeid(TRecord).name() << std::endl;
40 }
41 
42 template <typename TObject, typename TObjectO, typename TRecord>
44  edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter::~DummyCondDBWriter()" << std::endl;
45 }
46 
47 template <typename TObject, typename TObjectO, typename TRecord>
49  std::string rcdName = iConfig_.getParameter<std::string>("record");
50 
51  if (!watcher_.check(es)) {
52  edm::LogInfo("DummyCondDBWriter") << "not needed to store objects with Record " << rcdName << " at run "
53  << run.run() << std::endl;
54  return;
55  }
56 
57  auto obj = std::make_unique<TObjectO>(es.getData(token_));
58  cond::Time_t Time_;
59 
60  //And now write data in DB
62  if (dbservice.isAvailable()) {
63  std::string openIovAt = iConfig_.getUntrackedParameter<std::string>("OpenIovAt", "beginOfTime");
64  if (openIovAt == "beginOfTime")
65  Time_ = dbservice->beginOfTime();
66  else if (openIovAt == "currentTime")
67  Time_ = dbservice->currentTime();
68  else
69  Time_ = iConfig_.getUntrackedParameter<uint32_t>("OpenIovAtTime", 1);
70 
71  dbservice->writeOneIOV(*obj, Time_, rcdName);
72  } else {
73  edm::LogError("SiStripFedCablingBuilder") << "Service is unavailable" << std::endl;
74  }
75 }
76 
77 #endif
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
T getUntrackedParameter(std::string const &, T const &) const
RunNumber_t run() const
Definition: RunBase.h:40
edm::ESWatcher< TRecord > watcher_
DummyCondDBWriter(const edm::ParameterSet &iConfig)
Log< level::Error, false > LogError
bool getData(T &iHolder) const
Definition: EventSetup.h:128
unsigned long long Time_t
Definition: Time.h:14
bool isAvailable() const
Definition: Service.h:40
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Transition
Definition: Transition.h:12
Log< level::Info, false > LogInfo
edm::ESGetToken< TObject, TRecord > token_
edm::ParameterSet iConfig_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
void endRun(const edm::Run &run, const edm::EventSetup &es) override
~DummyCondDBWriter() override
void analyze(const edm::Event &e, const edm::EventSetup &es) override
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: Run.h:45