Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-06 04:13:42

0001 #include "DetectorDescription/Core/interface/DDCompactView.h"
0002 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0003 #include "FWCore/Framework/interface/ESProducer.h"
0004 #include "FWCore/Framework/interface/ESTransientHandle.h"
0005 #include "FWCore/Framework/interface/ModuleFactory.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0011 #include "Geometry/HGCalCommonData/interface/HGCalParametersFromDD.h"
0012 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0013 
0014 //#define EDM_ML_DEBUG
0015 
0016 class HGCalParametersESModule : public edm::ESProducer {
0017 public:
0018   HGCalParametersESModule(const edm::ParameterSet&);
0019 
0020   using ReturnType = std::unique_ptr<HGCalParameters>;
0021 
0022   static void fillDescriptions(edm::ConfigurationDescriptions&);
0023 
0024   ReturnType produce(const IdealGeometryRecord&);
0025 
0026 private:
0027   std::string name_, name2_, namew_, namec_, namet_, namex_;
0028   bool fromDD4hep_;
0029   edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvTokenDDD_;
0030   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> cpvTokenDD4hep_;
0031 };
0032 
0033 HGCalParametersESModule::HGCalParametersESModule(const edm::ParameterSet& iC) {
0034   name_ = iC.getParameter<std::string>("name");
0035   name2_ = iC.getParameter<std::string>("name2");
0036   namew_ = iC.getParameter<std::string>("nameW");
0037   namec_ = iC.getParameter<std::string>("nameC");
0038   namet_ = iC.getParameter<std::string>("nameT");
0039   namex_ = iC.getParameter<std::string>("nameX");
0040   fromDD4hep_ = iC.getParameter<bool>("fromDD4hep");
0041 #ifdef EDM_ML_DEBUG
0042   edm::LogVerbatim("HGCalGeom") << "HGCalParametersESModule for " << name_ << ":" << namew_ << ":" << namec_ << ":"
0043                                 << namet_ << " and fromDD4hep flag " << fromDD4hep_;
0044 #endif
0045   auto cc = setWhatProduced(this, namex_);
0046   if (fromDD4hep_)
0047     cpvTokenDD4hep_ = cc.consumesFrom<cms::DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0048   else
0049     cpvTokenDDD_ = cc.consumes<DDCompactView>(edm::ESInputTag());
0050 }
0051 
0052 void HGCalParametersESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0053   edm::ParameterSetDescription desc;
0054   desc.add<std::string>("name", "HGCalEESensitive");
0055   desc.add<std::string>("name2", "HGCalEE");
0056   desc.add<std::string>("nameW", "HGCalEEWafer");
0057   desc.add<std::string>("nameC", "HGCalEECell");
0058   desc.add<std::string>("nameT", "HGCal");
0059   desc.add<std::string>("nameX", "HGCalEESensitive");
0060   desc.add<bool>("fromDD4hep", false);
0061   descriptions.add("hgcalEEParametersInitialize", desc);
0062 }
0063 
0064 HGCalParametersESModule::ReturnType HGCalParametersESModule::produce(const IdealGeometryRecord& iRecord) {
0065 #ifdef EDM_ML_DEBUG
0066   edm::LogVerbatim("HGCalGeom") << "HGCalParametersESModule::produce(const IdealGeometryRecord& iRecord)";
0067 #endif
0068   auto ptp = std::make_unique<HGCalParameters>(name_);
0069   HGCalParametersFromDD builder;
0070   if (fromDD4hep_) {
0071 #ifdef EDM_ML_DEBUG
0072     edm::LogVerbatim("HGCalGeom") << "HGCalParametersESModule::Try to access cms::DDCompactView";
0073 #endif
0074     edm::ESTransientHandle<cms::DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDD4hep_);
0075     builder.build(cpv.product(), *ptp, name_, namew_, namec_, namet_, name2_);
0076   } else {
0077 #ifdef EDM_ML_DEBUG
0078     edm::LogVerbatim("HGCalGeom") << "HGCalParametersESModule::Try to access DDCompactView";
0079 #endif
0080     edm::ESTransientHandle<DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDDD_);
0081     builder.build(cpv.product(), *ptp, name_, namew_, namec_, namet_);
0082   }
0083   return ptp;
0084 }
0085 
0086 // define this as a plug-in
0087 DEFINE_FWK_EVENTSETUP_MODULE(HGCalParametersESModule);