23 xercesc::XMLPlatformUtils::Initialize();
29 xercesc::XercesDOMParser parser;
30 parser.setDoNamespaces(
false);
31 parser.setDoSchema(
false);
32 parser.setCreateEntityReferenceNodes(
false);
35 parser.parse(path.c_str());
36 }
catch (
const xercesc::XMLException& e) {
37 xercesc::XMLPlatformUtils::Terminate();
38 G4Exception(
"G4OCCTMaterialMapReader::ReadFile",
"G4OCCT_MatReader001", FatalException,
39 (
"XML error parsing '" + path +
"': " + Transcode(e.getMessage())).c_str());
41 }
catch (
const xercesc::DOMException& e) {
42 xercesc::XMLPlatformUtils::Terminate();
43 G4Exception(
"G4OCCTMaterialMapReader::ReadFile",
"G4OCCT_MatReader002", FatalException,
44 (
"DOM error parsing '" + path +
"': " + Transcode(e.getMessage())).c_str());
48 const xercesc::DOMDocument*
const doc = parser.getDocument();
50 xercesc::XMLPlatformUtils::Terminate();
51 G4Exception(
"G4OCCTMaterialMapReader::ReadFile",
"G4OCCT_MatReader003", FatalException,
52 (
"Cannot open document: " + path).c_str());
56 const xercesc::DOMElement*
const root = doc->getDocumentElement();
58 xercesc::XMLPlatformUtils::Terminate();
59 G4Exception(
"G4OCCTMaterialMapReader::ReadFile",
"G4OCCT_MatReader004", FatalException,
60 (
"Empty document: " + path).c_str());
64 const G4String rootTag = Transcode(root->getTagName());
65 if (rootTag !=
"materials") {
66 xercesc::XMLPlatformUtils::Terminate();
68 "G4OCCTMaterialMapReader::ReadFile",
"G4OCCT_MatReader005", FatalException,
69 (
"Root element must be <materials>, got <" + rootTag +
"> in '" + path +
"'").c_str());
75 for (xercesc::DOMNode* node = root->getFirstChild(); node !=
nullptr;
76 node = node->getNextSibling()) {
77 if (node->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
80 const auto* child =
dynamic_cast<const xercesc::DOMElement*
>(node);
84 const G4String tag = Transcode(child->getTagName());
85 if (tag ==
"isotope") {
87 }
else if (tag ==
"element") {
93 for (xercesc::DOMNode* node = root->getFirstChild(); node !=
nullptr;
94 node = node->getNextSibling()) {
95 if (node->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
98 const auto* child =
dynamic_cast<const xercesc::DOMElement*
>(node);
102 if (Transcode(child->getTagName()) !=
"material") {
110 const xercesc::DOMNamedNodeMap* attrs = child->getAttributes();
111 for (XMLSize_t i = 0; i < attrs->getLength(); ++i) {
112 const auto* attr =
dynamic_cast<const xercesc::DOMAttr*
>(attrs->item(i));
116 const G4String aName = Transcode(attr->getName());
117 const G4String aValue = Transcode(attr->getValue());
118 if (aName ==
"stepName") {
120 }
else if (aName ==
"geant4Name") {
122 }
else if (aName ==
"name") {
127 if (stepName.empty()) {
128 G4Exception(
"G4OCCTMaterialMapReader::ReadFile",
"G4OCCT_MatReader006", FatalException,
129 (
"<material> element in '" + path +
130 "' is missing the required 'stepName' "
136 G4Material* mat =
nullptr;
138 if (!geant4Name.empty()) {
140 mat = G4NistManager::Instance()->FindOrBuildMaterial(geant4Name);
142 G4Exception(
"G4OCCTMaterialMapReader::ReadFile",
"G4OCCT_MatReader007", FatalException,
143 (
"NIST material '" + geant4Name +
"' not found (stepName='" + stepName +
145 "Check the spelling against the Geant4 NIST material database.")
151 if (gdmlName.empty()) {
152 G4Exception(
"G4OCCTMaterialMapReader::ReadFile",
"G4OCCT_MatReader008", FatalException,
153 (
"Inline <material stepName=\"" + stepName +
"\"> in '" + path +
154 "' requires a 'name' attribute (used as the GDML material registry key).")
168 mat = G4Material::GetMaterial(GenerateName(gdmlName),
false);
169 if (mat ==
nullptr) {
170 mat = G4Material::GetMaterial(gdmlName,
false);
172 if (mat ==
nullptr) {
176 mat = GetMaterial(GenerateName(gdmlName));
177 if (mat ==
nullptr) {
178 mat = G4Material::GetMaterial(gdmlName,
false);
182 G4Exception(
"G4OCCTMaterialMapReader::ReadFile",
"G4OCCT_MatReader009", FatalException,
183 (
"Failed to create inline material '" + gdmlName +
"' (stepName='" +
184 stepName +
"') in '" + path +
185 "'. Check that density and composition are valid.")
191 result.
Add(stepName, mat);
195 xercesc::XMLPlatformUtils::Terminate();