SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
PluginMessenger.cc
Go to the documentation of this file.
1 #include "PluginMessenger.hh"
2 
3 namespace slic {
4 
6  pluginManager_(thePluginManager) {
7 
8  pluginDir_ = new G4UIdirectory("/slic/plugins/");
9  pluginDir_->SetGuidance("Commands for controlling LDMX sim plugins");
10 
11  loadCmd_ = new G4UIcommand("/slic/plugins/load", this);
12  loadCmd_->AvailableForStates(G4ApplicationState::G4State_PreInit, G4ApplicationState::G4State_Idle);
13  loadCmd_->SetGuidance("Load a sim plugin from a shared library. A plugin of a specific type may only be loaded once.");
14  G4UIparameter* pluginName = new G4UIparameter("pluginName", 's', false);
15  pluginName->SetGuidance("Name of plugin to load.");
16  loadCmd_->SetParameter(pluginName);
17  G4UIparameter* libName = new G4UIparameter("libName", 's', true);
18  libName->SetGuidance("Name of plugin library; if omitted will use the 'libSimPlugins.so' library.");
19  loadCmd_->SetParameter(libName);
20 
21  destroyCmd_ = new G4UIcommand("/slic/plugins/destroy", this);
22  destroyCmd_->SetGuidance("Destroy a loaded plugin by name.");
23  destroyCmd_->AvailableForStates(G4ApplicationState::G4State_Idle);
24  pluginName = new G4UIparameter("pluginName", 's', false);
25  pluginName->SetGuidance("Name of plugin to destroy.");
26  destroyCmd_->SetParameter(pluginName);
27 
28  listCmd_ = new G4UIcommand("/slic/plugins/list", this);
29  listCmd_->SetGuidance("List currently loaded plugins.");
30  listCmd_->AvailableForStates(G4ApplicationState::G4State_Idle, G4ApplicationState::G4State_PreInit);
31 }
32 
34  delete pluginDir_;
35  delete loadCmd_;
36  delete destroyCmd_;
37  delete listCmd_;
38 }
39 
40 void PluginMessenger::SetNewValue(G4UIcommand* command, G4String newValues) {
41 
42  std::istringstream is((const char*) newValues);
43  std::string pluginName, libName;
44 
45  is >> pluginName >> libName;
46 
47  if (libName.size() == 0 || libName == "") {
48  libName = "libslicPlugins.so";
49  }
50 
51  if (command == loadCmd_) {
52  pluginManager_->create(pluginName, libName);
53  } else if (command == destroyCmd_) {
54  pluginManager_->destroy(pluginName);
55  } else if (command == listCmd_) {
56  pluginManager_->print(std::cout);
57  }
58 }
59 
60 }
Manages user sim plugins.
std::ostream & print(std::ostream &os)
void destroy(const std::string &pluginName)
void create(const std::string &pluginName, const std::string &libName)
PluginMessenger(PluginManager *mgr)
G4UIdirectory * pluginDir_
void SetNewValue(G4UIcommand *command, G4String newValues)
PluginManager * pluginManager_
G4UIcommand * destroyCmd_