Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GDMLReadSetup.cc
Go to the documentation of this file.
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 //
26 // $Id$
27 //
28 // class G4GDMLReadSetup Implementation
29 //
30 // Original author: Zoltan Torzsok, November 2007
31 //
32 // --------------------------------------------------------------------
33 
34 #include "G4GDMLReadSetup.hh"
35 
37 {
38 }
39 
41 {
42 }
43 
45 {
46  if (setupMap.size() == 1) // If there is only one setup defined,
47  { // no matter how it is named
48  return setupMap.begin()->second;
49  }
50 
51  if (setupMap.find(ref) == setupMap.end())
52  {
53  G4String error_msg = "Referenced setup '" + ref + "' was not found!";
54  G4Exception("G4GDMLReadSetup::getSetup()", "ReadError",
55  FatalException, error_msg);
56  }
57 
58  return setupMap[ref];
59 }
60 
61 void G4GDMLReadSetup::SetupRead(const xercesc::DOMElement* const element)
62 {
63  G4cout << "G4GDML: Reading setup..." << G4endl;
64 
65  G4String name;
66 
67  const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
68  XMLSize_t attributeCount = attributes->getLength();
69 
70  for (XMLSize_t attribute_index=0;
71  attribute_index<attributeCount; attribute_index++)
72  {
73  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
74 
75  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
76  { continue; }
77 
78  const xercesc::DOMAttr* const attribute
79  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
80  if (!attribute)
81  {
82  G4Exception("G4GDMLReadSetup::SetupRead()",
83  "InvalidRead", FatalException, "No attribute found!");
84  return;
85  }
86  const G4String attName = Transcode(attribute->getName());
87  const G4String attValue = Transcode(attribute->getValue());
88 
89  if (attName=="name") { name = attValue; }
90  }
91 
92  for (xercesc::DOMNode* iter = element->getFirstChild();
93  iter != 0; iter = iter->getNextSibling())
94  {
95  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
96 
97  const xercesc::DOMElement* const child
98  = dynamic_cast<xercesc::DOMElement*>(iter);
99  if (!child)
100  {
101  G4Exception("G4GDMLReadSetup::SetupRead()",
102  "InvalidRead", FatalException, "No child found!");
103  return;
104  }
105  const G4String tag = Transcode(child->getTagName());
106 
107  if (tag == "world") { setupMap[name] = GenerateName(RefRead(child)); }
108  }
109 }