46 : validate(true), check(false), dostrip(true), inLoop(0), loopCount(0)
57 char* char_str = xercesc::XMLString::transcode(toTranscode);
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);
263 G4String error_msg =
"No handle to user-code for parsing extensions!";
276 G4cout <<
"G4GDML: Reading module '" << fileName <<
"'..." <<
G4endl;
280 G4cout <<
"G4GDML: Reading '" << fileName <<
"'..." <<
G4endl;
287 xercesc::XercesDOMParser*
parser =
new xercesc::XercesDOMParser;
291 parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
293 parser->setValidationSchemaFullChecking(
validate);
294 parser->setCreateEntityReferenceNodes(
false);
297 parser->setDoNamespaces(
true);
299 parser->setErrorHandler(handler);
301 try { parser->parse(fileName.c_str()); }
302 catch (
const xercesc::XMLException &e)
304 catch (
const xercesc::DOMException &e)
307 xercesc::DOMDocument* doc = parser->getDocument();
311 G4String error_msg =
"Unable to open document: " + fileName;
316 xercesc::DOMElement* element = doc->getDocumentElement();
320 std::ostringstream message;
321 message <<
"ERROR - Empty document or unable to validate schema!" <<
G4endl
322 <<
" Check Internet connection is ON in case of schema"
324 <<
" validation enabled and location defined as URL in"
326 <<
" the GDML file - " << fileName <<
" - being imported!"
328 <<
" Otherwise, verify GDML schema server is reachable!";
333 for (xercesc::DOMNode* iter = element->getFirstChild();
334 iter != 0; iter = iter->getNextSibling())
336 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
continue; }
338 const xercesc::DOMElement*
const child
339 =
dynamic_cast<xercesc::DOMElement*
>(iter);
348 if (tag==
"define") {
DefineRead(child); }
else
350 if (tag==
"solids") {
SolidsRead(child); }
else
351 if (tag==
"setup") {
SetupRead(child); }
else
356 G4String error_msg =
"Unknown tag in gdml: " + tag;
367 G4cout <<
"G4GDML: Reading module '" << fileName <<
"' done!" <<
G4endl;
371 G4cout <<
"G4GDML: Reading '" << fileName <<
"' done!" <<
G4endl;
static int release(statusMessageReporting *smr, xDataType *xDT)
static void BuildUnitsTable()
G4int EvaluateInteger(const G4String &)
void SetName(const G4String &name)
void OverlapCheck(G4bool)
G4String & remove(str_size)
const G4String & GetName() const
static G4MaterialTable * GetMaterialTable()
std::vector< G4Material * > G4MaterialTable
virtual void MaterialsRead(const xercesc::DOMElement *const)=0
G4String Transcode(const XMLCh *const)
void SetName(const G4String &pName)
void GeneratePhysvolName(const G4String &, G4VPhysicalVolume *)
virtual void StructureRead(const xercesc::DOMElement *const)=0
static G4PhysicalVolumeStore * GetInstance()
void SetName(const G4String &name)
void LoopRead(const xercesc::DOMElement *const, void(G4GDMLRead::*)(const xercesc::DOMElement *const))
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
G4bool IsVariable(const G4String &) const
CommandLineParser * parser(0)
void StripName(G4String &) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4String SolveBrackets(const G4String &)
virtual void DefineRead(const xercesc::DOMElement *const)=0
virtual void ExtensionRead(const xercesc::DOMElement *const)
G4String GenerateName(const G4String &name, G4bool strip=false)
G4LogicalVolume * GetLogicalVolume() const
void SetVariable(const G4String &, G4double)
G4String Strip(const G4String &) const
void SetName(const G4String &pName)
std::vector< G4Element * > G4ElementTable
const G4String & GetName() const
virtual void SetupRead(const xercesc::DOMElement *const)=0
static G4ElementTable * GetElementTable()
virtual void SolidsRead(const xercesc::DOMElement *const)=0
void SetName(const G4String &name)
void Read(const G4String &, G4bool validation, G4bool isModule, G4bool strip=true)