Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:19:03

0001 #include "FWCore/Framework/interface/ModuleFactory.h"
0002 #include "FWCore/Framework/interface/ESProducer.h"
0003 
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/ESTransientHandle.h"
0006 
0007 #include "FWCore/Concurrency/interface/SharedResourceNames.h"
0008 
0009 #include "DetectorDescription/Core/interface/DDCompactView.h"
0010 #include "DetectorDescription/Core/interface/DDRoot.h"
0011 #include "DetectorDescription/Parser/interface/DDLParser.h"
0012 #include "CondFormats/Common/interface/FileBlob.h"
0013 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0014 
0015 #include "DetectorDescription/Core/interface/DDMaterial.h"
0016 #include "DetectorDescription/Core/interface/DDSolid.h"
0017 #include "DetectorDescription/Core/interface/DDSpecifics.h"
0018 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0019 
0020 #include "DetectorDescription/Core/interface/Material.h"
0021 #include "DetectorDescription/Core/interface/Solid.h"
0022 #include "DetectorDescription/Core/interface/LogicalPart.h"
0023 #include "DetectorDescription/Core/interface/Specific.h"
0024 
0025 #include <memory>
0026 
0027 class XMLIdealMagneticFieldGeometryESProducer : public edm::ESProducer {
0028 public:
0029   XMLIdealMagneticFieldGeometryESProducer(const edm::ParameterSet&);
0030   ~XMLIdealMagneticFieldGeometryESProducer() override;
0031 
0032   typedef std::unique_ptr<DDCompactView> ReturnType;
0033 
0034   ReturnType produce(const IdealMagneticFieldRecord&);
0035 
0036 private:
0037   std::string rootDDName_;  // this must be the form namespace:name
0038   std::string label_;
0039   edm::ESGetToken<FileBlob, MFGeometryFileRcd> geomToken_;
0040 
0041   DDI::Store<DDName, DDI::Material*> matStore_;
0042   DDI::Store<DDName, DDI::Solid*> solidStore_;
0043   DDI::Store<DDName, DDI::LogicalPart*> lpStore_;
0044   DDI::Store<DDName, DDI::Specific*> specStore_;
0045   DDI::Store<DDName, DDRotationMatrix*> rotStore_;
0046 };
0047 
0048 XMLIdealMagneticFieldGeometryESProducer::XMLIdealMagneticFieldGeometryESProducer(const edm::ParameterSet& iConfig)
0049     : rootDDName_(iConfig.getParameter<std::string>("rootDDName")), label_(iConfig.getParameter<std::string>("label")) {
0050   usesResources({{edm::ESSharedResourceNames::kDDGeometry}});
0051 
0052   auto cc = setWhatProduced(this);
0053   geomToken_ = cc.consumesFrom<FileBlob, MFGeometryFileRcd>(edm::ESInputTag("", label_));
0054 }
0055 
0056 XMLIdealMagneticFieldGeometryESProducer::~XMLIdealMagneticFieldGeometryESProducer(void) {}
0057 
0058 XMLIdealMagneticFieldGeometryESProducer::ReturnType XMLIdealMagneticFieldGeometryESProducer::produce(
0059     const IdealMagneticFieldRecord& iRecord) {
0060   using namespace edm::es;
0061 
0062   edm::ESTransientHandle<FileBlob> gdd = iRecord.getTransientHandle(geomToken_);
0063 
0064   DDName ddName(rootDDName_);
0065   DDLogicalPart rootNode(ddName);
0066   DDRootDef::instance().set(rootNode);
0067   ReturnType returnValue(new DDCompactView(rootNode));
0068   DDLParser parser(*returnValue);
0069   parser.getDDLSAX2FileHandler()->setUserNS(true);
0070   parser.clearFiles();
0071 
0072   std::unique_ptr<std::vector<unsigned char> > tb = (*gdd).getUncompressedBlob();
0073 
0074   parser.parse(*tb, tb->size());
0075 
0076   returnValue->lockdown();
0077 
0078   return returnValue;
0079 }
0080 
0081 DEFINE_FWK_EVENTSETUP_MODULE(XMLIdealMagneticFieldGeometryESProducer);