Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4GeometryManager << 26 // >> 27 // $Id: G4GeometryManager.hh 66872 2013-01-15 01:25:57Z japost $ >> 28 // >> 29 // class G4GeometryManager 27 // 30 // 28 // Class description: 31 // Class description: 29 // 32 // 30 // A class responsible for high level geometri 33 // A class responsible for high level geometrical functions, and for 31 // high level objects in the geometry subdomai 34 // high level objects in the geometry subdomain. 32 // The class is a `singleton', with access via 35 // The class is a `singleton', with access via the static method 33 // G4GeometryManager::GetInstance(). 36 // G4GeometryManager::GetInstance(). 34 // 37 // 35 // Member data: 38 // Member data: 36 // 39 // 37 // - fgInstance << 40 // static G4GeometryManager* fgInstance 38 // Ptr to the unique instance of class (pe << 41 // - Ptr to the unique instance of class 39 42 40 // 26.07.95, P.Kent - Initial version, includi << 43 // Author: 41 // 12.06.24, J.Apostolakis - Added parallel op << 44 // 26.07.95 P.Kent Initial version, including optimisation Build 42 // ------------------------------------------- 45 // -------------------------------------------------------------------- 43 #ifndef G4GEOMETRYMANAGER_HH 46 #ifndef G4GEOMETRYMANAGER_HH 44 #define G4GEOMETRYMANAGER_HH 1 << 47 #define G4GEOMETRYMANAGER_HH 45 48 46 #include <vector> 49 #include <vector> 47 << 48 #include "G4Types.hh" 50 #include "G4Types.hh" 49 #include "G4SmartVoxelStat.hh" 51 #include "G4SmartVoxelStat.hh" 50 #include "G4ios.hh" << 51 52 52 class G4VPhysicalVolume; 53 class G4VPhysicalVolume; 53 class G4Timer; << 54 54 55 class G4GeometryManager 55 class G4GeometryManager 56 { 56 { 57 public: << 57 public: // with description 58 58 59 G4bool CloseGeometry(G4bool pOptimise = tr << 59 G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, 60 G4VPhysicalVolume* vo << 60 G4VPhysicalVolume* vol=0); 61 // Close (`lock') the geometry: perform 61 // Close (`lock') the geometry: perform sanity and `completion' checks 62 // and optionally [default=yes] build op 62 // and optionally [default=yes] build optimisation information. 63 // Applies to just a specific subtree if 63 // Applies to just a specific subtree if a physical volume is specified. 64 64 65 void OpenGeometry(G4VPhysicalVolume* vol = << 65 void OpenGeometry(G4VPhysicalVolume* vol=0); 66 // Open (`unlock') the geometry and remo 66 // Open (`unlock') the geometry and remove optimisation information if 67 // present. Applies to just a specific s 67 // present. Applies to just a specific subtree if a physical volume is 68 // specified. 68 // specified. 69 69 70 inline G4bool IsGeometryClosed() { return << 70 G4bool IsGeometryClosed(); 71 // Return true/false according to state << 71 // Return true/false according to state of optimised geoemtry. 72 72 73 void SetWorldMaximumExtent(G4double worldE 73 void SetWorldMaximumExtent(G4double worldExtent); 74 // Set the maximum extent of the world v 74 // Set the maximum extent of the world volume. The operation is 75 // allowed only if NO solids have been c 75 // allowed only if NO solids have been created already. 76 76 77 static G4GeometryManager* GetInstance(); 77 static G4GeometryManager* GetInstance(); 78 // Return ptr to singleton instance of t << 78 // Return ptr to singleton instance of the class. 79 // not existing. << 80 79 81 static G4GeometryManager* GetInstanceIfExi << 80 protected: 82 // Return ptr to singleton instance. << 83 << 84 void OptimiseInParallel(G4bool val = true) << 85 // Request optimisation using threads (i << 86 << 87 void UndertakeOptimisation(); << 88 // Method that contributes to (Voxel) op << 89 // Must be called by Worker thread initi << 90 // method. << 91 << 92 void RequestParallelOptimisation(G4bool va << 93 G4bool ve << 94 // Detailed method for user to request p << 95 // (if verbosity is required). Calling t << 96 // It will be used if Geant4 is built wi << 97 81 98 void ChooseSequentialOptimisation(G4bool v << 82 G4GeometryManager(); 99 // Simple way to avoid parallel optimisa << 100 << 101 G4bool IsParallelOptimisationConfigured(); << 102 // Check whether parallel optimisation w << 103 G4bool IsParallelOptimisationFinished(); << 104 // Report whether parallel optimisation << 105 << 106 ~G4GeometryManager(); << 107 // Destructor; called by G4RunManagerKer << 108 83 109 private: 84 private: 110 85 111 G4GeometryManager() = default; << 86 void BuildOptimisations(G4bool allOpt, G4bool verbose=false); 112 // Private constructor. Set the geometry << 113 << 114 G4bool BuildOptimisations(G4bool allOpt, G << 115 // Optimise all or just multi-volumes ( << 116 void BuildOptimisations(G4bool allOpt, G4V 87 void BuildOptimisations(G4bool allOpt, G4VPhysicalVolume* vol); 117 // Optimise one volume or subtree only. << 118 void DeleteOptimisations(); 88 void DeleteOptimisations(); 119 void DeleteOptimisations(G4VPhysicalVolume 89 void DeleteOptimisations(G4VPhysicalVolume* vol); 120 << 90 static void ReportVoxelStats( std::vector<G4SmartVoxelStat> & stats, 121 void ReportVoxelStats( std::vector<G4Smart << 91 G4double totalCpuTime ); 122 G4double totalCpuTi << 123 std::ostream &os = << 124 void ReportVoxelInfo(G4LogicalVolume * log << 125 << 126 void PrepareParallelOptimisation(G4bool al << 127 void BuildOptimisationsSequential(G4bool a << 128 << 129 // Methods for parallel initialization << 130 void CreateListOfVolumesToOptimise(G4bool << 131 // Build vector of relevant volumes. << 132 G4LogicalVolume* ObtainVolumeToOptimise(); << 133 << 134 void ConfigureParallelOptimisation(G4bool << 135 // Prepare for parallel optimisation. << 136 << 137 G4int ReportWorkerIsDoneOptimising(unsigne << 138 // Thread-safe method for worker to repo << 139 // It counts the number of workers that << 140 // It counts the number of volumes optim << 141 // reported, it results in a 'Finished' << 142 << 143 void InformOptimisationIsFinished(G4bool v << 144 // Returns true if all workers are finis << 145 << 146 void ResetListOfVolumesToOptimise(); << 147 // Resets (empties) the list of candidat << 148 // Must be called when Optimisation is f << 149 << 150 G4int CheckOptimisation(); << 151 // Check volumes marked to optimised are << 152 // that are missing voxel header. << 153 << 154 void WaitForVoxelisationFinish(G4bool verb << 155 // Wait until the voxelisation is all do << 156 << 157 private: << 158 << 159 static G4ThreadLocal G4GeometryManager* fg 92 static G4ThreadLocal G4GeometryManager* fgInstance; 160 G4bool fIsClosed = false; << 93 G4bool fIsClosed; 161 << 162 static std::vector<G4LogicalVolume*> fVolu << 163 // The list of volumes which threads nee << 164 static std::vector<G4LogicalVolume*>::cons << 165 // Iterator used by UndertakeOptimisatio << 166 << 167 static std::vector<G4SmartVoxelStat> fGlob << 168 // Statistics container shared by all wo << 169 << 170 // Flags for parallel initialization << 171 // --------------------------------- << 172 static G4bool fVerboseParallel; << 173 static G4bool fParallelVoxelOptimisationRe << 174 // Flag to register it was requested. << 175 static G4bool fOptimiseInParallelConfigure << 176 // Not just requested, but adopted (i.e. << 177 static G4bool fParallelVoxelOptimisationUn << 178 static G4bool fParallelVoxelOptimisationFi << 179 static G4bool fUsingExistingWorkers; // Ca << 180 << 181 // Statistics for parallel Optimisation - << 182 // ------------------------------------ << 183 static G4double fSumVoxelTime; << 184 static G4int fNumberThreadsReporting; << 185 static unsigned int fTotalNumberVolumesOpt << 186 // Counters. << 187 << 188 // For Wall Clock time in parallel mode .. << 189 // << 190 static G4Timer* fWallClockTimer; // Owne << 191 static G4bool fWallClockStarted; << 192 }; 94 }; 193 95 194 #endif 96 #endif 195 97