Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:18

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/Framework/interface/ESHandle.h"
0003 #include "FWCore/Framework/interface/ESTransientHandle.h"
0004 #include "FWCore/Framework/interface/ModuleFactory.h"
0005 #include "FWCore/Concurrency/interface/SharedResourceNames.h"
0006 #include "DetectorDescription/Core/interface/DDCompactView.h"
0007 #include "DetectorDescription/Core/interface/DDRoot.h"
0008 #include "DetectorDescription/Parser/interface/DDLParser.h"
0009 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0010 #include "Geometry/Records/interface/GeometryFileRcd.h"
0011 #include "CondFormats/Common/interface/FileBlob.h"
0012 
0013 #include <memory>
0014 
0015 class XMLIdealGeometryESProducer : public edm::ESProducer {
0016 public:
0017   XMLIdealGeometryESProducer(const edm::ParameterSet&);
0018 
0019   using ReturnType = std::unique_ptr<DDCompactView>;
0020 
0021   ReturnType produce(const IdealGeometryRecord&);
0022 
0023   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0024 
0025 private:
0026   const std::string rootDDName_;  // this must be the form namespace:name
0027   const edm::ESGetToken<FileBlob, GeometryFileRcd> blobToken_;
0028 };
0029 
0030 XMLIdealGeometryESProducer::XMLIdealGeometryESProducer(const edm::ParameterSet& iConfig)
0031     : rootDDName_(iConfig.getParameter<std::string>("rootDDName")),
0032       blobToken_(setWhatProduced(this).consumes(edm::ESInputTag("", iConfig.getParameter<std::string>("label")))) {
0033   usesResources({{edm::ESSharedResourceNames::kDDGeometry}});
0034 }
0035 
0036 XMLIdealGeometryESProducer::ReturnType XMLIdealGeometryESProducer::produce(const IdealGeometryRecord& iRecord) {
0037   edm::ESTransientHandle<FileBlob> gdd = iRecord.getTransientHandle(blobToken_);
0038   auto cpv = std::make_unique<DDCompactView>(DDName(rootDDName_));
0039   DDLParser parser(*cpv);
0040   parser.getDDLSAX2FileHandler()->setUserNS(true);
0041   parser.clearFiles();
0042 
0043   std::unique_ptr<std::vector<unsigned char> > tb = (*gdd).getUncompressedBlob();
0044 
0045   parser.parse(*tb, tb->size());
0046 
0047   cpv->lockdown();
0048 
0049   return cpv;
0050 }
0051 
0052 void XMLIdealGeometryESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0053   edm::ParameterSetDescription desc;
0054   desc.add<std::string>("rootDDName")->setComment("The value must be of the form 'namespace:name'");
0055   desc.add<std::string>("label")->setComment("product label used to get the FileBlob");
0056 
0057   descriptions.addDefault(desc);
0058 }
0059 
0060 //define this as a plug-in
0061 DEFINE_FWK_EVENTSETUP_MODULE(XMLIdealGeometryESProducer);