46 : 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)
177 void(
G4GDMLRead::*func)(
const xercesc::DOMElement*
const))
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; }
233 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
236 if ((_from < _to) && (_step <= 0))
238 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
241 if ((_from > _to) && (_step >= 0))
243 G4Exception(
"G4GDMLRead::loopRead()",
"InvalidRead",
252 (this->*func)(element);
267 const xercesc::DOMNamedNodeMap*
const attributes
268 = auxiliaryElement->getAttributes();
269 XMLSize_t attributeCount = attributes->getLength();
271 for (XMLSize_t attribute_index=0;
272 attribute_index<attributeCount; attribute_index++)
274 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
276 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
279 const xercesc::DOMAttr*
const attribute
280 =
dynamic_cast<xercesc::DOMAttr*
>(attribute_node);
290 if (attName==
"auxtype") { auxstruct.
type = attValue; }
else
291 if (attName==
"auxvalue") { auxstruct.
value = attValue; }
else
292 if (attName==
"auxunit") { auxstruct.
unit = attValue; }
295 for (xercesc::DOMNode* iter = auxiliaryElement->getFirstChild();
296 iter != 0; iter = iter->getNextSibling())
298 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
continue; }
300 const xercesc::DOMElement*
const child
301 =
dynamic_cast<xercesc::DOMElement*
>(iter);
310 if (tag==
"auxiliary")
317 if (auxList) { auxstruct.
auxList = auxList; }
327 for (xercesc::DOMNode* iter = userinfoElement->getFirstChild();
328 iter != 0; iter = iter->getNextSibling())
330 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
continue; }
332 const xercesc::DOMElement*
const child
333 =
dynamic_cast<xercesc::DOMElement*
>(iter);
342 if (tag==
"auxiliary")
348 G4String error_msg =
"Unknown tag in structure: " + tag;
357 G4String error_msg =
"No handle to user-code for parsing extensions!";
371 G4cout <<
"G4GDML: Reading module '" << fileName <<
"'..." <<
G4endl;
375 G4cout <<
"G4GDML: Reading '" << fileName <<
"'..." <<
G4endl;
382 xercesc::XercesDOMParser*
parser =
new xercesc::XercesDOMParser;
386 parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
388 parser->setValidationSchemaFullChecking(
validate);
389 parser->setCreateEntityReferenceNodes(
false);
392 parser->setDoNamespaces(
true);
394 parser->setErrorHandler(handler);
396 try { parser->parse(fileName.c_str()); }
397 catch (
const xercesc::XMLException &
e)
399 catch (
const xercesc::DOMException &e)
402 xercesc::DOMDocument* doc = parser->getDocument();
406 G4String error_msg =
"Unable to open document: " + fileName;
411 xercesc::DOMElement* element = doc->getDocumentElement();
416 message <<
"ERROR - Empty document or unable to validate schema!" <<
G4endl
417 <<
" Check Internet connection is ON in case of schema"
419 <<
" validation enabled and location defined as URL in"
421 <<
" the GDML file - " << fileName <<
" - being imported!"
423 <<
" Otherwise, verify GDML schema server is reachable!";
428 for (xercesc::DOMNode* iter = element->getFirstChild();
429 iter != 0; iter = iter->getNextSibling())
431 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
continue; }
433 const xercesc::DOMElement*
const child
434 =
dynamic_cast<xercesc::DOMElement*
>(iter);
443 if (tag==
"define") {
DefineRead(child); }
else
445 if (tag==
"solids") {
SolidsRead(child); }
else
446 if (tag==
"setup") {
SetupRead(child); }
else
452 G4String error_msg =
"Unknown tag in gdml: " + tag;
464 G4cout <<
"G4GDML: Reading module '" << fileName <<
"' done!" <<
G4endl;
469 G4cout <<
"G4GDML: Reading '" << fileName <<
"' done!" <<
G4endl;
void SetName(const G4String &name)
G4String & remove(str_size)
void SetName(const G4String &pName)
G4LogicalVolume * GetLogicalVolume() const
void Read(const G4String &, G4bool validation, G4bool isModule, G4bool strip=true)
static G4MaterialTable * GetMaterialTable()
const G4String & GetName() const
const G4GDMLAuxListType * GetAuxList() const
void SetName(const G4String &name)
void LoopRead(const xercesc::DOMElement *const, void(G4GDMLRead::*)(const xercesc::DOMElement *const))
void message(RunManager *runmanager)
G4String GenerateName(const G4String &name, G4bool strip=false)
virtual void DefineRead(const xercesc::DOMElement *const)=0
virtual void SolidsRead(const xercesc::DOMElement *const)=0
virtual void StructureRead(const xercesc::DOMElement *const)=0
const G4String & GetName() const
G4GDMLAuxStructType AuxiliaryRead(const xercesc::DOMElement *const auxElem)
void GeneratePhysvolName(const G4String &, G4VPhysicalVolume *)
G4String Strip(const G4String &) const
G4String Transcode(const XMLCh *const)
std::vector< G4Element * > G4ElementTable
std::vector< G4GDMLAuxStructType > * auxList
void SetName(const G4String &name)
CommandLineParser * parser(0)
G4String SolveBrackets(const G4String &)
void StripName(G4String &) const
std::vector< G4Material * > G4MaterialTable
static G4SolidStore * GetInstance()
G4GDMLAuxListType auxGlobalList
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
void OverlapCheck(G4bool)
static G4PhysicalVolumeStore * GetInstance()
virtual void SetupRead(const xercesc::DOMElement *const)=0
void SetName(const G4String &pName)
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
G4GLOB_DLL std::ostream G4cout
G4bool IsVariable(const G4String &) const
G4int EvaluateInteger(const G4String &)
virtual void MaterialsRead(const xercesc::DOMElement *const)=0
void SetVariable(const G4String &, G4double)
static G4LogicalVolumeStore * GetInstance()
const G4String & GetName() const
virtual void ExtensionRead(const xercesc::DOMElement *const)
virtual void UserinfoRead(const xercesc::DOMElement *const)
const G4String & GetName() const
static void BuildUnitsTable()
static G4ElementTable * GetElementTable()