46 : validate(true), check(false), inLoop(0), loopCount(0)
57 char* char_str = xercesc::XMLString::transcode(toTranscode);
59 xercesc::XMLString::release(&char_str);
91 std::stringstream stream;
93 nameOut = stream.str();
103 return sname.
remove(sname.find(
"0x"));
108 name.
remove(name.find(
"0x"));
122 G4cout <<
"Stripping off GDML names of materials, solids and volumes ..."
130 for (i=0; i<solids->size(); i++)
140 for (i=0; i<lvols->size(); i++)
150 for (i=0; i<pvols->size(); i++)
160 for (i=0; i<materials->size(); i++)
170 for (i=0; i<elements->size(); i++)
180 void(
G4GDMLRead::*func)(
const xercesc::DOMElement*
const))
187 const xercesc::DOMNamedNodeMap*
const attributes = element->getAttributes();
188 XMLSize_t attributeCount = attributes->getLength();
190 for (XMLSize_t attribute_index=0;
191 attribute_index<attributeCount;attribute_index++)
193 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
195 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
198 const xercesc::DOMAttr*
const attribute
199 =
dynamic_cast<xercesc::DOMAttr*
>(attribute_node);
202 G4Exception(
"G4GDMLRead::LoopRead()",
"InvalidRead",
209 if (attribute_name==
"for") { var = attribute_value; }
else
210 if (attribute_name==
"from") { from = attribute_value; }
else
211 if (attribute_name==
"to") { to = attribute_value; }
else
212 if (attribute_name==
"step") { step = attribute_value; }
217 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
223 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
232 if (!from.empty()) { _var = _from; }
236 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
239 if ((_from < _to) && (_step <= 0))
241 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
244 if ((_from > _to) && (_step >= 0))
246 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
255 (this->*func)(element);
261 if (!inLoop) { loopCount = 0; }
266 G4String error_msg =
"No handle to user-code for parsing extensions!";
278 G4cout <<
"G4GDML: Reading module '" << fileName <<
"'..." <<
G4endl;
282 G4cout <<
"G4GDML: Reading '" << fileName <<
"'..." <<
G4endl;
289 xercesc::XercesDOMParser* parser =
new xercesc::XercesDOMParser;
291 parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
292 parser->setValidationSchemaFullChecking(
true);
293 parser->setCreateEntityReferenceNodes(
false);
296 parser->setDoNamespaces(
true);
297 parser->setDoSchema(
true);
298 parser->setErrorHandler(handler);
300 try { parser->parse(fileName.c_str()); }
301 catch (
const xercesc::XMLException &
e)
303 catch (
const xercesc::DOMException &e)
306 xercesc::DOMDocument* doc = parser->getDocument();
310 G4String error_msg =
"Unable to open document: " + fileName;
315 xercesc::DOMElement* element = doc->getDocumentElement();
324 for (xercesc::DOMNode* iter = element->getFirstChild();
325 iter != 0; iter = iter->getNextSibling())
327 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
continue; }
329 const xercesc::DOMElement*
const child
330 =
dynamic_cast<xercesc::DOMElement*
>(iter);
339 if (tag==
"define") {
DefineRead(child); }
else
341 if (tag==
"solids") {
SolidsRead(child); }
else
342 if (tag==
"setup") {
SetupRead(child); }
else
347 G4String error_msg =
"Unknown tag in gdml: " + tag;
358 G4cout <<
"G4GDML: Reading module '" << fileName <<
"' done!" <<
G4endl;
362 G4cout <<
"G4GDML: Reading '" << fileName <<
"' done!" <<
G4endl;