File indexing completed on 2024-04-06 12:01:31
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0004 #include "FWCore/ServiceRegistry/interface/Service.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0007 #include "CondFormats/Calibration/interface/Pedestals.h"
0008
0009 #include <iostream>
0010 #include <string>
0011
0012 namespace edm {
0013 class ParameterSet;
0014 class Event;
0015 class EventSetup;
0016 }
0017
0018
0019 class Timestamp : public edm::one::EDAnalyzer<> {
0020 public:
0021 explicit Timestamp(const edm::ParameterSet& iConfig);
0022 virtual ~Timestamp();
0023 virtual void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup);
0024 virtual void endJob();
0025
0026 private:
0027 std::string m_record;
0028 };
0029
0030 Timestamp::Timestamp(const edm::ParameterSet& iConfig) : m_record(iConfig.getParameter<std::string>("record")) {
0031 std::cout << "Timestamp::Timestamp" << std::endl;
0032 }
0033 Timestamp::~Timestamp() { std::cout << "Timestamp::~Timestamp" << std::endl; }
0034 void Timestamp::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
0035 std::cout << "Timestamp::analyze " << std::endl;
0036 edm::Service<cond::service::PoolDBOutputService> mydbservice;
0037 if (!mydbservice.isAvailable()) {
0038 std::cout << "Service is unavailable" << std::endl;
0039 return;
0040 }
0041 cond::Time_t itime = (cond::Time_t)evt.time().value();
0042 std::string tag = mydbservice->tag(m_record);
0043 std::cout << "tag " << tag << std::endl;
0044 std::cout << "time " << itime << std::endl;
0045 Pedestals myped;
0046 for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0047 Pedestals::Item item;
0048 item.m_mean = 1.11 * ichannel + itime;
0049 item.m_variance = 1.12 * ichannel + itime;
0050 myped.m_pedestals.push_back(item);
0051 }
0052 std::cout << myped.m_pedestals[1].m_mean << std::endl;
0053 std::cout << "currentTime " << mydbservice->currentTime() << std::endl;
0054 if (mydbservice->currentTime() % 5 == 0) {
0055 mydbservice->writeOneIOV(myped, mydbservice->currentTime(), m_record);
0056 }
0057 }
0058 void Timestamp::endJob() {}
0059 DEFINE_FWK_MODULE(Timestamp);