ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GDMLReadSetup.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4GDMLReadSetup.cc
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 //
27 // class G4GDMLReadSetup Implementation
28 //
29 // Original author: Zoltan Torzsok, November 2007
30 //
31 // --------------------------------------------------------------------
32 
33 #include "G4GDMLReadSetup.hh"
34 
36 {
37 }
38 
40 {
41 }
42 
44 {
45  if (setupMap.size() == 1) // If there is only one setup defined,
46  { // no matter how it is named
47  return setupMap.begin()->second;
48  }
49 
50  if (setupMap.find(ref) == setupMap.end())
51  {
52 #ifdef G4VERBOSE
53  std::ostringstream message;
54  message << "Referenced setup '" << ref << "' was not found!";
55  G4Exception("G4GDMLReadSetup::getSetup()", "NullSetup",
56  JustWarning, message, "Returning NULL pointer!");
57 #endif
58  return "";
59  }
60 
61  return setupMap[ref];
62 }
63 
64 void G4GDMLReadSetup::SetupRead(const xercesc::DOMElement* const element)
65 {
66 #ifdef G4VERBOSE
67  G4cout << "G4GDML: Reading setup..." << G4endl;
68 #endif
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 }