Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: G4GDMLReadSetup.cc 88207 2015-02-03 13:47:36Z gcosmo $
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 #ifdef G4VERBOSE
54  std::ostringstream message;
55  message << "Referenced setup '" << ref << "' was not found!";
56  G4Exception("G4GDMLReadSetup::getSetup()", "NullSetup",
57  JustWarning, message, "Returning NULL pointer!");
58 #endif
59  return "";
60  }
61 
62  return setupMap[ref];
63 }
64 
65 void G4GDMLReadSetup::SetupRead(const xercesc::DOMElement* const element)
66 {
67  G4cout << "G4GDML: Reading setup..." << G4endl;
68 
69  G4String name;
70 
71  const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
72  XMLSize_t attributeCount = attributes->getLength();
73 
74  for (XMLSize_t attribute_index=0;
75  attribute_index<attributeCount; attribute_index++)
76  {
77  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
78 
79  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
80  { continue; }
81 
82  const xercesc::DOMAttr* const attribute
83  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
84  if (!attribute)
85  {
86  G4Exception("G4GDMLReadSetup::SetupRead()",
87  "InvalidRead", FatalException, "No attribute found!");
88  return;
89  }
90  const G4String attName = Transcode(attribute->getName());
91  const G4String attValue = Transcode(attribute->getValue());
92 
93  if (attName=="name") { name = attValue; }
94  }
95 
96  for (xercesc::DOMNode* iter = element->getFirstChild();
97  iter != 0; iter = iter->getNextSibling())
98  {
99  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
100 
101  const xercesc::DOMElement* const child
102  = dynamic_cast<xercesc::DOMElement*>(iter);
103  if (!child)
104  {
105  G4Exception("G4GDMLReadSetup::SetupRead()",
106  "InvalidRead", FatalException, "No child found!");
107  return;
108  }
109  const G4String tag = Transcode(child->getTagName());
110 
111  if (tag == "world") { setupMap[name] = GenerateName(RefRead(child)); }
112  }
113 }
const XML_Char * name
Definition: expat.h:151
std::map< G4String, G4String > setupMap
virtual ~G4GDMLReadSetup()
virtual void SetupRead(const xercesc::DOMElement *const element)
Definition: xmlparse.cc:187
G4String Transcode(const XMLCh *const)
Definition: G4GDMLRead.cc:55
G4String RefRead(const xercesc::DOMElement *const)
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4String GenerateName(const G4String &name, G4bool strip=false)
Definition: G4GDMLRead.cc:68
#define G4endl
Definition: G4ios.hh:61
G4String GetSetup(const G4String &)