16#ifndef _RMG_USER_INIT_HH_
17#define _RMG_USER_INIT_HH_
26#include "G4UserSteppingAction.hh"
27#include "G4UserTrackingAction.hh"
30#include "RMGVGenerator.hh"
31#include "RMGVOutputScheme.hh"
96 Add<T>(&fSteppingActions, std::forward<Args>(args)...);
106 Add<T>(&fTrackingActions, std::forward<Args>(args)...);
116 Add<T>(&fOutputSchemes, std::forward<Args>(args)...);
128 template<
typename T,
typename... Args>
130 Add<T>(&fOptionalOutputSchemes, name, std::forward<Args>(args)...);
140 Set<T>(fUserGenerator, std::forward<Args>(args)...);
168 template<
typename T>
using late_init_fn = std::function<std::unique_ptr<T>()>;
169 template<
typename T>
using late_init_vec = std::vector<late_init_fn<T>>;
170 template<
typename K,
typename T>
using late_init_map = std::map<K, late_init_fn<T>>;
172 template<
typename B,
typename T,
typename... Args> late_init_fn<B> CreateInit(Args&&... args) {
173 return std::bind(&std::make_unique<T, Args&...>, std::forward<Args>(args)...);
175 template<
typename B,
typename T> late_init_fn<B> CreateInit() {
176 return [] {
return std::make_unique<T>(); };
179 template<
typename T,
typename B,
typename... Args>
180 void Add(late_init_vec<B>* vec, Args&&... args) {
181 static_assert(std::is_base_of<B, T>::value);
184 auto create = CreateInit<B, T>(std::forward<Args>(args)...);
185 vec->emplace_back(std::move(create));
187 template<
typename T,
typename B,
typename K,
typename... Args>
188 void Add(late_init_map<K, B>* map, K k, Args&&... args) {
189 static_assert(std::is_base_of<B, T>::value);
192 auto create = CreateInit<B, T>(std::forward<Args>(args)...);
193 map->emplace(k, std::move(create));
195 template<
typename T,
typename B,
typename... Args>
196 void Set(late_init_fn<B>& fn, Args&&... args) {
197 static_assert(std::is_base_of<B, T>::value);
200 auto create = CreateInit<B, T>(std::forward<Args>(args)...);
205 late_init_vec<G4UserSteppingAction> fSteppingActions;
206 late_init_vec<G4UserTrackingAction> fTrackingActions;
207 late_init_vec<RMGVOutputScheme> fOutputSchemes;
208 late_init_map<std::string, RMGVOutputScheme> fOptionalOutputSchemes;
209 late_init_fn<RMGVGenerator> fUserGenerator;
211 std::vector<std::string> fActivatedOutputScheme;
auto GetTrackingActions() const
Retrieves the collection of tracking actions.
Definition RMGUserInit.hh:71
void SetUserGenerator(Args &&... args)
Sets the user generator to an instance of type T.
Definition RMGUserInit.hh:139
void AddOptionalOutputScheme(std::string name, Args &&... args)
Adds an optional output scheme of type T with a given name.
Definition RMGUserInit.hh:129
void AddSteppingAction(Args &&... args)
Adds a stepping action of type T.
Definition RMGUserInit.hh:95
void AddTrackingAction(Args &&... args)
Adds a tracking action of type T.
Definition RMGUserInit.hh:105
auto GetOptionalOutputSchemes() const
Retrieves the optional output schemes.
Definition RMGUserInit.hh:81
auto GetUserGenerator() const
Retrieves the user generator.
Definition RMGUserInit.hh:86
~RMGUserInit()=default
Default destructor.
auto GetOutputSchemes() const
Retrieves the registered output schemes.
Definition RMGUserInit.hh:76
bool IsOptionalOutputSchemeActivated(std::string name)
Check whether the optional output scheme is activated.
Definition RMGUserInit.cc:51
void RegisterDefaultOptionalOutputSchemes()
Registers the default optional output schemes.
Definition RMGUserInit.cc:26
void ActivateOptionalOutputScheme(std::string name)
Activates an optional output scheme by its name.
Definition RMGUserInit.cc:36
auto GetSteppingActions() const
Retrieves the collection of stepping actions.
Definition RMGUserInit.hh:66
void AddOutputScheme(Args &&... args)
Adds an output scheme of type T.
Definition RMGUserInit.hh:115
RMGUserInit()=default
Default constructor.