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
5 #include <string>
6 
16 
17 template <typename TObject, typename TObjectO, typename TRecord>
18 class DummyCondDBWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
19 public:
20  explicit DummyCondDBWriter(const edm::ParameterSet& iConfig);
21  ~DummyCondDBWriter() override;
22  void analyze(const edm::Event& e, const edm::EventSetup& es) override{};
23  void beginRun(const edm::Run& run, const edm::EventSetup& es) override{};
24  void endRun(const edm::Run& run, const edm::EventSetup& es) override;
25 
26 private:
30 };
31 
32 template <typename TObject, typename TObjectO, typename TRecord>
34  : iConfig_(iConfig),
35  token_(esConsumes<edm::Transition::EndRun>(
36  edm::ESInputTag{"", iConfig.getUntrackedParameter<std::string>("label", "")})) {
38  edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter constructor for typename " << typeid(TObject).name()
39  << " and record " << typeid(TRecord).name();
40 }
41 
42 template <typename TObject, typename TObjectO, typename TRecord>
44  edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter::~DummyCondDBWriter()";
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();
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("DummyCondDBWriter") << "Service is unavailable";
74  }
75 }
76 
77 #endif
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
edm::ESWatcher< TRecord > watcher_
DummyCondDBWriter(const edm::ParameterSet &iConfig)
Log< level::Error, false > LogError
T getUntrackedParameter(std::string const &, T const &) const
unsigned long long Time_t
Definition: Time.h:14
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_
static const std::string kSharedResource
HLT enums.
void endRun(const edm::Run &run, const edm::EventSetup &es) override
bool isAvailable() const
Definition: Service.h:40
~DummyCondDBWriter() override
void analyze(const edm::Event &e, const edm::EventSetup &es) override
Definition: Run.h:45