File indexing completed on 2023-03-17 11:14:41
0001
0002 #include <memory>
0003 #include <string>
0004
0005
0006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0007 #include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h"
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ServiceRegistry/interface/Service.h"
0014 #include "MuonAnalysis/MomentumScaleCalibration/interface/BackgroundFunction.h"
0015 #include "MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h"
0016 #include "MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h"
0017
0018 class DBWriter : public edm::one::EDAnalyzer<> {
0019 public:
0020 explicit DBWriter(const edm::ParameterSet&);
0021 ~DBWriter() override = default;
0022
0023 private:
0024 void analyze(const edm::Event&, const edm::EventSetup&) override;
0025 std::unique_ptr<BaseFunction> corrector_;
0026 };
0027
0028 DBWriter::DBWriter(const edm::ParameterSet& ps) {
0029
0030 std::string type(ps.getUntrackedParameter<std::string>("Type"));
0031
0032 if (type == "scale")
0033 corrector_ =
0034 std::make_unique<MomentumScaleCorrector>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
0035 else if (type == "resolution")
0036 corrector_ = std::make_unique<ResolutionFunction>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
0037 else if (type == "background")
0038 corrector_ = std::make_unique<BackgroundFunction>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
0039 else {
0040 edm::LogPrint("DBWriter") << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'"
0041 << std::endl;
0042 exit(1);
0043 }
0044 }
0045
0046
0047 void DBWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0048 MuScleFitDBobject dbObject;
0049
0050 dbObject.identifiers = corrector_->identifiers();
0051 dbObject.parameters = corrector_->parameters();
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 edm::Service<cond::service::PoolDBOutputService> mydbservice;
0071 if (mydbservice.isAvailable()) {
0072 if (mydbservice->isNewTagRequest("MuScleFitDBobjectRcd")) {
0073 mydbservice->createOneIOV<MuScleFitDBobject>(dbObject, mydbservice->beginOfTime(), "MuScleFitDBobjectRcd");
0074 } else {
0075 mydbservice->appendOneIOV<MuScleFitDBobject>(dbObject, mydbservice->currentTime(), "MuScleFitDBobjectRcd");
0076 }
0077 } else {
0078 edm::LogError("DBWriter") << "Service is unavailable" << std::endl;
0079 }
0080 }
0081
0082
0083 DEFINE_FWK_MODULE(DBWriter);