source: trunk/source/persistency/gdml/src/G4GDMLReadSetup.cc @ 1347

Last change on this file since 1347 was 1347, checked in by garnier, 13 years ago

geant4 tag 9.4

File size: 4.1 KB
Line 
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: G4GDMLReadSetup.cc,v 1.11 2010/10/14 16:19:40 gcosmo Exp $
27// GEANT4 tag $Name: gdml-V09-03-09 $
28//
29// class G4GDMLReadSetup Implementation
30//
31// Original author: Zoltan Torzsok, November 2007
32//
33// --------------------------------------------------------------------
34
35#include "G4GDMLReadSetup.hh"
36
37G4GDMLReadSetup::G4GDMLReadSetup() : G4GDMLReadSolids()
38{
39}
40
41G4GDMLReadSetup::~G4GDMLReadSetup()
42{
43}
44
45G4String 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
62void 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      if (!attribute)
82      {
83        G4Exception("G4GDMLReadSetup::SetupRead()",
84                    "InvalidRead", FatalException, "No attribute found!");
85        return;
86      }
87      const G4String attName  = Transcode(attribute->getName());
88      const G4String attValue = Transcode(attribute->getValue());
89
90      if (attName=="name")  { name = attValue; }
91   }
92
93   for (xercesc::DOMNode* iter = element->getFirstChild();
94        iter != 0; iter = iter->getNextSibling())
95   {
96      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)  { continue; }
97
98      const xercesc::DOMElement* const child
99            = dynamic_cast<xercesc::DOMElement*>(iter);
100      if (!child)
101      {
102        G4Exception("G4GDMLReadSetup::SetupRead()",
103                    "InvalidRead", FatalException, "No child found!");
104        return;
105      }
106      const G4String tag = Transcode(child->getTagName());
107
108      if (tag == "world") { setupMap[name] = GenerateName(RefRead(child)); }
109   }
110}
Note: See TracBrowser for help on using the repository browser.