G4GDMLReadSetup.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // class G4GDMLReadSetup Implementation
00029 //
00030 // Original author: Zoltan Torzsok, November 2007
00031 //
00032 // --------------------------------------------------------------------
00033 
00034 #include "G4GDMLReadSetup.hh"
00035 
00036 G4GDMLReadSetup::G4GDMLReadSetup() : G4GDMLReadSolids()
00037 {
00038 }
00039 
00040 G4GDMLReadSetup::~G4GDMLReadSetup()
00041 {
00042 }
00043 
00044 G4String G4GDMLReadSetup::GetSetup(const G4String& ref)
00045 {
00046    if (setupMap.size() == 1)     // If there is only one setup defined,
00047    {                             // no matter how it is named
00048      return setupMap.begin()->second;
00049    }
00050 
00051    if (setupMap.find(ref) == setupMap.end())
00052    {
00053      G4String error_msg = "Referenced setup '" + ref + "' was not found!";
00054      G4Exception("G4GDMLReadSetup::getSetup()", "ReadError",
00055                  FatalException, error_msg);
00056    }
00057 
00058    return setupMap[ref];
00059 }
00060 
00061 void G4GDMLReadSetup::SetupRead(const xercesc::DOMElement* const element)
00062 {
00063    G4cout << "G4GDML: Reading setup..." << G4endl;
00064 
00065    G4String name;
00066 
00067    const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
00068    XMLSize_t attributeCount = attributes->getLength();
00069 
00070    for (XMLSize_t attribute_index=0;
00071         attribute_index<attributeCount; attribute_index++)
00072    {
00073       xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
00074 
00075       if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
00076         { continue; }
00077 
00078       const xercesc::DOMAttr* const attribute
00079             = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
00080       if (!attribute)
00081       {
00082         G4Exception("G4GDMLReadSetup::SetupRead()",
00083                     "InvalidRead", FatalException, "No attribute found!");
00084         return;
00085       }
00086       const G4String attName  = Transcode(attribute->getName());
00087       const G4String attValue = Transcode(attribute->getValue());
00088 
00089       if (attName=="name")  { name = attValue; }
00090    }
00091 
00092    for (xercesc::DOMNode* iter = element->getFirstChild();
00093         iter != 0; iter = iter->getNextSibling())
00094    {
00095       if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)  { continue; }
00096 
00097       const xercesc::DOMElement* const child
00098             = dynamic_cast<xercesc::DOMElement*>(iter);
00099       if (!child)
00100       {
00101         G4Exception("G4GDMLReadSetup::SetupRead()",
00102                     "InvalidRead", FatalException, "No child found!");
00103         return;
00104       }
00105       const G4String tag = Transcode(child->getTagName());
00106 
00107       if (tag == "world") { setupMap[name] = GenerateName(RefRead(child)); }
00108    }
00109 }

Generated on Mon May 27 17:48:20 2013 for Geant4 by  doxygen 1.4.7