45 : validate(
true), check(
false), dostrip(
true), inLoop(0), loopCount(0)
57 char* char_str = xercesc::XMLString::transcode(toTranscode);
59 xercesc::XMLString::release(&char_str);
88 std::stringstream stream;
90 nameOut = stream.str();
100 return sname.
remove(sname.find(
"0x"));
105 name.
remove(name.find(
"0x"));
119 G4cout <<
"Stripping off GDML names of materials, solids and volumes ..."
127 for (i=0; i<solids->size(); ++i)
137 for (i=0; i<lvols->size(); ++i)
147 for (i=0; i<pvols->size(); ++i)
157 for (i=0; i<materials->size(); ++i)
167 for (i=0; i<elements->size(); ++i)
184 const xercesc::DOMNamedNodeMap*
const attributes = element->getAttributes();
185 XMLSize_t attributeCount = attributes->getLength();
187 for (XMLSize_t attribute_index=0;
188 attribute_index<attributeCount;attribute_index++)
190 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
192 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
195 const xercesc::DOMAttr*
const attribute
196 =
dynamic_cast<xercesc::DOMAttr*
>(attribute_node);
199 G4Exception(
"G4GDMLRead::LoopRead()",
"InvalidRead",
206 if (attribute_name==
"for") { var = attribute_value; }
else
207 if (attribute_name==
"from") { from = attribute_value; }
else
208 if (attribute_name==
"to") { to = attribute_value; }
else
209 if (attribute_name==
"step") { step = attribute_value; }
214 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
220 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
229 if (!from.empty()) { _var = _from; }
231 if ((_from < _to) && (_step <= 0))
233 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
236 if ((_from > _to) && (_step >= 0))
238 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
247 (this->*
func)(element);
262 const xercesc::DOMNamedNodeMap*
const attributes
263 = auxiliaryElement->getAttributes();
264 XMLSize_t attributeCount = attributes->getLength();
266 for (XMLSize_t attribute_index=0;
267 attribute_index<attributeCount; attribute_index++)
269 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
271 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
274 const xercesc::DOMAttr*
const attribute
275 =
dynamic_cast<xercesc::DOMAttr*
>(attribute_node);
285 if (attName==
"auxtype") { auxstruct.
type = attValue; }
else
286 if (attName==
"auxvalue") { auxstruct.
value = attValue; }
else
287 if (attName==
"auxunit") { auxstruct.
unit = attValue; }
290 for (xercesc::DOMNode* iter = auxiliaryElement->getFirstChild();
291 iter != 0; iter = iter->getNextSibling())
293 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
continue; }
295 const xercesc::DOMElement*
const child
296 =
dynamic_cast<xercesc::DOMElement*
>(iter);
305 if (tag==
"auxiliary")
312 if (auxList) { auxstruct.
auxList = auxList; }
322 for (xercesc::DOMNode* iter = userinfoElement->getFirstChild();
323 iter != 0; iter = iter->getNextSibling())
325 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
continue; }
327 const xercesc::DOMElement*
const child
328 =
dynamic_cast<xercesc::DOMElement*
>(iter);
337 if (tag==
"auxiliary")
343 G4String error_msg =
"Unknown tag in structure: " + tag;
352 G4String error_msg =
"No handle to user-code for parsing extensions!";
366 G4cout <<
"G4GDML: Reading module '" << fileName <<
"'..." <<
G4endl;
370 G4cout <<
"G4GDML: Reading '" << fileName <<
"'..." <<
G4endl;
377 xercesc::XercesDOMParser*
parser =
new xercesc::XercesDOMParser;
381 parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
383 parser->setValidationSchemaFullChecking(
validate);
384 parser->setCreateEntityReferenceNodes(
false);
387 parser->setDoNamespaces(
true);
389 parser->setErrorHandler(handler);
391 try { parser->parse(fileName.c_str()); }
392 catch (
const xercesc::XMLException &
e)
394 catch (
const xercesc::DOMException &e)
397 xercesc::DOMDocument* doc = parser->getDocument();
401 G4String error_msg =
"Unable to open document: " + fileName;
406 xercesc::DOMElement* element = doc->getDocumentElement();
411 message <<
"ERROR - Empty document or unable to validate schema!" <<
G4endl
412 <<
" Check Internet connection is ON in case of schema"
414 <<
" validation enabled and location defined as URL in"
416 <<
" the GDML file - " << fileName <<
" - being imported!"
418 <<
" Otherwise, verify GDML schema server is reachable!";
423 for (xercesc::DOMNode* iter = element->getFirstChild();
424 iter != 0; iter = iter->getNextSibling())
426 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
continue; }
428 const xercesc::DOMElement*
const child
429 =
dynamic_cast<xercesc::DOMElement*
>(iter);
438 if (tag==
"define") {
DefineRead(child); }
else
440 if (tag==
"solids") {
SolidsRead(child); }
else
441 if (tag==
"setup") {
SetupRead(child); }
else
447 G4String error_msg =
"Unknown tag in gdml: " + tag;
459 G4cout <<
"G4GDML: Reading module '" << fileName <<
"' done!" <<
G4endl;
464 G4cout <<
"G4GDML: Reading '" << fileName <<
"' done!" <<
G4endl;