00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "G4GDMLReadSetup.hh"
00035
00036 G4GDMLReadSetup::G4GDMLReadSetup() : G4GDMLReadSolids()
00037 {
00038 }
00039
00040 G4GDMLReadSetup::~G4GDMLReadSetup()
00041 {
00042 }
00043
00044 G4String G4GDMLReadSetup::GetSetup(const G4String& ref)
00045 {
00046 if (setupMap.size() == 1)
00047 {
00048 return setupMap.begin()->second;
00049 }
00050
00051 if (setupMap.find(ref) == setupMap.end())
00052 {
00053 G4String error_msg = "Referenced setup '" + ref + "' was not found!";
00054 G4Exception("G4GDMLReadSetup::getSetup()", "ReadError",
00055 FatalException, error_msg);
00056 }
00057
00058 return setupMap[ref];
00059 }
00060
00061 void G4GDMLReadSetup::SetupRead(const xercesc::DOMElement* const element)
00062 {
00063 G4cout << "G4GDML: Reading setup..." << G4endl;
00064
00065 G4String name;
00066
00067 const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
00068 XMLSize_t attributeCount = attributes->getLength();
00069
00070 for (XMLSize_t attribute_index=0;
00071 attribute_index<attributeCount; attribute_index++)
00072 {
00073 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
00074
00075 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
00076 { continue; }
00077
00078 const xercesc::DOMAttr* const attribute
00079 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
00080 if (!attribute)
00081 {
00082 G4Exception("G4GDMLReadSetup::SetupRead()",
00083 "InvalidRead", FatalException, "No attribute found!");
00084 return;
00085 }
00086 const G4String attName = Transcode(attribute->getName());
00087 const G4String attValue = Transcode(attribute->getValue());
00088
00089 if (attName=="name") { name = attValue; }
00090 }
00091
00092 for (xercesc::DOMNode* iter = element->getFirstChild();
00093 iter != 0; iter = iter->getNextSibling())
00094 {
00095 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
00096
00097 const xercesc::DOMElement* const child
00098 = dynamic_cast<xercesc::DOMElement*>(iter);
00099 if (!child)
00100 {
00101 G4Exception("G4GDMLReadSetup::SetupRead()",
00102 "InvalidRead", FatalException, "No child found!");
00103 return;
00104 }
00105 const G4String tag = Transcode(child->getTagName());
00106
00107 if (tag == "world") { setupMap[name] = GenerateName(RefRead(child)); }
00108 }
00109 }