16#ifndef _RMG_MANAGER_HH_
17#define _RMG_MANAGER_HH_
24#include "G4RunManager.hh"
25#include "G4RunManagerFactory.hh"
26#include "G4Threading.hh"
27#include "G4VisManager.hh"
30#include "RMGExceptionHandler.hh"
32#include "RMGOutputManager.hh"
33#include "RMGUserInit.hh"
51 RMGManager() =
delete;
59 RMGManager(std::string app_name,
int argc,
char** argv);
65 RMGManager(RMGManager
const&) =
delete;
66 RMGManager& operator=(RMGManager
const&) =
delete;
67 RMGManager(RMGManager&&) =
delete;
68 RMGManager& operator=(RMGManager&&) =
delete;
75 static RMGManager*
Instance() {
return fRMGManager; }
117 return fG4RunManager->GetRunManagerType() == G4RunManager::RMType::sequentialRM;
128 RMGLog::OutDev(
RMGLog::fatal,
"wrong setup for process-based parallelization.");
129 return fProcessNumber;
146 fG4RunManager = std::unique_ptr<G4RunManager>(g4_manager);
188 void IncludeMacroFile(std::string filename) { fMacroFilesOrContents.emplace_back(filename); }
194 void RegisterG4Alias(std::string alias, std::string value) { fG4Aliases.emplace(alias, value); }
258 fProcessNumber = proc_num;
259 fMultiProcessing =
true;
267 return fExceptionHandler->HadWarning() || RMGLog::HadWarning();
274 return fExceptionHandler->HadError() || RMGLog::HadError();
290 if (!fAbortRun.is_lock_free()) {
306 void SetUpDefaultG4RunManager(G4RunManagerType type = G4RunManagerType::Default);
307 void SetUpDefaultG4VisManager();
308 void SetUpDefaultDetectorConstruction();
309 void SetUpDefaultProcessesList();
310 void SetUpDefaultUserAction();
311 void CheckRandEngineMTState();
313 std::unique_ptr<G4UIExecutive> StartInteractiveSession();
315 std::string fApplicationName;
318 std::map<std::string, std::string> fG4Aliases;
319 std::vector<std::string> fMacroFilesOrContents;
320 bool fInteractive =
false;
321 int fPrintModulo = -1;
323 int fProcessNumber = 0;
324 bool fMultiProcessing =
false;
326 bool fIsRandControlled =
false;
327 bool fIsRandControlledAtEngineChange =
false;
328 std::string fRandEngineName;
331 static std::atomic<bool> fAbortRun;
333 std::unique_ptr<G4RunManager> fG4RunManager =
nullptr;
334 std::unique_ptr<G4VisManager> fG4VisManager =
nullptr;
342 std::shared_ptr<RMGUserInit> fUserInit;
345 std::unique_ptr<G4GenericMessenger> fMessenger;
346 std::unique_ptr<G4GenericMessenger> fLogMessenger;
347 std::unique_ptr<G4GenericMessenger> fRandMessenger;
348 void DefineCommands();
Geant4 exception handler that records whether warnings/errors have occurred.
Definition RMGExceptionHandler.hh:29
Definition RMGHardware.hh:39
@ error
Print only errors.
Definition RMGLog.hh:72
@ fatal
Print only errors, stop execution.
Definition RMGLog.hh:73
static void Out(RMGLog::LogLevel loglevel, const T &message)
Main manager class for the remage simulation.
Definition RMGManager.hh:47
G4RunManager * GetG4RunManager()
Retrieves the Geant4 run manager.
Definition RMGManager.cc:251
void Run()
Executes the supplied macro files and commands and switch to interactive session if requested.
Definition RMGManager.cc:140
void EnableMultiProcessing(int proc_num)
Sets the process number for offset calculations in process-parallelized mode.
Definition RMGManager.hh:257
void SetRandEngineInternalSeed(int index)
Sets the internal seed index for the random engine.
Definition RMGManager.cc:340
void IncludeMacroFile(std::string filename)
Includes a macro or single macro command file for execution.
Definition RMGManager.hh:188
auto GetOutputManager() const
Retrieves the output manager.
Definition RMGManager.hh:105
void SetUserInit(G4VUserPhysicsList *proc)
Sets the physics list.
Definition RMGManager.hh:162
void RegisterG4Alias(std::string alias, std::string value)
Registers a Geant4 alias for use in macro commands.
Definition RMGManager.hh:194
void SetLogLevel(std::string level)
Sets the logging level.
Definition RMGManager.cc:271
~RMGManager()=default
Default destructor.
bool ApplyRandEngineForCurrentThread()
Applies the random engine settings for the current thread.
Definition RMGManager.cc:292
void ActivateOptionalOutputScheme(std::string name)
Activates an optional output scheme.
Definition RMGManager.hh:282
bool GetRandIsControlled() const
Checks if the random engine is under user controlled seeding.
Definition RMGManager.hh:240
int GetPrintModulo() const
Returns the print modulo value.
Definition RMGManager.hh:110
RMGHardware * GetDetectorConstruction()
Retrieves the detector construction.
Definition RMGManager.cc:261
bool HadError() const
Checks if any errors have been recorded.
Definition RMGManager.hh:273
void SetUserInit(G4VisManager *vis)
Sets the Geant4 visualization manager.
Definition RMGManager.hh:152
void SetInteractive(bool flag=true)
Enables or disables interactive mode.
Definition RMGManager.hh:168
void SetRandSystemEntropySeed()
Sets the random engine seed using system entropy.
Definition RMGManager.cc:358
bool IsExecSequential() const
Checks if the execution is sequential (single-threaded).
Definition RMGManager.hh:116
void SetUserInit(RMGHardware *det)
Sets the detector construction.
Definition RMGManager.hh:157
void Initialize()
Initialize the simulation components (run manager, visualization, random engine, detector constructio...
Definition RMGManager.cc:82
bool HadWarning() const
Checks if any warnings have been recorded.
Definition RMGManager.hh:266
void SetNumberOfThreads(int nthreads)
Sets the number of threads.
Definition RMGManager.hh:173
static void AbortRunGracefully()
Set a flag to gracefully aborts the simulation run at the next possible time.
Definition RMGManager.hh:289
void SetRandEngineSeed(int seed)
Sets the seed for the random engine.
Definition RMGManager.cc:321
bool IsMultiProcessing() const
Checks if the execution is part of a process-parallelized run.
Definition RMGManager.hh:138
static bool ShouldAbortRun()
Checks whether an abort signal has been triggered.
Definition RMGManager.hh:302
auto GetUserInit() const
Retrieves the user initialization object.
Definition RMGManager.hh:100
static RMGManager * Instance()
Retrieves the singleton instance of RMGManager.
Definition RMGManager.hh:75
int GetProcessNumberOffset() const
Gets the process number offset.
Definition RMGManager.hh:126
bool GetRandEngineSelected() const
Checks if a random engine has been selected by the user.
Definition RMGManager.hh:245
int GetNumberOfThreads() const
Returns the number of threads.
Definition RMGManager.hh:177
G4VUserPhysicsList * GetProcessesList()
Retrieves the physics list.
Definition RMGManager.cc:266
G4VisManager * GetG4VisManager()
Retrieves the Geant4 visualization manager.
Definition RMGManager.cc:256
void SetPrintModulo(int n_ev)
Sets the print modulo value.
Definition RMGManager.hh:182
void SetUserInit(G4RunManager *g4_manager)
Sets the Geant4 run manager.
Definition RMGManager.hh:145
void SetRandEngine(std::string name)
Sets the random engine by name.
Definition RMGManager.cc:282
static RMGOutputManager * Instance()
Gets the singleton instance of RMGOutputManager.
Definition RMGOutputManager.hh:56
Action initialization assembling all remage user actions.
Definition RMGUserAction.hh:29