CMS 3D CMS Logo

DDDetector.cc
Go to the documentation of this file.
4 #include <DD4hep/Detector.h>
5 #include <DD4hep/DetectorTools.h>
6 #include <DD4hep/Printout.h>
7 #include <DD4hep/Volumes.h>
8 #include <XML/DocumentHandler.h>
9 #include <XML/XMLElements.h>
10 
11 #include <iostream>
12 
13 namespace cms {
14 
15  DDDetector::DDDetector(const std::string& tag, const std::string& fileName, bool bigXML) : m_tag(tag) {
16  //We do not want to use any previously created TGeoManager but we do want to reset after we are done.
17  auto oldGeoManager = gGeoManager;
18  gGeoManager = nullptr;
19  auto resetManager = [oldGeoManager](TGeoManager*) { gGeoManager = oldGeoManager; };
20  std::unique_ptr<TGeoManager, decltype(resetManager)> sentry(oldGeoManager, resetManager);
21 
22  std::string tagStr(m_tag);
23  bool makePayload = false;
24  if (tagStr == "make-payload") {
25  makePayload = true;
26  tagStr = "";
27  }
28  // Set DD4hep message level to ERROR. The default is INFO,
29  // but those messages are not necessary for general use.
30  dd4hep::setPrintLevel(dd4hep::ERROR);
31 
32  m_description = &dd4hep::Detector::getInstance(tagStr);
33  m_description->addExtension<cms::DDVectorsMap>(&m_vectors);
34  //only validate if using XML
35  auto parsingContext =
36  new cms::DDParsingContext(*m_description, makePayload, not bigXML); // Removed at end of constructor
37  m_description->addExtension<cms::DDParsingContext>(parsingContext);
38  m_description->addExtension<dd4hep::PartSelectionMap>(&m_partsels);
39  m_description->addExtension<dd4hep::SpecParRegistry>(&m_specpars);
40  m_description->setStdConditions("NTP");
41  edm::LogVerbatim("Geometry") << "DDDetector::ctor Setting DD4hep STD conditions to NTP";
42  if (bigXML)
44  else
46  if (makePayload == false) // context no longer needed if not making payloads
47  m_description->removeExtension<cms::DDParsingContext>();
48  }
49 
51  std::string name("DD4hep_CompactLoader");
52  const char* files[] = {fileName.c_str(), nullptr};
53  m_description->apply(name.c_str(), 2, (char**)files);
54  }
55 
57  edm::LogVerbatim("Geometry") << "DDDetector::processXML process string size " << xml.size() << " with max_size "
58  << xml.max_size();
59  edm::LogVerbatim("Geometry") << "DDDetector::processXML XML string contents = " << xml.substr(0, 800);
60  std::string name("DD4hep_XMLProcessor");
61  dd4hep::xml::DocumentHolder doc(dd4hep::xml::DocumentHandler().parse(xml.c_str(), xml.length()));
62 
63  char* args[] = {(char*)doc.root().ptr(), nullptr};
64  m_description->apply(name.c_str(), 1, (char**)args);
65  }
66 
69  return m_description->worldVolume();
70  }
71 
72  dd4hep::DetElement DDDetector::world() const {
74  return m_description->world();
75  }
76 
77  TGeoManager& DDDetector::manager() const {
79  return m_description->manager();
80  }
81 
82  dd4hep::DetElement DDDetector::findElement(const std::string& path) const {
84  return dd4hep::detail::tools::findElement(*m_description, path);
85  }
86 } // namespace cms
dd4hep::Detector * m_description
Definition: DDDetector.h:41
Log< level::Info, true > LogVerbatim
vector< string > parse(string line, const string &delimiter)
const std::string m_tag
Definition: DDDetector.h:45
TGeoManager & manager() const
The geometry manager of this instance.
Definition: DDDetector.cc:77
DDDetector()=delete
assert(be >=bs)
std::unordered_map< std::string, std::vector< double > > DDVectorsMap
Definition: DDNamespace.h:20
dd4hep::PartSelectionMap m_partsels
Definition: DDDetector.h:43
dd4hep::Volume Volume
Namespace of DDCMS conversion namespace.
void process(const std::string &)
Definition: DDDetector.cc:50
dd4hep::SpecParRegistry m_specpars
Definition: DDDetector.h:44
dd4hep::Volume worldVolume() const
Handle to the world volume containing everything.
Definition: DDDetector.cc:67
void processXML(const std::string &)
Definition: DDDetector.cc:56
dd4hep::DetElement findElement(const std::string &) const
Find DetElement as child of the top level volume by it&#39;s absolute path.
Definition: DDDetector.cc:82
cms::DDVectorsMap m_vectors
Definition: DDDetector.h:42
static const int ERROR
dd4hep::DetElement world() const
Reference to the top-most (world) detector element.
Definition: DDDetector.cc:72