Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:19

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4GDMLRead
0027 //
0028 // Class description:
0029 //
0030 // GDML reader.
0031 
0032 // Author: Zoltan Torzsok, November 2007
0033 // --------------------------------------------------------------------
0034 #ifndef G4GDMLBASE_HH
0035 #define G4GDMLBASE_HH 1
0036 
0037 #include <xercesc/parsers/XercesDOMParser.hpp>
0038 #include <xercesc/util/PlatformUtils.hpp>
0039 #include <xercesc/sax/HandlerBase.hpp>
0040 #include <xercesc/util/XMLUni.hpp>
0041 #include <xercesc/dom/DOM.hpp>
0042 
0043 #include "G4Types.hh"
0044 
0045 #include "G4GDMLEvaluator.hh"
0046 #include "G4GDMLAuxStructType.hh"
0047 
0048 class G4LogicalVolume;
0049 class G4VPhysicalVolume;
0050 
0051 class G4GDMLErrorHandler : public xercesc::ErrorHandler
0052 {
0053   public:
0054 
0055     G4GDMLErrorHandler(const G4bool set) { Suppress = set; }
0056 
0057     void warning(const xercesc::SAXParseException& exception)
0058     {
0059       if(Suppress)
0060       {
0061         return;
0062       }
0063       char* message = xercesc::XMLString::transcode(exception.getMessage());
0064       G4cout << "G4GDML: VALIDATION WARNING! " << message
0065              << " at line: " << exception.getLineNumber() << G4endl;
0066       xercesc::XMLString::release(&message);
0067     }
0068 
0069     void error(const xercesc::SAXParseException& exception)
0070     {
0071       if(Suppress)
0072       {
0073         return;
0074       }
0075       char* message = xercesc::XMLString::transcode(exception.getMessage());
0076       G4cout << "G4GDML: VALIDATION ERROR! " << message
0077              << " at line: " << exception.getLineNumber() << G4endl;
0078       xercesc::XMLString::release(&message);
0079     }
0080 
0081     void fatalError(const xercesc::SAXParseException& exception)
0082     {
0083       error(exception);
0084     }
0085     void resetErrors() {}
0086 
0087   private:
0088 
0089     G4bool Suppress = false;
0090 };
0091 
0092 class G4GDMLRead
0093 {
0094   public:
0095 
0096     virtual void DefineRead(const xercesc::DOMElement* const)           = 0;
0097     virtual void MaterialsRead(const xercesc::DOMElement* const)        = 0;
0098     virtual void SetupRead(const xercesc::DOMElement* const)            = 0;
0099     virtual void SolidsRead(const xercesc::DOMElement* const)           = 0;
0100     virtual void Paramvol_contentRead(const xercesc::DOMElement* const) = 0;
0101     virtual void Volume_contentRead(const xercesc::DOMElement* const)   = 0;
0102     virtual void StructureRead(const xercesc::DOMElement* const)        = 0;
0103     //
0104     // Pure virtual methods implemented in concrete reader plugin's classes
0105 
0106     virtual void ExtensionRead(const xercesc::DOMElement* const);
0107     //
0108     // To be implemented in the client code for handling extensions
0109     // to the GDML schema, identified with the tag "extension".
0110     // The implementation should be placed inside a user-class
0111     // inheriting from G4GDMLReadStructure and being registered
0112     // as argument to G4GDMLParser.
0113 
0114     virtual void UserinfoRead(const xercesc::DOMElement* const);
0115     //
0116     // Customisable by user to handle "userinfo" extensions to the
0117     // GDML schema, identified by the tag "userinfo".
0118 
0119     virtual G4LogicalVolume* GetVolume(const G4String&) const = 0;
0120     virtual G4String GetSetup(const G4String&)                = 0;
0121     //
0122     // More pure virtual methods implemented in the reader plugin.
0123 
0124     void Read(const G4String&, G4bool validation, G4bool isModule,
0125               G4bool strip = true);
0126     //
0127     // Main method for reading GDML files.
0128 
0129     void StripNames() const;
0130     void StripName(G4String&) const;
0131     //
0132     // Strip off pointers from entity IDs.
0133 
0134     const G4String& GetSchemaFile() const;
0135     void SetSchemaFile(const G4String& schemaFile);
0136     //
0137     // Set/Get alternative XML schema path/file for parsing validation.
0138 
0139     void OverlapCheck(G4bool);
0140     //
0141     // Activate/de-activate surface check for overlaps (default is off).
0142 
0143     const G4GDMLAuxListType* GetAuxList() const;
0144 
0145   protected:
0146 
0147     G4GDMLRead();
0148     virtual ~G4GDMLRead();
0149 
0150     G4String Transcode(const XMLCh* const);
0151     G4String GenerateName(const G4String& name, G4bool strip = false);
0152     G4String Strip(const G4String&) const;
0153     void GeneratePhysvolName(const G4String&, G4VPhysicalVolume*);
0154     void LoopRead(const xercesc::DOMElement* const,
0155                   void (G4GDMLRead::*)(const xercesc::DOMElement* const));
0156 
0157     G4GDMLAuxStructType AuxiliaryRead(const xercesc::DOMElement* const auxElem);
0158 
0159   protected:
0160 
0161     G4GDMLEvaluator eval;
0162     G4bool validate = true;
0163     G4bool check = false;
0164     G4bool dostrip = true;
0165     G4String schema = "";
0166 
0167   private:
0168 
0169     G4int inLoop = 0, loopCount = 0;
0170     G4GDMLAuxListType auxGlobalList;
0171 };
0172 
0173 #endif