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