Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 (ivana@ipno.in2p3.fr)
28
29#include "G4HnMessenger.hh"
30#include "G4HnManager.hh"
32
33#include "G4UIcommand.hh"
34#include "G4UIparameter.hh"
35#include "G4UIcmdWithABool.hh"
36#include "G4UIcmdWithAString.hh"
37
38using namespace G4Analysis;
39
40//_____________________________________________________________________________
42 : fManager(manager),
43 fHnType(manager.GetHnType()),
44 fHnDimension(std::stoi(manager.GetHnType().substr(1,1)))
45{
46 SetHnAsciiCmd();
47 SetHnActivationCmd();
48 SetHnActivationToAllCmd();
49 SetHnPlottingCmd();
50 SetHnPlottingToAllCmd();
51 SetHnFileNameCmd();
52 SetHnFileNameToAllCmd();
53
54 auto maxDim = (fHnDimension < kMaxDim) ? fHnDimension + 1 : kMaxDim;
55 for (unsigned int idim = 0; idim < maxDim; ++idim) {
56 fSetAxisLogCmd.push_back(CreateSetAxisLogCommand(idim));
57 }
58}
59
60//_____________________________________________________________________________
62
63//
64// private functions
65//
66
67//_____________________________________________________________________________
68G4String G4HnMessenger::GetObjectType() const
69{
70 return (fHnType[0] == 'h') ?
71 fHnType.substr(1,1) + "D histogram" :
72 fHnType.substr(1,1) + "D profile";
73}
74
75//_____________________________________________________________________________
76void G4HnMessenger::AddIdParameter(G4UIcommand& command)
77{
78 auto htId = new G4UIparameter("id", 'i', false);
79 htId->SetGuidance("Histogram id");
80 htId->SetParameterRange("id>=0");
81 command.SetParameter(htId);
82}
83
84//_____________________________________________________________________________
85void G4HnMessenger::AddOptionParameter(G4UIcommand& command, G4String optionName)
86{
87 auto param = new G4UIparameter(optionName, 'b', true);
88 auto guidance = GetObjectType() + " " + optionName + " option";
89 param->SetGuidance(guidance.c_str());
90 param->SetDefaultValue("true");
91 command.SetParameter(param);
92}
93
94//_____________________________________________________________________________
95void G4HnMessenger::SetHnAsciiCmd()
96{
97 fSetAsciiCmd =
98 CreateCommand<G4UIcommand>("setAscii", "Print on ascii file the ");
99
100 AddIdParameter(*fSetAsciiCmd);
101 AddOptionParameter(*fSetAsciiCmd, "hnAscii");
102
103}
104
105//_____________________________________________________________________________
106void G4HnMessenger::SetHnActivationCmd()
107{
108 fSetActivationCmd =
109 CreateCommand<G4UIcommand>("setActivation", "Set activation to the ");
110
111 AddIdParameter(*fSetActivationCmd);
112 AddOptionParameter(*fSetActivationCmd, "hnActivation");
113}
114
115//_____________________________________________________________________________
116void G4HnMessenger::SetHnActivationToAllCmd()
117{
118 fSetActivationAllCmd =
119 CreateCommand<G4UIcmdWithABool>(
120 "setActivationToAll", "Set activation to all");
121 fSetActivationAllCmd->SetParameterName("Activation", false);
122}
123
124//_____________________________________________________________________________
125void G4HnMessenger::SetHnPlottingCmd()
126{
127 fSetPlottingCmd =
128 CreateCommand<G4UIcommand>("setPlotting", "(In)Activate batch plotting of the ");
129
130 AddIdParameter(*fSetPlottingCmd);
131 AddOptionParameter(*fSetPlottingCmd, "hnPlotting");
132}
133
134//_____________________________________________________________________________
135void G4HnMessenger::SetHnPlottingToAllCmd()
136{
137 fSetPlottingAllCmd =
138 CreateCommand<G4UIcmdWithABool>(
139 "setPlottingToAll", "(In)Activate batch plotting of all ");
140 fSetPlottingAllCmd->SetParameterName("Plotting", false);
141}
142
143//_____________________________________________________________________________
144void G4HnMessenger::SetHnFileNameCmd()
145{
146 fSetFileNameCmd =
147 CreateCommand<G4UIcommand>("setFileName", "Set the output file name for the ");
148
149 AddIdParameter(*fSetFileNameCmd);
150
151 auto param = new G4UIparameter("hnFileName", 's', false);
152 auto guidance = GetObjectType() + " output file name";
153 param->SetGuidance(guidance.c_str());
154 fSetFileNameCmd->SetParameter(param);
155}
156
157//_____________________________________________________________________________
158void G4HnMessenger::SetHnFileNameToAllCmd()
159{
160 fSetFileNameAllCmd =
161 CreateCommand<G4UIcmdWithAString>(
162 "setFileNameToAll", "Set output file name for all ");
163 fSetFileNameAllCmd->SetParameterName("FileName", false);
164}
165
166//_____________________________________________________________________________
167std::unique_ptr<G4UIcommand>
168G4HnMessenger::CreateSetAxisLogCommand(unsigned int idim)
169{
170 G4String xyz{"XYZ"};
171 auto axis = xyz.substr(idim, 1);
172
173 G4String commandName = "set" + axis + "axisLog";
174 G4String guidance = "Activate " + axis + "-axis log scale for plotting of the ";
175
176 auto command = CreateCommand<G4UIcommand>(commandName, guidance);
178
179 // Add Id parameter
180 AddIdParameter(*command);
181
182 auto parAxisLog = new G4UIparameter("axis", 'b', false);
183 guidance = GetObjectType() + " " + axis + "-axis log scale";
184 parAxisLog->SetGuidance(guidance.c_str());
185 command->SetParameter(parAxisLog);
186
187 return command;
188}
189
190//
191// public methods
192//
193
194//_____________________________________________________________________________
196{
197 // process "All" commands first
198 if ( command == fSetActivationAllCmd.get() ) {
199 fManager.SetActivation(fSetActivationAllCmd->GetNewBoolValue(newValues));
200 return;
201 }
202
203 if ( command == fSetPlottingAllCmd.get() ) {
204 fManager.SetPlotting(fSetPlottingAllCmd->GetNewBoolValue(newValues));
205 return;
206 }
207
208 if ( command == fSetFileNameAllCmd.get() ) {
209 fManager.SetFileName(newValues);
210 return;
211 }
212
213 // Tokenize parameters in a vector
214 std::vector<G4String> parameters;
215 G4Analysis::Tokenize(newValues, parameters);
216 // check consistency
217 if ( parameters.size() != command->GetParameterEntries() ) {
218 // Should never happen but let's check anyway for consistency
220 "Got wrong number of \"" + command->GetCommandName() +
221 "\" parameters: " + std::to_string(parameters.size()) +
222 " instead of " + std::to_string(command->GetParameterEntries()) + " expected",
223 fkClass, "WarnAboutParameters");
224 return;
225 }
226
227 auto counter = 0;
228 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
229
230 if ( command == fSetAsciiCmd.get() ) {
231 fManager.SetAscii(id, G4UIcommand::ConvertToBool(parameters[counter++]));
232 return;
233 }
234
235 if ( command == fSetActivationCmd.get() ) {
236 fManager.SetActivation(id, G4UIcommand::ConvertToBool(parameters[counter++]));
237 return;
238 }
239
240 if ( command == fSetPlottingCmd.get() ) {
241 fManager.SetPlotting(id, G4UIcommand::ConvertToBool(parameters[counter++]));
242 return;
243 }
244
245 if ( command == fSetFileNameCmd.get() ) {
246 fManager.SetFileName(id, parameters[counter++]);
247 return;
248 }
249
250 auto maxDim = (fHnDimension < kMaxDim) ? fHnDimension + 1 : kMaxDim;
251 for (unsigned int idim = 0; idim < maxDim; ++idim) {
252 if ( command == fSetAxisLogCmd[idim].get() ) {
253 auto axisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
254 fManager.SetAxisIsLog(idim, id, axisLog);
255 return;
256 }
257 }
258}
@ G4State_Idle
@ G4State_PreInit
G4bool SetAxisIsLog(unsigned int idim, G4int id, G4bool isLogAxis)
void SetActivation(G4bool activation)
void SetFileName(G4int id, const G4String &fileName)
void SetAscii(G4int id, G4bool ascii)
void SetPlotting(G4int id, G4bool plotting)
G4HnMessenger()=delete
~G4HnMessenger() override
void SetNewValue(G4UIcommand *command, G4String value) final
std::size_t GetParameterEntries() const
void SetParameter(G4UIparameter *const newParameter)
static G4int ConvertToInt(const char *st)
static G4bool ConvertToBool(const char *st)
void AvailableForStates(G4ApplicationState s1)
const G4String & GetCommandName() const
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
constexpr unsigned int kMaxDim
G4String GetHnType()
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)