Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4HnMessenger.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26
27// Author: Ivana Hrivnacova, 18/06/2013 ([email protected])
28
29#include "G4HnMessenger.hh"
30#include "G4HnManager.hh"
31
32#include "G4UIcommand.hh"
33#include "G4UIparameter.hh"
34#include "G4UIcmdWithABool.hh"
35#include "G4UIcmdWithAString.hh"
36
37//_____________________________________________________________________________
39 : fManager(manager),
40 fHnType(manager.GetHnType())
41{
42 SetHnAsciiCmd();
43 SetHnActivationCmd();
44 SetHnActivationToAllCmd();
45 SetHnPlottingCmd();
46 SetHnPlottingToAllCmd();
47 SetHnFileNameCmd();
48 SetHnFileNameToAllCmd();
49}
50
51//_____________________________________________________________________________
53
54//
55// private functions
56//
57
58//_____________________________________________________________________________
59G4String G4HnMessenger::GetObjectType() const
60{
61 return (fHnType[0] == 'h') ?
62 fHnType.substr(1,1) + "D histogram" :
63 fHnType.substr(1,1) + "D profile";
64}
65
66//_____________________________________________________________________________
67void G4HnMessenger::AddIdParameter(G4UIcommand& command)
68{
69 auto htId = new G4UIparameter("id", 'i', false);
70 htId->SetGuidance("Histogram id");
71 htId->SetParameterRange("id>=0");
72 command.SetParameter(htId);
73}
74
75//_____________________________________________________________________________
76void G4HnMessenger::AddOptionParameter(G4UIcommand& command, G4String optionName)
77{
78 auto param = new G4UIparameter(optionName, 'b', true);
79 auto guidance = GetObjectType() + " " + optionName + " option";
80 param->SetGuidance(guidance.c_str());
81 param->SetDefaultValue("true");
82 command.SetParameter(param);
83}
84
85//_____________________________________________________________________________
86void G4HnMessenger::SetHnAsciiCmd()
87{
88 fSetAsciiCmd =
89 CreateCommand<G4UIcommand>("setAscii", "Print on ascii file the ");
90
91 AddIdParameter(*fSetAsciiCmd);
92 AddOptionParameter(*fSetAsciiCmd, "hnAscii");
93
94}
95
96//_____________________________________________________________________________
97void G4HnMessenger::SetHnActivationCmd()
98{
99 fSetActivationCmd =
100 CreateCommand<G4UIcommand>("setActivation", "Set activation to the ");
101
102 AddIdParameter(*fSetActivationCmd);
103 AddOptionParameter(*fSetActivationCmd, "hnActivation");
104}
105
106//_____________________________________________________________________________
107void G4HnMessenger::SetHnActivationToAllCmd()
108{
109 fSetActivationAllCmd =
110 CreateCommand<G4UIcmdWithABool>(
111 "setActivationToAll", "Set activation to all");
112 fSetActivationAllCmd->SetParameterName("Activation", false);
113}
114
115//_____________________________________________________________________________
116void G4HnMessenger::SetHnPlottingCmd()
117{
118 fSetPlottingCmd =
119 CreateCommand<G4UIcommand>("setPlotting", "(In)Activate batch plotting of the ");
120
121 AddIdParameter(*fSetPlottingCmd);
122 AddOptionParameter(*fSetPlottingCmd, "hnPlotting");
123}
124
125//_____________________________________________________________________________
126void G4HnMessenger::SetHnPlottingToAllCmd()
127{
128 fSetPlottingAllCmd =
129 CreateCommand<G4UIcmdWithABool>(
130 "setPlottingToAll", "(In)Activate batch plotting of all ");
131 fSetPlottingAllCmd->SetParameterName("Plotting", false);
132}
133
134//_____________________________________________________________________________
135void G4HnMessenger::SetHnFileNameCmd()
136{
137 fSetFileNameCmd =
138 CreateCommand<G4UIcommand>("setFileName", "Set the output file name for the ");
139
140 AddIdParameter(*fSetFileNameCmd);
141
142 auto param = new G4UIparameter("hnFileName", 's', false);
143 auto guidance = GetObjectType() + " output file name";
144 param->SetGuidance(guidance.c_str());
145 fSetFileNameCmd->SetParameter(param);
146}
147
148//_____________________________________________________________________________
149void G4HnMessenger::SetHnFileNameToAllCmd()
150{
151 fSetFileNameAllCmd =
152 CreateCommand<G4UIcmdWithAString>(
153 "setFileNameToAll", "Set output file name for all ");
154 fSetFileNameAllCmd->SetParameterName("FileName", false);
155}
156
157//
158// public methods
159//
160
161//_____________________________________________________________________________
163{
164 // process "All" commands first
165 if ( command == fSetActivationAllCmd.get() ) {
166 fManager.SetActivation(fSetActivationAllCmd->GetNewBoolValue(newValues));
167 return;
168 }
169
170 if ( command == fSetPlottingAllCmd.get() ) {
171 fManager.SetPlotting(fSetPlottingAllCmd->GetNewBoolValue(newValues));
172 return;
173 }
174
175 if ( command == fSetFileNameAllCmd.get() ) {
176 fManager.SetFileName(newValues);
177 return;
178 }
179
180 // Tokenize parameters in a vector
181 std::vector<G4String> parameters;
182 G4Analysis::Tokenize(newValues, parameters);
183 // check consistency
184 if ( parameters.size() != command->GetParameterEntries() ) {
185 // Should never happen but let's check anyway for consistency
187 "Got wrong number of \"" + command->GetCommandName() +
188 "\" parameters: " + std::to_string(parameters.size()) +
189 " instead of " + std::to_string(command->GetParameterEntries()) + " expected",
190 fkClass, "WarnAboutParameters");
191 return;
192 }
193
194 auto counter = 0;
195 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
196
197 if ( command == fSetAsciiCmd.get() ) {
198 fManager.SetAscii(id, G4UIcommand::ConvertToBool(parameters[counter++]));
199 return;
200 }
201
202 if ( command == fSetActivationCmd.get() ) {
203 fManager.SetActivation(id, G4UIcommand::ConvertToBool(parameters[counter++]));
204 return;
205 }
206
207 if ( command == fSetPlottingCmd.get() ) {
208 fManager.SetPlotting(id, G4UIcommand::ConvertToBool(parameters[counter++]));
209 return;
210 }
211
212 if ( command == fSetFileNameCmd.get() ) {
213 fManager.SetFileName(id, parameters[counter++]);
214 return;
215 }
216}
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:204
void SetFileName(G4int id, const G4String &fileName)
Definition: G4HnManager.cc:258
void SetAscii(G4int id, G4bool ascii)
Definition: G4HnManager.cc:218
void SetPlotting(G4int id, G4bool plotting)
Definition: G4HnManager.cc:238
G4HnMessenger()=delete
~G4HnMessenger() override
void SetNewValue(G4UIcommand *command, G4String value) final
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:139
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:561
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:549
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:138
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)