Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:04

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/ServiceRegistry/interface/Service.h"
0006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0007 #include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
0008 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0009 #include "DetectorDescription/Core/interface/DDCompactView.h"
0010 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0011 #include "Geometry/TrackerGeometryBuilder/interface/TrackerParametersFromDD.h"
0012 
0013 class PTrackerParametersDBBuilder : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0014 public:
0015   PTrackerParametersDBBuilder(const edm::ParameterSet&);
0016 
0017   void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
0018   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
0019   void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
0020 
0021 private:
0022   bool fromDD4hep_;
0023   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4HepCompactViewToken_;
0024   edm::ESGetToken<DDCompactView, IdealGeometryRecord> compactViewToken_;
0025 };
0026 
0027 PTrackerParametersDBBuilder::PTrackerParametersDBBuilder(const edm::ParameterSet& iConfig) {
0028   fromDD4hep_ = iConfig.getParameter<bool>("fromDD4hep");
0029   dd4HepCompactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0030   compactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0031 }
0032 
0033 void PTrackerParametersDBBuilder::beginRun(const edm::Run&, edm::EventSetup const& es) {
0034   PTrackerParameters ptp;
0035   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0036   if (!mydbservice.isAvailable()) {
0037     edm::LogError("PTrackerParametersDBBuilder") << "PoolDBOutputService unavailable";
0038     return;
0039   }
0040 
0041   TrackerParametersFromDD builder;
0042 
0043   if (!fromDD4hep_) {
0044     auto cpv = es.getTransientHandle(compactViewToken_);
0045     builder.build(&(*cpv), ptp);
0046   } else {
0047     auto cpv = es.getTransientHandle(dd4HepCompactViewToken_);
0048     builder.build(&(*cpv), ptp);
0049   }
0050 
0051   if (mydbservice->isNewTagRequest("PTrackerParametersRcd")) {
0052     mydbservice->createOneIOV(ptp, mydbservice->beginOfTime(), "PTrackerParametersRcd");
0053   } else {
0054     edm::LogError("PTrackerParametersDBBuilder") << "PTrackerParameters and PTrackerParametersRcd Tag already present";
0055   }
0056 }
0057 
0058 DEFINE_FWK_MODULE(PTrackerParametersDBBuilder);