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);
347 G4String error_msg =
"Unknown tag in gdml: " +
tag;
358 G4cout <<
"G4GDML: Reading module '" << fileName <<
"' done!" <<
G4endl;
362 G4cout <<
"G4GDML: Reading '" << fileName <<
"' done!" <<
G4endl;
std::vector< G4Element * > G4ElementTable
std::vector< G4Material * > G4MaterialTable
G4DLLIMPORT std::ostream G4cout
void SetName(const G4String &name)
const G4String & GetName() const
static const G4ElementTable * GetElementTable()
void SetVariable(const G4String &, G4double)
G4bool IsVariable(const G4String &) const
G4int EvaluateInteger(const G4String &)
G4String SolveBrackets(const G4String &)
G4String Strip(const G4String &) const
void GeneratePhysvolName(const G4String &, G4VPhysicalVolume *)
virtual void SolidsRead(const xercesc::DOMElement *const)=0
G4String GenerateName(const G4String &name, G4bool strip=false)
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 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)
void SetName(const G4String &name)
static const G4MaterialTable * GetMaterialTable()
const G4String & GetName() const
static G4PhysicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
G4String & remove(str_size)
static void BuildUnitsTable()
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
void SetName(const G4String &pName)
void SetName(const G4String &name)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)