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);
184 void IncludeMacroFile(std::string filename) { fMacroFilesOrContents.emplace_back(filename); }
190 void RegisterG4Alias(std::string alias, std::string value) { fG4Aliases.emplace(alias, value); }
254 fProcessNumber = proc_num;
255 fMultiProcessing =
true;
263 return fExceptionHandler->HadWarning() || RMGLog::HadWarning();
270 return fExceptionHandler->HadError() || RMGLog::HadError();
286 if (!fAbortRun.is_lock_free())
return;
297 void SetUpDefaultG4RunManager(G4RunManagerType type = G4RunManagerType::Default);
298 void SetUpDefaultG4VisManager();
299 void SetUpDefaultDetectorConstruction();
300 void SetUpDefaultProcessesList();
301 void SetUpDefaultUserAction();
302 void CheckRandEngineMTState();
304 std::unique_ptr<G4UIExecutive> StartInteractiveSession();
306 std::string fApplicationName;
309 std::map<std::string, std::string> fG4Aliases;
310 std::vector<std::string> fMacroFilesOrContents;
311 bool fInteractive =
false;
312 int fPrintModulo = -1;
314 int fProcessNumber = 0;
315 bool fMultiProcessing =
false;
317 bool fIsRandControlled =
false;
318 bool fIsRandControlledAtEngineChange =
false;
319 std::string fRandEngineName;
322 static std::atomic<bool> fAbortRun;
324 std::unique_ptr<G4RunManager> fG4RunManager =
nullptr;
325 std::unique_ptr<G4VisManager> fG4VisManager =
nullptr;
333 std::shared_ptr<RMGUserInit> fUserInit;
336 std::unique_ptr<G4GenericMessenger> fMessenger;
337 std::unique_ptr<G4GenericMessenger> fLogMessenger;
338 std::unique_ptr<G4GenericMessenger> fRandMessenger;
339 void DefineCommands();
Geant4 exception handler that records whether warnings/errors have occurred.
Definition RMGExceptionHandler.hh:27
Definition RMGHardware.hh:39
@ fatal
Print only errors, stop execution.
Definition RMGLog.hh:73
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:253
void SetRandEngineInternalSeed(int index)
Sets the internal seed index for the random engine.
Definition RMGManager.cc:338
void IncludeMacroFile(std::string filename)
Includes a macro or single macro command file for execution.
Definition RMGManager.hh:184
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:190
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:290
void ActivateOptionalOutputScheme(std::string name)
Activates an optional output scheme.
Definition RMGManager.hh:278
bool GetRandIsControlled() const
Checks if the random engine is under user controlled seeding.
Definition RMGManager.hh:236
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:269
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:356
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:262
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:285
void SetRandEngineSeed(int seed)
Sets the seed for the random engine.
Definition RMGManager.cc:319
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:293
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:241
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:178
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:280
static RMGOutputManager * Instance()
Gets the singleton instance of RMGOutputManager.
Definition RMGOutputManager.hh:56
Action initialization assembling all remage user actions.
Definition RMGUserAction.hh:29