Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4GDMLReadSetup implementation << 26 // $Id: G4GDMLReadSetup.cc 68053 2013-03-13 14:39:51Z gcosmo $ >> 27 // >> 28 // class G4GDMLReadSetup Implementation >> 29 // >> 30 // Original author: Zoltan Torzsok, November 2007 27 // 31 // 28 // Author: Zoltan Torzsok, November 2007 << 29 // ------------------------------------------- 32 // -------------------------------------------------------------------- 30 33 31 #include "G4GDMLReadSetup.hh" 34 #include "G4GDMLReadSetup.hh" 32 35 33 // ------------------------------------------- << 36 G4GDMLReadSetup::G4GDMLReadSetup() : G4GDMLReadSolids() 34 G4GDMLReadSetup::G4GDMLReadSetup() << 35 : G4GDMLReadSolids() << 36 { 37 { 37 } 38 } 38 39 39 // ------------------------------------------- << 40 G4GDMLReadSetup::~G4GDMLReadSetup() 40 G4GDMLReadSetup::~G4GDMLReadSetup() 41 { 41 { 42 } 42 } 43 43 44 // ------------------------------------------- << 45 G4String G4GDMLReadSetup::GetSetup(const G4Str 44 G4String G4GDMLReadSetup::GetSetup(const G4String& ref) 46 { 45 { 47 if(setupMap.size() == 1) // If there is onl << 46 if (setupMap.size() == 1) // If there is only one setup defined, 48 { // no matter how i << 47 { // no matter how it is named 49 return setupMap.cbegin()->second; << 48 return setupMap.begin()->second; 50 } << 49 } 51 << 50 52 if(setupMap.find(ref) == setupMap.cend()) << 51 if (setupMap.find(ref) == setupMap.end()) 53 { << 52 { 54 #ifdef G4VERBOSE << 53 G4String error_msg = "Referenced setup '" + ref + "' was not found!"; 55 std::ostringstream message; << 54 G4Exception("G4GDMLReadSetup::getSetup()", "ReadError", 56 message << "Referenced setup '" << ref << << 55 FatalException, error_msg); 57 G4Exception("G4GDMLReadSetup::getSetup()", << 56 } 58 message, "Returning NULL point << 59 #endif << 60 return ""; << 61 } << 62 57 63 return setupMap[ref]; << 58 return setupMap[ref]; 64 } 59 } 65 60 66 // ------------------------------------------- << 67 void G4GDMLReadSetup::SetupRead(const xercesc: 61 void G4GDMLReadSetup::SetupRead(const xercesc::DOMElement* const element) 68 { 62 { 69 #ifdef G4VERBOSE << 63 G4cout << "G4GDML: Reading setup..." << G4endl; 70 G4cout << "G4GDML: Reading setup..." << G4en << 64 71 #endif << 65 G4String name; 72 G4String name; << 66 73 << 67 const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes(); 74 const xercesc::DOMNamedNodeMap* const attrib << 68 XMLSize_t attributeCount = attributes->getLength(); 75 XMLSize_t attributeCount << 69 76 << 70 for (XMLSize_t attribute_index=0; 77 for(XMLSize_t attribute_index = 0; attribute << 71 attribute_index<attributeCount; attribute_index++) 78 ++attribute_index) << 72 { 79 { << 73 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 80 xercesc::DOMNode* attribute_node = attribu << 74 81 << 75 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 82 if(attribute_node->getNodeType() != xerces << 76 { continue; } 83 { << 77 84 continue; << 78 const xercesc::DOMAttr* const attribute 85 } << 79 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 86 << 80 if (!attribute) 87 const xercesc::DOMAttr* const attribute = << 81 { 88 dynamic_cast<xercesc::DOMAttr*>(attribut << 82 G4Exception("G4GDMLReadSetup::SetupRead()", 89 if(attribute == nullptr) << 83 "InvalidRead", FatalException, "No attribute found!"); 90 { << 84 return; 91 G4Exception("G4GDMLReadSetup::SetupRead( << 85 } 92 "No attribute found!"); << 86 const G4String attName = Transcode(attribute->getName()); 93 return; << 87 const G4String attValue = Transcode(attribute->getValue()); 94 } << 88 95 const G4String attName = Transcode(attrib << 89 if (attName=="name") { name = attValue; } 96 const G4String attValue = Transcode(attrib << 90 } 97 << 91 98 if(attName == "name") << 92 for (xercesc::DOMNode* iter = element->getFirstChild(); 99 { << 93 iter != 0; iter = iter->getNextSibling()) 100 name = attValue; << 94 { 101 } << 95 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 102 } << 96 103 << 97 const xercesc::DOMElement* const child 104 for(xercesc::DOMNode* iter = element->getFir << 98 = dynamic_cast<xercesc::DOMElement*>(iter); 105 iter = iter->getNextSi << 99 if (!child) 106 { << 100 { 107 if(iter->getNodeType() != xercesc::DOMNode << 101 G4Exception("G4GDMLReadSetup::SetupRead()", 108 { << 102 "InvalidRead", FatalException, "No child found!"); 109 continue; << 103 return; 110 } << 104 } 111 << 105 const G4String tag = Transcode(child->getTagName()); 112 const xercesc::DOMElement* const child = << 106 113 dynamic_cast<xercesc::DOMElement*>(iter) << 107 if (tag == "world") { setupMap[name] = GenerateName(RefRead(child)); } 114 if(child == nullptr) << 108 } 115 { << 116 G4Exception("G4GDMLReadSetup::SetupRead( << 117 "No child found!"); << 118 return; << 119 } << 120 const G4String tag = Transcode(child->getT << 121 << 122 if(tag == "world") << 123 { << 124 setupMap[name] = GenerateName(RefRead(ch << 125 } << 126 } << 127 } 109 } 128 110