File indexing completed on 2024-04-06 12:05:29
0001 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0002 #include "DetectorDescription/DDCMS/interface/DDParsingContext.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include <DD4hep/Detector.h>
0005 #include <DD4hep/DetectorTools.h>
0006 #include <DD4hep/Printout.h>
0007 #include <DD4hep/Volumes.h>
0008 #include <XML/DocumentHandler.h>
0009 #include <XML/XMLElements.h>
0010
0011 #include <iostream>
0012
0013 namespace cms {
0014
0015 DDDetector::DDDetector(const std::string& tag, const std::string& fileName, bool bigXML) : m_tag(tag) {
0016
0017 auto oldGeoManager = gGeoManager;
0018 gGeoManager = nullptr;
0019 auto resetManager = [oldGeoManager](TGeoManager*) { gGeoManager = oldGeoManager; };
0020 std::unique_ptr<TGeoManager, decltype(resetManager)> sentry(oldGeoManager, resetManager);
0021
0022 std::string tagStr(m_tag);
0023 bool makePayload = false;
0024 if (tagStr == "make-payload") {
0025 makePayload = true;
0026 tagStr = "";
0027 }
0028
0029
0030 dd4hep::setPrintLevel(dd4hep::ERROR);
0031
0032 m_description = &dd4hep::Detector::getInstance(tagStr);
0033 m_description->addExtension<cms::DDVectorsMap>(&m_vectors);
0034
0035 auto parsingContext =
0036 new cms::DDParsingContext(*m_description, makePayload, not bigXML);
0037 m_description->addExtension<cms::DDParsingContext>(parsingContext);
0038 m_description->addExtension<dd4hep::PartSelectionMap>(&m_partsels);
0039 m_description->addExtension<dd4hep::SpecParRegistry>(&m_specpars);
0040 m_description->setStdConditions("NTP");
0041 edm::LogVerbatim("Geometry") << "DDDetector::ctor Setting DD4hep STD conditions to NTP";
0042 if (bigXML)
0043 processXML(fileName);
0044 else
0045 process(fileName);
0046 if (makePayload == false)
0047 m_description->removeExtension<cms::DDParsingContext>();
0048 }
0049
0050 void DDDetector::process(const std::string& fileName) {
0051 std::string name("DD4hep_CompactLoader");
0052 const char* files[] = {fileName.c_str(), nullptr};
0053 m_description->apply(name.c_str(), 2, (char**)files);
0054 }
0055
0056 void DDDetector::processXML(const std::string& xml) {
0057 edm::LogVerbatim("Geometry") << "DDDetector::processXML process string size " << xml.size() << " with max_size "
0058 << xml.max_size();
0059 edm::LogVerbatim("Geometry") << "DDDetector::processXML XML string contents = " << xml.substr(0, 800);
0060 std::string name("DD4hep_XMLProcessor");
0061 dd4hep::xml::DocumentHolder doc(dd4hep::xml::DocumentHandler().parse(xml.c_str(), xml.length()));
0062
0063 char* args[] = {(char*)doc.root().ptr(), nullptr};
0064 m_description->apply(name.c_str(), 1, (char**)args);
0065 }
0066
0067 dd4hep::Volume DDDetector::worldVolume() const {
0068 assert(m_description);
0069 return m_description->worldVolume();
0070 }
0071
0072 dd4hep::DetElement DDDetector::world() const {
0073 assert(m_description);
0074 return m_description->world();
0075 }
0076
0077 TGeoManager& DDDetector::manager() const {
0078 assert(m_description);
0079 return m_description->manager();
0080 }
0081
0082 dd4hep::DetElement DDDetector::findElement(const std::string& path) const {
0083 assert(m_description);
0084 return dd4hep::detail::tools::findElement(*m_description, path);
0085 }
0086 }