Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-08 08:15:55

0001 // -*- C++ -*-
0002 //
0003 // Class:      WriteCTPPSBeamParameters
0004 //
0005 // Description: Test analyzer for CTPPS beam parameters condition data
0006 //
0007 //              Simple analyzer that writes one CTTPSBeamParameters record into a sql
0008 //              database file, as a test of offline conditions implementation.
0009 //              Another analyzer is then used to retrieve these conditions.
0010 //
0011 // Original Author:  Wagner De Paula Carvalho
0012 //         Created:  Wed, 21 Nov 2018 17:35:07 GMT
0013 //
0014 //==================================================================================
0015 
0016 // system include files
0017 #include <memory>
0018 
0019 // user include files
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0023 #include "FWCore/Framework/interface/ESHandle.h"
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "FWCore/ServiceRegistry/interface/Service.h"
0029 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0030 
0031 #include "CondFormats/PPSObjects/interface/CTPPSBeamParameters.h"
0032 #include "CondFormats/DataRecord/interface/CTPPSBeamParametersRcd.h"
0033 
0034 #include <cstdint>
0035 
0036 class WriteCTPPSBeamParameters : public edm::one::EDAnalyzer<> {
0037 public:
0038   WriteCTPPSBeamParameters(const edm::ParameterSet&)
0039       : tokenBeamParameters_(esConsumes<CTPPSBeamParameters, CTPPSBeamParametersRcd>()) {}
0040 
0041   ~WriteCTPPSBeamParameters() override = default;
0042 
0043 private:
0044   void analyze(const edm::Event&, const edm::EventSetup&) override;
0045 
0046   edm::ESGetToken<CTPPSBeamParameters, CTPPSBeamParametersRcd> tokenBeamParameters_;
0047 };
0048 
0049 //---------------------------------------------------------------------------------------
0050 
0051 void WriteCTPPSBeamParameters::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0052   const auto& beamParam = iSetup.getData(tokenBeamParameters_);
0053   // Using "lumiid" as IOV
0054   const edm::LuminosityBlock& iLBlock = iEvent.getLuminosityBlock();
0055   edm::LuminosityBlockID lu(iLBlock.run(), iLBlock.id().luminosityBlock());
0056   cond::Time_t ilumi = (cond::Time_t)(lu.value());
0057   // cond::Time_t itime = (cond::Time_t)(iEvent.time().value()) ;  //  use this for timestamp
0058 
0059   edm::LogInfo("WriteCTPPSBeamParameters::analyze")
0060       << "cond::Time_t ilumi = " << ilumi << " = "
0061       << boost::posix_time::to_iso_extended_string(cond::time::to_boost(ilumi)) << "\n";
0062 
0063   // Write to database or sqlite file
0064   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0065   if (poolDbService.isAvailable())
0066     poolDbService->writeOneIOV(beamParam, ilumi, "CTPPSBeamParametersRcd");
0067   else
0068     throw std::runtime_error("PoolDBService required.");
0069 }
0070 
0071 //define this as a plug-in
0072 DEFINE_FWK_MODULE(WriteCTPPSBeamParameters);