GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSGeneratorActionsManager.cpp
1 /*
2  * GGSGeneratorActionsManager.cpp
3  *
4  * Created on: 09 Oct 2013
5  * Author: Nicola Mori
6  */
7 
8 #include "montecarlo/generators/manager/GGSGeneratorActionsManager.h"
10 #include "utils/GGSSmartLog.h"
11 
12 #include <iostream>
13 
14 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
15 
16 GGSGeneratorActionsManager &GGSGeneratorActionsManager::GetInstance() {
17  static GGSGeneratorActionsManager instance;
18  return instance;
19 }
20 
21 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
22 
23 GGSGeneratorActionsManager::GGSGeneratorActionsManager()
24  : _messenger(new G4GenericMessenger(this, "/GGS/generatorActions/")), _candidates("") {
25  _commandSet =
26  &(_messenger->DeclareMethod("set", &GGSGeneratorActionsManager::SetGeneratorAction, "Set the particle generator")
27  .SetStates(G4State_Idle));
28 }
29 
30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31 
32 GGSGeneratorActionsManager::~GGSGeneratorActionsManager() { delete _messenger; }
33 
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
35 
36 void GGSGeneratorActionsManager::RegisterGABuilder(const G4String &name,
37  G4VUserPrimaryGeneratorAction *(*genBuilder)()) {
38  static const std::string routineName("GGSGeneratorActionsManager::RegisterGABuilder");
39  std::pair<GenBuildersMap::iterator, bool> insertResult =
40  _buildersMap.insert(std::pair<G4String, G4VUserPrimaryGeneratorAction *(*)()>(name, genBuilder));
41  if (!insertResult.second) {
42  COUT(WARNING) << "Generator " << name << " is already present." << ENDL;
43  } else {
44  _candidates.append(" ").append(name);
45  _commandSet->SetCandidates(_candidates);
46  }
47 }
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
51 void GGSGeneratorActionsManager::SetGeneratorAction(const G4String &name) {
52 
53  static const std::string routineName("GGSGeneratorActionsManager::SetGenerator");
54 
55  // Retrieve the generator builder
56  GenBuildersMap::iterator builder = _buildersMap.find(name);
57  if (builder == _buildersMap.end()) {
58  COUT(WARNING) << "Wuilder for generator " << name << " is not present." << ENDL;
59  return;
60  }
61 
62  // Build the generator
63  G4VUserPrimaryGeneratorAction *gen = builder->second();
64 
65  // Add to the run manager
66  if (GGSRunManager::GetRunManager()->GetUserPrimaryGeneratorAction())
67  delete GGSRunManager::GetRunManager()->GetUserPrimaryGeneratorAction();
69 }
#define ENDL
Definition: GGSSmartLog.h:105
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
void SetGGSGeneratorAction(G4VUserPrimaryGeneratorAction *userAction)
Replacement of the SetUserAction method.
Definition: GGSRunManager.h:65
static GGSRunManager * GetRunManager()
Static getter function the run manager.