Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-18 09:14:53

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 // G4GeometryManager
0027 //
0028 // Class description:
0029 //
0030 // A class responsible for high level geometrical functions, and for
0031 // high level objects in the geometry subdomain.
0032 // The class is a 'singleton', with access via the static method
0033 // G4GeometryManager::GetInstance().
0034 
0035 // Author: Paul Kent (CERN), 26.07.1995 - Initial version
0036 //         John Apostolakis (CERN), 12.06.2024 - Added parallel optimisation
0037 // --------------------------------------------------------------------
0038 #ifndef G4GEOMETRYMANAGER_HH
0039 #define G4GEOMETRYMANAGER_HH
0040 
0041 #include <vector>
0042 
0043 #include "G4Types.hh"
0044 #include "G4SmartVoxelStat.hh"
0045 #include "G4ios.hh"
0046 
0047 class G4VPhysicalVolume;
0048 class G4Timer;
0049 class G4VoxelisationHelper;
0050 
0051 /**
0052  * @brief G4GeometryManager is a singleton class responsible for high level
0053  * geometrical functions, and for high level objects in the geometry subdomain.
0054  */
0055 
0056 class G4GeometryManager
0057 {
0058   public:
0059   
0060     /**
0061      * Destructor; called by G4RunManagerKernel.
0062      */
0063     ~G4GeometryManager();
0064 
0065     /**
0066      * Returns a pointer to the singleton instance of the class, creating
0067      * it if not existing.
0068      */
0069     static G4GeometryManager* GetInstance();
0070 
0071     /**
0072      * Simply returns a pointer to the singleton instance.
0073      */
0074     static G4GeometryManager* GetInstanceIfExist();
0075 
0076     /**
0077      * Closes ('locks') the geometry: performs sanity and 'completion' checks
0078      * and optionally [default=yes] builds the optimisation structure.
0079      * Applies to just a specific subtree if a physical volume is specified.
0080      *  @param[in] pOptimise Flag to enabling/disabling optimisation structure.
0081      *  @param[in] verbose Flag for verbosity.
0082      *  @param[in] vol Optional pointer to a physical volume (subtree) for
0083      *             optimisation.
0084      *  @returns true if process succeeds.
0085      */
0086     G4bool CloseGeometry(G4bool pOptimise = true,
0087                          G4bool verbose = false,
0088                          G4VPhysicalVolume* vol = nullptr);
0089  
0090     /**
0091      * Opens ('unlocks') the geometry and removes the optimisation structure if
0092      * present. Applies to just a specific subtree if a physical volume is
0093      * specified.
0094      *  @param[in] vol Optional pointer to a physical volume (subtree) for
0095      *             optimisation.
0096      */
0097     void OpenGeometry(G4VPhysicalVolume* vol = nullptr);
0098 
0099     /**
0100      * Returns true/false according to the state of the optimised geometry.
0101      */
0102     G4bool IsGeometryClosed();
0103 
0104     /**
0105      * Sets the maximum extent of the world volume.
0106      * The operation is allowed only if NO solids have been created already.
0107      */
0108     void SetWorldMaximumExtent(G4double worldExtent);
0109 
0110     // Methods to choose or undertake Parallel Optimisation
0111     // ----------------------------------------------------
0112 
0113     /**
0114      * Requests optimisation using threads (if MT is enabled & used ).
0115      */
0116     void OptimiseInParallel(G4bool val = true);
0117   
0118     /**
0119      * Method that contributes to (voxel) optimisation until all work is done.
0120      * To be called by a worker thread initialisation - not by the user.
0121      */
0122     void UndertakeOptimisation();
0123 
0124     /**
0125      * Detailed method for user to request parallel optimisation (if verbosity
0126      * is required). Calling this method is enough to ask for it.
0127      * It will be used if Geant4 is built with MT/tasks.
0128      * Parallelism will be used if Geant4 is built with MT/tasks.
0129      */
0130     void RequestParallelOptimisation(G4bool val = true, G4bool verbose = true);
0131 
0132     /**
0133      * Checks whether parallel optimisation was requested and configured.
0134      */
0135     G4bool IsParallelOptimisationConfigured();
0136 
0137     /**
0138      * Reports whether parallel optimisation was completed.
0139      */
0140     G4bool IsParallelOptimisationFinished();
0141 
0142   private:
0143 
0144     /**
0145      * Private Constructor. Set the geometry to be open.
0146      */
0147     G4GeometryManager();
0148 
0149     // Create the voxel optimisation information. Return whether work is completed
0150     // (In case of parallel optimisation, it will be done later by the workers)
0151 
0152     /**
0153      * Optimises all volumes or just multi-volumes (parameterisations, etc. ).
0154      */
0155     G4bool BuildOptimisations(G4bool allOpt, G4bool verbose = false);  
0156 
0157     /**
0158      * Optimises one volume or subtree only.
0159      */
0160     G4bool BuildOptimisations(G4bool allOpt, G4VPhysicalVolume* vol);
0161 
0162     /**
0163      * Builds the optimisation structure in sequential mode.
0164      */
0165     void BuildOptimisationsSequential(G4bool allOpts, G4bool verbose = true);
0166 
0167     /**
0168      * Methods to delete the optimisation structure.
0169      */
0170     void DeleteOptimisations();
0171     void DeleteOptimisations(G4VPhysicalVolume* vol);
0172 
0173   private:
0174 
0175     /** The static instance. */
0176     static G4ThreadLocal G4GeometryManager* fgInstance;
0177 
0178     /** Pointer to the voxelisation helper. */
0179     static G4VoxelisationHelper* fParallelVoxeliser;
0180 
0181     G4bool fIsClosed = false;
0182 
0183     // Flags for parallel initialization
0184     // ---------------------------------
0185     static G4bool fParallelVoxelOptimisationRequested;
0186    
0187     /** Not just requested, but adopted (i.e. also in MT/tasking mode). */
0188     static G4bool fOptimiseInParallelConfigured;
0189 };
0190 
0191 #endif