CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDDetector.cc
Go to the documentation of this file.
4 #include <DD4hep/Detector.h>
5 #include <DD4hep/DetectorTools.h>
6 #include <DD4hep/Volumes.h>
7 #include <XML/DocumentHandler.h>
8 #include <XML/XMLElements.h>
9 
10 #include <iostream>
11 
12 namespace cms {
13 
14  DDDetector::DDDetector(const std::string& tag, const std::string& fileName, bool bigXML) : m_tag(tag) {
15  //We do not want to use any previously created TGeoManager but we do want to reset after we are done.
16  auto oldGeoManager = gGeoManager;
17  gGeoManager = nullptr;
18  auto resetManager = [oldGeoManager](TGeoManager*) { gGeoManager = oldGeoManager; };
19  std::unique_ptr<TGeoManager, decltype(resetManager)> sentry(oldGeoManager, resetManager);
20 
21  std::string tagStr(m_tag);
22  bool makePayload = false;
23  if (tagStr == "make-payload") {
24  makePayload = true;
25  tagStr = "";
26  }
27  m_description = &dd4hep::Detector::getInstance(tagStr);
28  m_description->addExtension<cms::DDVectorsMap>(&m_vectors);
29  auto parsingContext = new cms::DDParsingContext(*m_description, makePayload); // Removed at end of constructor
30  m_description->addExtension<cms::DDParsingContext>(parsingContext);
31  m_description->addExtension<dd4hep::PartSelectionMap>(&m_partsels);
32  m_description->addExtension<dd4hep::SpecParRegistry>(&m_specpars);
33  m_description->setStdConditions("NTP");
34  edm::LogVerbatim("Geometry") << "DDDetector::ctor Setting DD4hep STD conditions to NTP";
35  if (bigXML)
36  processXML(fileName);
37  else
38  process(fileName);
39  if (makePayload == false) // context no longer needed if not making payloads
40  m_description->removeExtension<cms::DDParsingContext>();
41  }
42 
44  std::string name("DD4hep_CompactLoader");
45  const char* files[] = {fileName.c_str(), nullptr};
46  m_description->apply(name.c_str(), 2, (char**)files);
47  }
48 
50  edm::LogVerbatim("Geometry") << "DDDetector::processXML process string size " << xml.size() << " with max_size "
51  << xml.max_size();
52  edm::LogVerbatim("Geometry") << "DDDetector::processXML XML string contents = " << xml.substr(0, 800);
53  std::string name("DD4hep_XMLProcessor");
54  dd4hep::xml::DocumentHolder doc(dd4hep::xml::DocumentHandler().parse(xml.c_str(), xml.length()));
55 
56  char* args[] = {(char*)doc.root().ptr(), nullptr};
57  m_description->apply(name.c_str(), 1, (char**)args);
58  }
59 
62  return m_description->worldVolume();
63  }
64 
65  dd4hep::DetElement DDDetector::world() const {
67  return m_description->world();
68  }
69 
70  TGeoManager& DDDetector::manager() const {
72  return m_description->manager();
73  }
74 
75  dd4hep::DetElement DDDetector::findElement(const std::string& path) const {
77  return dd4hep::detail::tools::findElement(*m_description, path);
78  }
79 } // namespace cms
std::unordered_map< std::string, std::vector< double >> DDVectorsMap
Definition: DDNamespace.h:20
dd4hep::Detector * m_description
Definition: DDDetector.h:41
Log< level::Info, true > LogVerbatim
const std::string m_tag
Definition: DDDetector.h:45
DDDetector()=delete
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:75
assert(be >=bs)
dd4hep::DetElement world() const
Reference to the top-most (world) detector element.
Definition: DDDetector.cc:65
TGeoManager & manager() const
The geometry manager of this instance.
Definition: DDDetector.cc:70
dd4hep::PartSelectionMap m_partsels
Definition: DDDetector.h:43
dd4hep::Volume Volume
void process(const std::string &)
Definition: DDDetector.cc:43
dd4hep::SpecParRegistry m_specpars
Definition: DDDetector.h:44
dd4hep::Volume worldVolume() const
Handle to the world volume containing everything.
Definition: DDDetector.cc:60
void processXML(const std::string &)
Definition: DDDetector.cc:49
cms::DDVectorsMap m_vectors
Definition: DDDetector.h:42