57 char* char_str = xercesc::XMLString::transcode(toTranscode);
59 xercesc::XMLString::release(&char_str);
94 std::stringstream stream;
96 nameOut = stream.str();
107 return sname.
remove(sname.find(
"0x"));
113 name.remove(name.find(
"0x"));
128 G4cout <<
"Stripping off GDML names of materials, solids and volumes ..."
136 for(i = 0; i < solids->size(); ++i)
146 for(i = 0; i < lvols->size(); ++i)
156 for(i = 0; i < pvols->size(); ++i)
166 for(i = 0; i < materials->size(); ++i)
176 for(i = 0; i < elements->size(); ++i)
187 void (
G4GDMLRead::*func)(
const xercesc::DOMElement*
const))
194 const xercesc::DOMNamedNodeMap*
const attributes = element->getAttributes();
195 XMLSize_t attributeCount = attributes->getLength();
197 for(XMLSize_t attribute_index = 0; attribute_index < attributeCount;
200 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
202 if(attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
207 const xercesc::DOMAttr*
const attribute =
208 dynamic_cast<xercesc::DOMAttr*
>(attribute_node);
212 "No attribute found!");
218 if(attribute_name ==
"for")
220 var = attribute_value;
222 else if(attribute_name ==
"from")
224 from = attribute_value;
226 else if(attribute_name ==
"to")
228 to = attribute_value;
230 else if(attribute_name ==
"step")
232 step = attribute_value;
239 "No variable is determined for loop!");
245 "Variable is not defined in loop!");
258 if((_from < _to) && (_step <= 0))
263 if((_from > _to) && (_step >= 0))
274 (this->*func)(element);
288 const xercesc::DOMElement*
const auxiliaryElement)
293 const xercesc::DOMNamedNodeMap*
const attributes =
294 auxiliaryElement->getAttributes();
295 XMLSize_t attributeCount = attributes->getLength();
297 for(XMLSize_t attribute_index = 0; attribute_index < attributeCount;
300 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
302 if(attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
307 const xercesc::DOMAttr*
const attribute =
308 dynamic_cast<xercesc::DOMAttr*
>(attribute_node);
312 "No attribute found!");
318 if(attName ==
"auxtype")
320 auxstruct.
type = attValue;
322 else if(attName ==
"auxvalue")
324 auxstruct.
value = attValue;
326 else if(attName ==
"auxunit")
328 auxstruct.
unit = attValue;
332 for(xercesc::DOMNode* iter = auxiliaryElement->getFirstChild();
333 iter !=
nullptr; iter = iter->getNextSibling())
335 if(iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)
340 const xercesc::DOMElement*
const child =
341 dynamic_cast<xercesc::DOMElement*
>(iter);
350 if(
tag ==
"auxiliary")
374 for(xercesc::DOMNode* iter = userinfoElement->getFirstChild();
375 iter !=
nullptr; iter = iter->getNextSibling())
377 if(iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)
382 const xercesc::DOMElement*
const child =
383 dynamic_cast<xercesc::DOMElement*
>(iter);
392 if(
tag ==
"auxiliary")
398 G4String error_msg =
"Unknown tag in structure: " +
tag;
408 G4String error_msg =
"No handle to user-code for parsing extensions!";
421 G4cout <<
"G4GDML: Reading module '" << fileName <<
"'..." <<
G4endl;
425 G4cout <<
"G4GDML: Reading '" << fileName <<
"'..." <<
G4endl;
432 xercesc::XercesDOMParser* parser =
new xercesc::XercesDOMParser;
436 parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
438 parser->setValidationSchemaFullChecking(
validate);
439 parser->setCreateEntityReferenceNodes(
false);
442 parser->setDoNamespaces(
true);
444 parser->setErrorHandler(handler);
448 parser->parse(fileName.c_str());
449 }
catch(
const xercesc::XMLException& e)
452 }
catch(
const xercesc::DOMException& e)
457 xercesc::DOMDocument* doc = parser->getDocument();
461 G4String error_msg =
"Unable to open document: " + fileName;
465 xercesc::DOMElement* element = doc->getDocumentElement();
467 if(element ==
nullptr )
469 std::ostringstream message;
470 message <<
"ERROR - Empty document or unable to validate schema!" <<
G4endl
471 <<
" Check Internet connection is ON in case of schema"
473 <<
" validation enabled and location defined as URL in"
474 <<
G4endl <<
" the GDML file - " << fileName
475 <<
" - being imported!" <<
G4endl
476 <<
" Otherwise, verify GDML schema server is reachable!";
481 for(xercesc::DOMNode* iter = element->getFirstChild(); iter !=
nullptr;
482 iter = iter->getNextSibling())
484 if(iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)
489 const xercesc::DOMElement*
const child =
490 dynamic_cast<xercesc::DOMElement*
>(iter);
503 else if(
tag ==
"materials")
507 else if(
tag ==
"solids")
511 else if(
tag ==
"setup")
515 else if(
tag ==
"structure")
519 else if(
tag ==
"userinfo")
523 else if(
tag ==
"extension")
529 G4String error_msg =
"Unknown tag in gdml: " +
tag;
541 G4cout <<
"G4GDML: Reading module '" << fileName <<
"' done!" <<
G4endl;
546 G4cout <<
"G4GDML: Reading '" << fileName <<
"' done!" <<
G4endl;
557 return &auxGlobalList;
std::vector< G4Element * > G4ElementTable
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
std::vector< G4Material * > G4MaterialTable
G4GLOB_DLL std::ostream G4cout
static G4ElementTable * GetElementTable()
void SetName(const G4String &name)
const G4String & GetName() const
void SetVariable(const G4String &, G4double)
G4bool IsVariable(const G4String &) const
G4int EvaluateInteger(const G4String &)
G4String SolveBrackets(const G4String &)
G4String Strip(const G4String &) const
G4GDMLAuxStructType AuxiliaryRead(const xercesc::DOMElement *const auxElem)
void GeneratePhysvolName(const G4String &, G4VPhysicalVolume *)
virtual void SolidsRead(const xercesc::DOMElement *const)=0
G4String GenerateName(const G4String &name, G4bool strip=false)
const G4GDMLAuxListType * GetAuxList() const
virtual void MaterialsRead(const xercesc::DOMElement *const)=0
void LoopRead(const xercesc::DOMElement *const, void(G4GDMLRead::*)(const xercesc::DOMElement *const))
void Read(const G4String &, G4bool validation, G4bool isModule, G4bool strip=true)
virtual void UserinfoRead(const xercesc::DOMElement *const)
virtual void SetupRead(const xercesc::DOMElement *const)=0
G4String Transcode(const XMLCh *const)
void StripName(G4String &) const
virtual void ExtensionRead(const xercesc::DOMElement *const)
virtual void DefineRead(const xercesc::DOMElement *const)=0
virtual void StructureRead(const xercesc::DOMElement *const)=0
void OverlapCheck(G4bool)
static G4LogicalVolumeStore * GetInstance()
void SetName(const G4String &pName)
const G4String & GetName() const
void SetName(const G4String &name)
static G4MaterialTable * GetMaterialTable()
const G4String & GetName() const
static G4PhysicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
G4String & remove(str_size)
static G4UnitsTable & GetUnitsTable()
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
void SetName(const G4String &pName)
void SetName(const G4String &name)
std::vector< G4GDMLAuxStructType > * auxList