File indexing completed on 2024-04-06 12:15:32
0001 #include "GeometryReaders/XMLIdealGeometryESSource/interface/XMLIdealGeometryESSource.h"
0002
0003 #include "FWCore/Concurrency/interface/SharedResourceNames.h"
0004
0005 #include "DetectorDescription/Parser/interface/DDLParser.h"
0006 #include "DetectorDescription/Core/interface/DDCompactView.h"
0007 #include "DetectorDescription/Core/interface/DDRoot.h"
0008
0009 #include "DetectorDescription/Core/interface/DDMaterial.h"
0010 #include "DetectorDescription/Core/interface/DDSolid.h"
0011 #include "DetectorDescription/Core/interface/DDSpecifics.h"
0012 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0013
0014 #include "DetectorDescription/Core/interface/Material.h"
0015 #include "DetectorDescription/Core/interface/Solid.h"
0016 #include "DetectorDescription/Core/interface/LogicalPart.h"
0017 #include "DetectorDescription/Core/interface/Specific.h"
0018
0019 #include "FWCore/ParameterSet/interface/FileInPath.h"
0020
0021 #include <memory>
0022
0023 XMLIdealGeometryESSource::XMLIdealGeometryESSource(const edm::ParameterSet &p)
0024 : rootNodeName_(p.getParameter<std::string>("rootNodeName")),
0025 userNS_(p.getUntrackedParameter<bool>("userControlledNamespace", false)),
0026 geoConfig_(p) {
0027 usesResources({{edm::ESSharedResourceNames::kDDGeometry}});
0028
0029 if (rootNodeName_.empty() || rootNodeName_ == "\\") {
0030 throw cms::Exception("DDException") << "XMLIdealGeometryESSource must have a root node name.";
0031 }
0032
0033 if (rootNodeName_ == "MagneticFieldVolumes:MAGF" || rootNodeName_ == "cmsMagneticField:MAGF") {
0034 setWhatProduced(
0035 this, &XMLIdealGeometryESSource::produceMagField, edm::es::Label(p.getParameter<std::string>("@module_label")));
0036 findingRecord<IdealMagneticFieldRecord>();
0037 } else {
0038 setWhatProduced(
0039 this, &XMLIdealGeometryESSource::produceGeom, edm::es::Label(p.getParameter<std::string>("@module_label")));
0040 findingRecord<IdealGeometryRecord>();
0041 }
0042 }
0043
0044 XMLIdealGeometryESSource::~XMLIdealGeometryESSource() {}
0045
0046 std::unique_ptr<DDCompactView> XMLIdealGeometryESSource::produceGeom(const IdealGeometryRecord &) { return produce(); }
0047
0048 std::unique_ptr<DDCompactView> XMLIdealGeometryESSource::produceMagField(const IdealMagneticFieldRecord &) {
0049 return produce();
0050 }
0051
0052 std::unique_ptr<DDCompactView> XMLIdealGeometryESSource::produce() {
0053 DDName ddName(rootNodeName_);
0054 DDLogicalPart rootNode(ddName);
0055 DDRootDef::instance().set(rootNode);
0056 std::unique_ptr<DDCompactView> returnValue(new DDCompactView(rootNode));
0057 DDLParser parser(*returnValue);
0058 parser.getDDLSAX2FileHandler()->setUserNS(userNS_);
0059 int result2 = parser.parse(geoConfig_);
0060 if (result2 != 0)
0061 throw cms::Exception("DDException") << "DDD-Parser: parsing failed!";
0062
0063
0064
0065 if (!rootNode.isValid()) {
0066 throw cms::Exception("Geometry") << "There is no valid node named \"" << rootNodeName_ << "\"";
0067 }
0068 returnValue->lockdown();
0069 return returnValue;
0070 }
0071
0072 void XMLIdealGeometryESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0073 const edm::IOVSyncValue &iosv,
0074 edm::ValidityInterval &oValidity) {
0075 edm::ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime());
0076 oValidity = infinity;
0077 }
0078
0079 #include "FWCore/Framework/interface/SourceFactory.h"
0080
0081 DEFINE_FWK_EVENTSETUP_SOURCE(XMLIdealGeometryESSource);