Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:29

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 // G4WorkerRunManager
0027 //
0028 // Class description:
0029 //
0030 // This is a class for run control in GEANT4 for multi-threading.
0031 // It extends G4RunManager re-implementing multi-threaded behavior in
0032 // key methods. See documentation for G4RunManager.
0033 // User should never initialize instances of this class, that are usually
0034 // handled by G4MTRunManager. There exists one instance of this class for
0035 // each worker in a MT application.
0036 
0037 // Original authors: X.Dong, A.Dotti - 2013
0038 // --------------------------------------------------------------------
0039 #ifndef G4WorkerRunManager_hh
0040 #define G4WorkerRunManager_hh 1
0041 
0042 #include "G4RNGHelper.hh"
0043 #include "G4RunManager.hh"
0044 
0045 class G4WorkerThread;
0046 class G4WorkerRunManagerKernel;
0047 
0048 class G4WorkerRunManager : public G4RunManager
0049 {
0050   public:
0051     using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Run>;
0052 
0053   public:
0054     static G4WorkerRunManager* GetWorkerRunManager();
0055     static G4WorkerRunManagerKernel* GetWorkerRunManagerKernel();
0056 
0057     G4WorkerRunManager();
0058     ~G4WorkerRunManager() override;
0059 
0060     void InitializeGeometry() override;
0061     void RunInitialization() override;
0062     void DoEventLoop(G4int n_event, const char* macroFile = nullptr, G4int n_select = -1) override;
0063     void ProcessOneEvent(G4int i_event) override;
0064     G4Event* GenerateEvent(G4int i_event) override;
0065 
0066     void RunTermination() override;
0067     void TerminateEventLoop() override;
0068 
0069     // This function is called by the thread function: it should
0070     // loop until some work is requested.
0071     virtual void DoWork();
0072 
0073     // Sets the worker context.
0074     inline void SetWorkerThread(G4WorkerThread* wc) { workerContext = wc; }
0075 
0076     void SetUserInitialization(G4VUserPhysicsList* userInit) override;
0077     void SetUserInitialization(G4VUserDetectorConstruction* userInit) override;
0078     void SetUserInitialization(G4VUserActionInitialization* userInit) override;
0079     void SetUserInitialization(G4UserWorkerInitialization* userInit) override;
0080     void SetUserInitialization(G4UserWorkerThreadInitialization* userInit) override;
0081     void SetUserAction(G4UserRunAction* userAction) override;
0082     void SetUserAction(G4VUserPrimaryGeneratorAction* userAction) override;
0083     void SetUserAction(G4UserEventAction* userAction) override;
0084     void SetUserAction(G4UserStackingAction* userAction) override;
0085     void SetUserAction(G4UserTrackingAction* userAction) override;
0086     void SetUserAction(G4UserSteppingAction* userAction) override;
0087 
0088     void RestoreRndmEachEvent(G4bool flag) override { readStatusFromFile = flag; }
0089 
0090   protected:
0091     void ConstructScoringWorlds() override;
0092     void StoreRNGStatus(const G4String& filenamePrefix) override;
0093     void rndmSaveThisRun() override;
0094     void rndmSaveThisEvent() override;
0095 
0096     // This method will merge (reduce) the results
0097     // of this run into the global run
0098     virtual void MergePartialResults();
0099 
0100   protected:
0101     G4WorkerThread* workerContext = nullptr;
0102 #ifdef G4MULTITHREADED
0103     G4bool visIsSetUp = false;
0104 #endif
0105 
0106     G4bool eventLoopOnGoing = false;
0107     G4bool runIsSeeded = false;
0108     G4int nevModulo = -1;
0109     G4int currEvID = -1;
0110     G4int luxury = -1;
0111     G4SeedsQueue seedsQueue;
0112     G4bool readStatusFromFile = false;
0113 
0114   private:
0115     void SetupDefaultRNGEngine();
0116 
0117   private:
0118     std::unique_ptr<ProfilerConfig> workerRunProfiler;
0119 };
0120 
0121 #endif  // G4WorkerRunManager_hh