[987] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
[1228] | 26 | // $Id: G4GDMLReadSetup.cc,v 1.10 2009/03/24 15:47:33 gcosmo Exp $ |
---|
| 27 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
[987] | 28 | // |
---|
| 29 | // class G4GDMLReadSetup Implementation |
---|
| 30 | // |
---|
| 31 | // Original author: Zoltan Torzsok, November 2007 |
---|
| 32 | // |
---|
| 33 | // -------------------------------------------------------------------- |
---|
| 34 | |
---|
| 35 | #include "G4GDMLReadSetup.hh" |
---|
| 36 | |
---|
[1228] | 37 | G4GDMLReadSetup::G4GDMLReadSetup() : G4GDMLReadSolids() |
---|
| 38 | { |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | G4GDMLReadSetup::~G4GDMLReadSetup() |
---|
| 42 | { |
---|
| 43 | } |
---|
| 44 | |
---|
[987] | 45 | G4String G4GDMLReadSetup::GetSetup(const G4String& ref) |
---|
| 46 | { |
---|
| 47 | if (setupMap.size() == 1) // If there is only one setup defined, |
---|
| 48 | { // no matter how it is named |
---|
| 49 | return setupMap.begin()->second; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | if (setupMap.find(ref) == setupMap.end()) |
---|
| 53 | { |
---|
| 54 | G4String error_msg = "Referenced setup '" + ref + "' was not found!"; |
---|
| 55 | G4Exception("G4GDMLReadSetup::getSetup()", "ReadError", |
---|
| 56 | FatalException, error_msg); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | return setupMap[ref]; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void G4GDMLReadSetup::SetupRead(const xercesc::DOMElement* const element) |
---|
| 63 | { |
---|
| 64 | G4cout << "G4GDML: Reading setup..." << G4endl; |
---|
| 65 | |
---|
| 66 | G4String name; |
---|
| 67 | |
---|
| 68 | const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes(); |
---|
| 69 | XMLSize_t attributeCount = attributes->getLength(); |
---|
| 70 | |
---|
| 71 | for (XMLSize_t attribute_index=0; |
---|
| 72 | attribute_index<attributeCount; attribute_index++) |
---|
| 73 | { |
---|
| 74 | xercesc::DOMNode* attribute_node = attributes->item(attribute_index); |
---|
| 75 | |
---|
| 76 | if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) |
---|
| 77 | { continue; } |
---|
| 78 | |
---|
| 79 | const xercesc::DOMAttr* const attribute |
---|
| 80 | = dynamic_cast<xercesc::DOMAttr*>(attribute_node); |
---|
| 81 | const G4String attName = Transcode(attribute->getName()); |
---|
| 82 | const G4String attValue = Transcode(attribute->getValue()); |
---|
| 83 | |
---|
| 84 | if (attName=="name") { name = attValue; } |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | for (xercesc::DOMNode* iter = element->getFirstChild(); |
---|
| 88 | iter != 0; iter = iter->getNextSibling()) |
---|
| 89 | { |
---|
| 90 | if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } |
---|
| 91 | |
---|
| 92 | const xercesc::DOMElement* const child |
---|
| 93 | = dynamic_cast<xercesc::DOMElement*>(iter); |
---|
| 94 | const G4String tag = Transcode(child->getTagName()); |
---|
| 95 | |
---|
| 96 | if (tag == "world") { setupMap[name] = GenerateName(RefRead(child)); } |
---|
| 97 | } |
---|
| 98 | } |
---|