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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 // G4RunManagerKernel
 27 //
 28 // Class description:
 29 //
 30 // This is a class for mandatory control of the Geant4 kernel.
 31 //
 32 // This class is constructed by G4RunManager. If a user adopts his/her own
 33 // class instead of G4RunManager, this class must be instantiated by at the
 34 // very beginning of the application and must be deleted at the very end.
 35 // In addition, the following methods must be invoked in the proper order:
 36 //   DefineWorldVolume()
 37 //   InitializePhysics()
 38 //   RunInitialization()
 39 //   RunTermination()
 40 //
 41 // User must provide his/her own classes derived from the following abstract
 42 // class and register it to G4RunManagerKernel:
 43 //   G4VUserPhysicsList - Particle types, Processes and Cuts
 44 //
 45 // G4RunManagerKernel does not have any event loop. Handling of events
 46 // is managed by G4RunManager.
 47 
 48 // Author: M.Asai, 1 August 2003
 49 // --------------------------------------------------------------------
 50 #ifndef G4RunManagerKernel_hh
 51 #define G4RunManagerKernel_hh 1
 52 
 53 #include "G4EventManager.hh"
 54 #include "globals.hh"
 55 
 56 class G4VUserPhysicsList;
 57 class G4VPhysicalVolume;
 58 class G4Region;
 59 class G4ExceptionHandler;
 60 class G4StackManager;
 61 class G4TrackingManager;
 62 class G4PrimaryTransformer;
 63 
 64 class G4RunManagerKernel
 65 {
 66   public:
 67     // Static method returning the singleton pointer of
 68     // G4RunManagerKernel or its derived class.
 69     static G4RunManagerKernel* GetRunManagerKernel();
 70 
 71     // The constructor and the destructor. The user must construct this class
 72     // object at the beginning of his/her main() and must delete it at the
 73     // bottom of the main(), unless he/she used G4RunManager.
 74     G4RunManagerKernel();
 75     virtual ~G4RunManagerKernel();
 76 
 77     void DefineWorldVolume(G4VPhysicalVolume* worldVol, G4bool topologyIsChanged = true);
 78 
 79     // This method must be invoked if the geometry setup has been changed
 80     // between runs. The flag "topologyIsChanged" will specify if the
 81     // geometry topology is different from the original one used in the
 82     // previous run; if not, it must be set to false, so that the original
 83     // optimisation and navigation history is preserved. This method is
 84     // invoked also at initialisation.
 85     void WorkerDefineWorldVolume(G4VPhysicalVolume* worldVol, G4bool topologyIsChanged = true);
 86 
 87     // This method must be invoked at least once with a valid concrete
 88     // implementation of user physics list.
 89     void SetPhysics(G4VUserPhysicsList* uPhys);
 90 
 91     // This method must be invoked at least once to build physics processes.
 92     void InitializePhysics();
 93 
 94     // Trigger geometry closing and physics table constructions.
 95     // It returns TRUE if all procedures went well.
 96     G4bool RunInitialization(G4bool fakeRun = false);
 97 
 98     // Set the application state to 'Idle' so that the user can modify
 99     // physics/geometry.
100     void RunTermination();
101 
102     // Update region list. This method is mandatory before invoking the
103     // following two dump methods.
104     // At RunInitialization(), this method is automatically invoked.
105     void UpdateRegion();
106 
107     // Dump information of a region.
108     void DumpRegion(const G4String& rname) const;
109 
110     // Dump information of a region.
111     // If the pointer is NULL, all regions are shown.
112     void DumpRegion(G4Region* region = nullptr) const;
113 
114     void WorkerUpdateWorldVolume();
115 
116     // This method must be invoked (or equivalent UI commands can be used)
117     // in case the user changes his/her detector geometry.
118     // This method is automatically invoked from DefineWorldVolume().
119     inline void GeometryHasBeenModified() { geometryNeedsToBeClosed = true; }
120 
121     // This method must be invoked in case the user changes his/her physics
122     // process(es), e.g. (in)activate some processes. Once this method is
123     // invoked, regardless of cuts changed or not, BuildPhysicsTable() of
124     // a PhysicsList is invoked for refreshing all physics tables.
125     inline void PhysicsHasBeenModified() { physicsNeedsToBeReBuilt = true; }
126 
127     inline G4EventManager* GetEventManager() const { return eventManager; }
128     inline G4StackManager* GetStackManager() const { return eventManager->GetStackManager(); }
129     inline G4TrackingManager* GetTrackingManager() const
130     {
131       return eventManager->GetTrackingManager();
132     }
133     inline void SetPrimaryTransformer(G4PrimaryTransformer* pt)
134     {
135       eventManager->SetPrimaryTransformer(pt);
136     }
137     inline G4PrimaryTransformer* GetPrimaryTransformer() const
138     {
139       return eventManager->GetPrimaryTransformer();
140     }
141 
142     inline const G4String& GetVersionString() const { return versionString; }
143 
144     inline void SetVerboseLevel(G4int vl) { verboseLevel = vl; }
145 
146     inline void SetGeometryToBeOptimized(G4bool vl)
147     {
148       if (geometryToBeOptimized != vl) {
149         geometryToBeOptimized = vl;
150         geometryNeedsToBeClosed = true;
151       }
152     }
153   
154     inline void ResetNavigatorAtInitialization(G4bool val=true)
155     { resetNavigatorAtInitialization = val; }
156 
157     inline G4int GetNumberOfParallelWorld() const { return numberOfParallelWorld; }
158     inline void SetNumberOfParallelWorld(G4int i) { numberOfParallelWorld = i; }
159 
160     inline G4VUserPhysicsList* GetPhysicsList() const { return physicsList; }
161 
162     inline G4VPhysicalVolume* GetCurrentWorld() const { return currentWorld; }
163 
164     inline G4int GetNumberOfStaticAllocators() const { return numberOfStaticAllocators; }
165 
166     enum RMKType
167     {
168       sequentialRMK,
169       masterRMK,
170       workerRMK
171     };
172 
173   protected:
174     // Constructor to be used by derived classes.
175     G4RunManagerKernel(RMKType rmkType);
176 
177     // Called by DefineWorldVolume().
178     void SetupDefaultRegion();
179     void SetupPhysics();
180     void ResetNavigator();
181     void BuildPhysicsTables(G4bool fakeRun);
182     void CheckRegions();
183 
184     // This method will setup the G4VProcesses instances to have a reference
185     // to the process instance created by the master thread.
186     // See G4VProcess::GetMasterProcess().
187     virtual void SetupShadowProcess() const;
188 
189     void PropagateGenericIonID();
190 
191   private:
192     void CheckRegularGeometry();
193     G4bool ConfirmCoupledTransportation();
194     void SetScoreSplitter();
195 
196   protected:
197     RMKType runManagerKernelType;
198     G4Region* defaultRegion = nullptr;
199     G4Region* defaultRegionForParallelWorld = nullptr;
200     G4bool geometryNeedsToBeClosed = true;
201 
202   private:
203     G4VUserPhysicsList* physicsList = nullptr;
204     G4VPhysicalVolume* currentWorld = nullptr;
205     G4bool geometryInitialized = false;
206     G4bool physicsInitialized = false;
207     G4bool geometryToBeOptimized = true;
208     G4bool physicsNeedsToBeReBuilt = true;
209     G4int verboseLevel = 0;
210     G4int numberOfParallelWorld = 0;
211 
212     G4EventManager* eventManager = nullptr;
213     G4ExceptionHandler* defaultExceptionHandler = nullptr;
214     G4String versionString = "";
215 
216     static G4ThreadLocal G4RunManagerKernel* fRunManagerKernel;
217 
218     G4int numberOfStaticAllocators = 0;
219 
220     G4bool resetNavigatorAtInitialization = false;
221 };
222 
223 #endif
224