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/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 #include "FWCore/ServiceRegistry/interface/Service.h"
0009 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0010 #include "CondFormats/GeometryObjects/interface/PHGCalParameters.h"
0011 #include "DetectorDescription/Core/interface/DDCompactView.h"
0012 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0013 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0014 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0015 #include "Geometry/HGCalCommonData/interface/HGCalParametersFromDD.h"
0016 
0017 //#define EDM_ML_DEBUG
0018 
0019 class PHGCalParametersDBBuilder : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0020 public:
0021   PHGCalParametersDBBuilder(const edm::ParameterSet&);
0022 
0023   static void fillDescriptions(edm::ConfigurationDescriptions&);
0024 
0025   void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
0026   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
0027   void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
0028 
0029 private:
0030   void swapParameters(HGCalParameters*, PHGCalParameters*);
0031 
0032   std::string name_, name2_, namew_, namec_, namet_;
0033   bool fromDD4hep_;
0034   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4HepCompactViewToken_;
0035   edm::ESGetToken<DDCompactView, IdealGeometryRecord> compactViewToken_;
0036 };
0037 
0038 PHGCalParametersDBBuilder::PHGCalParametersDBBuilder(const edm::ParameterSet& iC) {
0039   name_ = iC.getParameter<std::string>("name");
0040   name2_ = iC.getParameter<std::string>("name2");
0041   namew_ = iC.getParameter<std::string>("nameW");
0042   namec_ = iC.getParameter<std::string>("nameC");
0043   namet_ = iC.getParameter<std::string>("nameT");
0044   fromDD4hep_ = iC.getParameter<bool>("fromDD4hep");
0045   dd4HepCompactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0046   compactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0047 
0048 #ifdef EDM_ML_DEBUG
0049   edm::LogVerbatim("HGCalGeom") << "HGCalParametersESModule for " << name_ << ":" << name2_ << ":" << namew_ << ":"
0050                                 << namec_ << ":" << namet_ << " and fromDD4hep flag " << fromDD4hep_;
0051 #endif
0052 }
0053 
0054 void PHGCalParametersDBBuilder::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0055   edm::ParameterSetDescription desc;
0056   desc.add<std::string>("name", "HGCalEESensitive");
0057   desc.add<std::string>("name2", "HGCalEE");
0058   desc.add<std::string>("nameW", "HGCalEEWafer");
0059   desc.add<std::string>("nameC", "HGCalEECell");
0060   desc.add<std::string>("nameT", "HGCal");
0061   desc.add<bool>("fromDD4hep", false);
0062   descriptions.add("HGCalEEParametersWriter", desc);
0063 }
0064 
0065 void PHGCalParametersDBBuilder::beginRun(const edm::Run&, edm::EventSetup const& es) {
0066   PHGCalParameters phgp;
0067   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0068   if (!mydbservice.isAvailable()) {
0069     edm::LogError("PHGCalParametersDBBuilder") << "PoolDBOutputService unavailable";
0070     return;
0071   }
0072 
0073   HGCalParameters* ptp = new HGCalParameters(name_);
0074   HGCalParametersFromDD builder;
0075   if (fromDD4hep_) {
0076 #ifdef EDM_ML_DEBUG
0077     edm::LogVerbatim("HGCalGeom") << "PHGCalParametersDBBuilder::Try to access cm::DDCompactView";
0078 #endif
0079     auto cpv = es.getTransientHandle(dd4HepCompactViewToken_);
0080     builder.build(cpv.product(), *ptp, name_, namew_, namec_, namet_, name2_);
0081   } else {
0082 #ifdef EDM_ML_DEBUG
0083     edm::LogVerbatim("HGCalGeom") << "PHGCalParametersDBBuilder::Try to access DDCompactView";
0084 #endif
0085     auto cpv = es.getTransientHandle(compactViewToken_);
0086     builder.build(cpv.product(), *ptp, name_, namew_, namec_, namet_);
0087   }
0088   swapParameters(ptp, &phgp);
0089   delete ptp;
0090 
0091   if (mydbservice->isNewTagRequest("PHGCalParametersRcd")) {
0092     mydbservice->createOneIOV(phgp, mydbservice->beginOfTime(), "PHGCalParametersRcd");
0093   } else {
0094     edm::LogError("PHGCalParametersDBBuilder") << "PHGCalParameters and PHGCalParametersRcd Tag already present";
0095   }
0096 }
0097 
0098 void PHGCalParametersDBBuilder::swapParameters(HGCalParameters* ptp, PHGCalParameters* phgp) {
0099   phgp->name_ = ptp->name_;
0100   phgp->cellSize_.swap(ptp->cellSize_);
0101   phgp->moduleBlS_.swap(ptp->moduleBlS_);
0102   phgp->moduleTlS_.swap(ptp->moduleTlS_);
0103   phgp->moduleHS_.swap(ptp->moduleHS_);
0104   phgp->moduleDzS_.swap(ptp->moduleDzS_);
0105   phgp->moduleAlphaS_.swap(ptp->moduleAlphaS_);
0106   phgp->moduleCellS_.swap(ptp->moduleCellS_);
0107   phgp->moduleBlR_.swap(ptp->moduleBlR_);
0108   phgp->moduleTlR_.swap(ptp->moduleTlR_);
0109   phgp->moduleHR_.swap(ptp->moduleHR_);
0110   phgp->moduleDzR_.swap(ptp->moduleDzR_);
0111   phgp->moduleAlphaR_.swap(ptp->moduleAlphaR_);
0112   phgp->moduleCellR_.swap(ptp->moduleCellR_);
0113   phgp->trformTranX_.swap(ptp->trformTranX_);
0114   phgp->trformTranY_.swap(ptp->trformTranY_);
0115   phgp->trformTranZ_.swap(ptp->trformTranZ_);
0116   phgp->trformRotXX_.swap(ptp->trformRotXX_);
0117   phgp->trformRotYX_.swap(ptp->trformRotYX_);
0118   phgp->trformRotZX_.swap(ptp->trformRotZX_);
0119   phgp->trformRotXY_.swap(ptp->trformRotXY_);
0120   phgp->trformRotYY_.swap(ptp->trformRotYY_);
0121   phgp->trformRotZY_.swap(ptp->trformRotZY_);
0122   phgp->trformRotXZ_.swap(ptp->trformRotXZ_);
0123   phgp->trformRotYZ_.swap(ptp->trformRotYZ_);
0124   phgp->trformRotZZ_.swap(ptp->trformRotZZ_);
0125   phgp->zLayerHex_.swap(ptp->zLayerHex_);
0126   phgp->rMinLayHex_.swap(ptp->rMinLayHex_);
0127   phgp->rMaxLayHex_.swap(ptp->rMaxLayHex_);
0128   phgp->waferPosX_.swap(ptp->waferPosX_);
0129   phgp->waferPosY_.swap(ptp->waferPosY_);
0130   phgp->cellFineX_.swap(ptp->cellFineX_);
0131   phgp->cellFineY_.swap(ptp->cellFineY_);
0132   phgp->cellCoarseX_.swap(ptp->cellCoarseX_);
0133   phgp->cellCoarseY_.swap(ptp->cellCoarseY_);
0134   phgp->boundR_.swap(ptp->boundR_);
0135   phgp->moduleLayS_.swap(ptp->moduleLayS_);
0136   phgp->moduleLayR_.swap(ptp->moduleLayR_);
0137   phgp->layer_.swap(ptp->layer_);
0138   phgp->layerIndex_.swap(ptp->layerIndex_);
0139   phgp->layerGroup_.swap(ptp->layerGroup_);
0140   phgp->cellFactor_.swap(ptp->cellFactor_);
0141   phgp->depth_.swap(ptp->depth_);
0142   phgp->depthIndex_.swap(ptp->depthIndex_);
0143   phgp->depthLayerF_.swap(ptp->depthLayerF_);
0144   phgp->waferCopy_.swap(ptp->waferCopy_);
0145   phgp->waferTypeL_.swap(ptp->waferTypeL_);
0146   phgp->waferTypeT_.swap(ptp->waferTypeT_);
0147   phgp->layerGroupM_.swap(ptp->layerGroupM_);
0148   phgp->layerGroupO_.swap(ptp->layerGroupO_);
0149   phgp->trformIndex_.swap(ptp->trformIndex_);
0150   phgp->slopeMin_.swap(ptp->slopeMin_);
0151   phgp->waferR_ = ptp->waferR_;
0152   phgp->nCells_ = ptp->nCells_;
0153   phgp->nSectors_ = ptp->nSectors_;
0154   phgp->mode_ = ptp->mode_;
0155 }
0156 
0157 DEFINE_FWK_MODULE(PHGCalParametersDBBuilder);