File indexing completed on 2024-04-06 12:03:07
0001 #include <sys/types.h>
0002 #include <sys/stat.h>
0003 #include <unistd.h>
0004
0005 #include <cassert>
0006 #include <fstream>
0007 #include <memory>
0008
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016
0017 #include "CondFormats/HcalObjects/interface/OOTPileupCorrectionBuffer.h"
0018 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0019
0020
0021
0022
0023 class BufferedBoostIODBWriter : public edm::one::EDAnalyzer<> {
0024 public:
0025 explicit BufferedBoostIODBWriter(const edm::ParameterSet&);
0026 ~BufferedBoostIODBWriter() override {}
0027
0028 BufferedBoostIODBWriter() = delete;
0029 BufferedBoostIODBWriter(const BufferedBoostIODBWriter&) = delete;
0030 BufferedBoostIODBWriter& operator=(const BufferedBoostIODBWriter&) = delete;
0031
0032 private:
0033 void analyze(const edm::Event&, const edm::EventSetup&) override;
0034
0035 std::string inputFile;
0036 std::string record;
0037 };
0038
0039 BufferedBoostIODBWriter::BufferedBoostIODBWriter(const edm::ParameterSet& ps)
0040 : inputFile(ps.getParameter<std::string>("inputFile")), record(ps.getParameter<std::string>("record")) {}
0041
0042 void BufferedBoostIODBWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0043 std::unique_ptr<OOTPileupCorrectionBuffer> fcp;
0044
0045 {
0046 std::ifstream input(inputFile.c_str(), std::ios_base::binary);
0047 if (!input.is_open())
0048 throw cms::Exception("InvalidArgument") << "Failed to open file \"" << inputFile << '"' << std::endl;
0049
0050 struct stat st;
0051 if (stat(inputFile.c_str(), &st))
0052 throw cms::Exception("SystemError") << "Failed to stat file \"" << inputFile << '"' << std::endl;
0053
0054 const std::size_t len = st.st_size;
0055 fcp = std::make_unique<OOTPileupCorrectionBuffer>(len);
0056 assert(fcp->length() == len);
0057 if (len)
0058 input.read(fcp->getBuffer(), len);
0059 if (input.fail())
0060 throw cms::Exception("SystemError")
0061 << "Input stream failure while reading file \"" << inputFile << '"' << std::endl;
0062 }
0063
0064 edm::Service<cond::service::PoolDBOutputService> poolDbService;
0065 if (poolDbService.isAvailable())
0066 poolDbService->writeOneIOV(*fcp, poolDbService->currentTime(), record);
0067 else
0068 throw cms::Exception("ConfigurationError") << "PoolDBOutputService is not available, "
0069 << "please configure it properly" << std::endl;
0070 }
0071
0072 DEFINE_FWK_MODULE(BufferedBoostIODBWriter);