Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-25 03:29:19

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/ESTransientHandle.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0009 #include "CondFormats/GeometryObjects/interface/HcalParameters.h"
0010 #include "DetectorDescription/Core/interface/DDCompactView.h"
0011 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0012 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0013 #include "Geometry/HcalCommonData/interface/HcalParametersFromDD.h"
0014 
0015 //#define EDM_ML_DEBUG
0016 
0017 class HcalParametersDBBuilder : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0018 public:
0019   HcalParametersDBBuilder(const edm::ParameterSet&);
0020 
0021   static void fillDescriptions(edm::ConfigurationDescriptions&);
0022 
0023   void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
0024   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
0025   void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
0026 
0027 private:
0028   bool fromDD4hep_;
0029   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4HepCompactViewToken_;
0030   edm::ESGetToken<DDCompactView, IdealGeometryRecord> compactViewToken_;
0031 };
0032 
0033 HcalParametersDBBuilder::HcalParametersDBBuilder(const edm::ParameterSet& ps)
0034     : fromDD4hep_(ps.getParameter<bool>("fromDD4hep")) {
0035 #ifdef EDM_ML_DEBUG
0036   edm::LogVerbatim("HCalGeom") << "HcalParametersDBBuilder::HcalParametersDBBuilder called with dd4hep: "
0037                                << fromDD4hep_;
0038 #endif
0039   dd4HepCompactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0040   compactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0041 }
0042 
0043 void HcalParametersDBBuilder::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0044   edm::ParameterSetDescription desc;
0045   desc.add<bool>("fromDD4hep", false);
0046   descriptions.add("HcalParametersWriter", desc);
0047 }
0048 
0049 void HcalParametersDBBuilder::beginRun(const edm::Run&, edm::EventSetup const& es) {
0050   HcalParameters php;
0051   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0052   if (!mydbservice.isAvailable()) {
0053     edm::LogError("HcalParametersDBBuilder") << "PoolDBOutputService unavailable";
0054     return;
0055   }
0056 
0057   HcalParametersFromDD builder;
0058 
0059   if (fromDD4hep_) {
0060 #ifdef EDM_ML_DEBUG
0061     edm::LogVerbatim("HCalGeom") << "HcalParametersDBBuilder::Try to access cms::DDCompactView";
0062 #endif
0063     auto cpv = es.getTransientHandle(dd4HepCompactViewToken_);
0064     builder.build((*cpv), php);
0065   } else {
0066 #ifdef EDM_ML_DEBUG
0067     edm::LogVerbatim("HCalGeom") << "HcalParametersDBBuilder::Try to access DDCompactView";
0068 #endif
0069     auto cpv = es.getTransientHandle(compactViewToken_);
0070     builder.build(&(*cpv), php);
0071   }
0072 
0073   if (mydbservice->isNewTagRequest("HcalParametersRcd")) {
0074     mydbservice->createOneIOV(php, mydbservice->beginOfTime(), "HcalParametersRcd");
0075   } else {
0076     edm::LogError("HcalParametersDBBuilder") << "HcalParameters and HcalParametersRcd Tag already present";
0077   }
0078 }
0079 
0080 DEFINE_FWK_MODULE(HcalParametersDBBuilder);