59 char* char_str = xercesc::XMLString::transcode(toTranscode);
61 xercesc::XMLString::release(&char_str);
96 std::stringstream stream;
98 nameOut = stream.str();
116 auto idx = name.find(
"0x");
117 if(idx != G4String::npos)
135 G4cout <<
"Stripping off GDML names of materials, solids and volumes ..."
143 for(i = 0; i < solids->size(); ++i)
154 for(i = 0; i < lvols->size(); ++i)
165 for(i = 0; i < pvols->size(); ++i)
176 for(i = 0; i < materials->size(); ++i)
186 for(i = 0; i < elements->size(); ++i)
197 void (
G4GDMLRead::*func)(
const xercesc::DOMElement*
const))
204 const xercesc::DOMNamedNodeMap*
const attributes = element->getAttributes();
205 XMLSize_t attributeCount = attributes->getLength();
207 for(XMLSize_t attribute_index = 0; attribute_index < attributeCount;
210 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
212 if(attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
217 const xercesc::DOMAttr*
const attribute =
218 dynamic_cast<xercesc::DOMAttr*
>(attribute_node);
222 "No attribute found!");
228 if(attribute_name ==
"for")
230 var = attribute_value;
232 else if(attribute_name ==
"from")
234 from = attribute_value;
236 else if(attribute_name ==
"to")
238 to = attribute_value;
240 else if(attribute_name ==
"step")
242 step = attribute_value;
249 "No variable is determined for loop!");
255 "Variable is not defined in loop!");
268 if((_from < _to) && (_step <= 0))
273 if((_from > _to) && (_step >= 0))
284 (this->*func)(element);
298 const xercesc::DOMElement*
const auxiliaryElement)
303 const xercesc::DOMNamedNodeMap*
const attributes =
304 auxiliaryElement->getAttributes();
305 XMLSize_t attributeCount = attributes->getLength();
307 for(XMLSize_t attribute_index = 0; attribute_index < attributeCount;
310 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
312 if(attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
317 const xercesc::DOMAttr*
const attribute =
318 dynamic_cast<xercesc::DOMAttr*
>(attribute_node);
322 "No attribute found!");
328 if(attName ==
"auxtype")
330 auxstruct.
type = attValue;
332 else if(attName ==
"auxvalue")
334 auxstruct.
value = attValue;
336 else if(attName ==
"auxunit")
338 auxstruct.
unit = attValue;
342 for(xercesc::DOMNode* iter = auxiliaryElement->getFirstChild();
343 iter !=
nullptr; iter = iter->getNextSibling())
345 if(iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)
350 const xercesc::DOMElement*
const child =
351 dynamic_cast<xercesc::DOMElement*
>(iter);
360 if(
tag ==
"auxiliary")
384 for(xercesc::DOMNode* iter = userinfoElement->getFirstChild();
385 iter !=
nullptr; iter = iter->getNextSibling())
387 if(iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)
392 const xercesc::DOMElement*
const child =
393 dynamic_cast<xercesc::DOMElement*
>(iter);
402 if(
tag ==
"auxiliary")
408 G4String error_msg =
"Unknown tag in structure: " +
tag;
418 G4String error_msg =
"No handle to user-code for parsing extensions!";
443 G4cout <<
"G4GDML: Reading module '" << fileName <<
"'..." <<
G4endl;
447 G4cout <<
"G4GDML: Reading '" << fileName <<
"'..." <<
G4endl;
454 xercesc::XercesDOMParser* parser =
new xercesc::XercesDOMParser;
458 parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
467 if(parser->loadGrammar(schemaPath.c_str(), xercesc::Grammar::SchemaGrammarType,
true) !=
nullptr)
469 G4cout <<
"G4GDML: Loaded alternative schema URI: " << schemaPath <<
G4endl;
474 "InvalidGDMLSchemaFile",
476 G4String(
"Failed to load/parse schema file '" + schemaPath +
"'").c_str());
478 parser->useCachedGrammarInParse(
true);
480 parser->setExternalNoNamespaceSchemaLocation(schemaPath.c_str());
483 parser->setValidationSchemaFullChecking(
validate);
484 parser->setCreateEntityReferenceNodes(
false);
487 parser->setDoNamespaces(
true);
489 parser->setErrorHandler(handler);
493 parser->parse(fileName.c_str());
494 }
catch(
const xercesc::XMLException& e)
497 }
catch(
const xercesc::DOMException& e)
502 xercesc::DOMDocument* doc = parser->getDocument();
506 G4String error_msg =
"Unable to open document: " + fileName;
510 xercesc::DOMElement* element = doc->getDocumentElement();
512 if(element ==
nullptr )
514 std::ostringstream message;
515 message <<
"ERROR - Empty document or unable to validate schema!" <<
G4endl
516 <<
" Check Internet connection is ON in case of schema"
518 <<
" validation enabled and location defined as URL in"
519 <<
G4endl <<
" the GDML file - " << fileName
520 <<
" - being imported!" <<
G4endl
521 <<
" Otherwise, verify GDML schema server is reachable!";
526 for(xercesc::DOMNode* iter = element->getFirstChild(); iter !=
nullptr;
527 iter = iter->getNextSibling())
529 if(iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)
534 const xercesc::DOMElement*
const child =
535 dynamic_cast<xercesc::DOMElement*
>(iter);
548 else if(
tag ==
"materials")
552 else if(
tag ==
"solids")
556 else if(
tag ==
"setup")
560 else if(
tag ==
"structure")
564 else if(
tag ==
"userinfo")
568 else if(
tag ==
"extension")
574 G4String error_msg =
"Unknown tag in gdml: " +
tag;
586 G4cout <<
"G4GDML: Reading module '" << fileName <<
"' done!" <<
G4endl;
591 G4cout <<
"G4GDML: Reading '" << fileName <<
"' done!" <<
G4endl;
602 return &auxGlobalList;
std::vector< G4Element * > G4ElementTable
_Tp G4GetEnv(const std::string &env_id, _Tp _default=_Tp())
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 &)
const G4String & GetSchemaFile() const
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
void SetSchemaFile(const G4String &schemaFile)
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()
static G4UnitsTable & GetUnitsTable()
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
void SetName(const G4String &pName)
void SetName(const G4String &name)
std::vector< G4GDMLAuxStructType > * auxList