Geant4 10.7.0
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"
33
34#include "G4UIcommand.hh"
35#include "G4UIparameter.hh"
37#include "G4UIcmdWithABool.hh"
38#include "G4UIcmdWithAString.hh"
39
40using namespace G4Analysis;
41
42#include <iostream>
43
45 : G4UImessenger(),
46 fManager(manager),
47 fHelper(nullptr),
48 fSetHnAsciiCmd(nullptr),
49 fSetHnActivationCmd(nullptr),
50 fSetHnActivationAllCmd(nullptr),
51 fSetHnPlottingCmd(nullptr),
52 fSetHnPlottingAllCmd(nullptr),
53 fSetHnFileNameCmd(nullptr),
54 fSetHnFileNameAllCmd(nullptr)
55{
56 G4String hnType = fManager.GetHnType();
57 hnType.toLower();
58 fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>(hnType);
59
60 SetHnAsciiCmd();
61 SetHnActivationCmd();
62 SetHnActivationToAllCmd();
63 SetHnPlottingCmd();
64 SetHnPlottingToAllCmd();
65 SetHnFileNameCmd();
66 SetHnFileNameToAllCmd();
67}
68
69//_____________________________________________________________________________
71{}
72
73//
74// private functions
75//
76
77//_____________________________________________________________________________
78void G4HnMessenger::SetHnAsciiCmd()
79{
80 fSetHnAsciiCmd
81 = G4Analysis::make_unique<G4UIcmdWithAnInteger>(fHelper->Update("/analysis/HNTYPE_/setAscii"), this);
82 fSetHnAsciiCmd->SetGuidance(
83 fHelper->Update("Print NDIM_D LOBJECT of given id on ascii file."));
84
85 fSetHnAsciiCmd->SetParameterName("id",false);
86 fSetHnAsciiCmd->SetRange("id>=0");
87 fSetHnAsciiCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
88}
89
90//_____________________________________________________________________________
91void G4HnMessenger::SetHnActivationCmd()
92{
93 auto hnId = new G4UIparameter("id", 'i', false);
94 hnId->SetGuidance(fHelper->Update("OBJECT id"));
95 hnId->SetParameterRange("id>=0");
96
97 auto hnActivation = new G4UIparameter("hnActivation", 's', true);
98 hnActivation->SetGuidance(fHelper->Update("OBJECT activation"));
99 hnActivation->SetDefaultValue("none");
100
101 fSetHnActivationCmd
102 = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setActivation"), this);
103 fSetHnActivationCmd->SetGuidance(
104 fHelper->Update("Set activation for the NDIM_D LOBJECT of given id"));
105 fSetHnActivationCmd->SetParameter(hnId);
106 fSetHnActivationCmd->SetParameter(hnActivation);
107 fSetHnActivationCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
108}
109
110//_____________________________________________________________________________
111void G4HnMessenger::SetHnActivationToAllCmd()
112{
113 fSetHnActivationAllCmd
114 = G4Analysis::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setActivationToAll"), this);
115 fSetHnActivationAllCmd->SetGuidance(
116 fHelper->Update("Set activation to all NDIM_D LOBJECTs"));
117 fSetHnActivationAllCmd->SetParameterName("Activation",false);
118}
119
120//_____________________________________________________________________________
121void G4HnMessenger::SetHnPlottingCmd()
122{
123 auto hnId = new G4UIparameter("id", 'i', false);
124 hnId->SetGuidance(fHelper->Update("OBJECT id"));
125 hnId->SetParameterRange("id>=0");
126
127 auto hnPlotting = new G4UIparameter("hnPlotting", 's', true);
128 hnPlotting->SetGuidance(fHelper->Update("(In)Activate OBJECT plotting"));
129 hnPlotting->SetDefaultValue("none");
130
131 fSetHnPlottingCmd
132 = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setPlotting"), this);
133 fSetHnPlottingCmd->SetGuidance(
134 fHelper->Update("(In)Activate batch plotting of the NDIM_D LOBJECT of given id"));
135 fSetHnPlottingCmd->SetParameter(hnId);
136 fSetHnPlottingCmd->SetParameter(hnPlotting);
137 fSetHnPlottingCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
138}
139
140//_____________________________________________________________________________
141void G4HnMessenger::SetHnPlottingToAllCmd()
142{
143 fSetHnPlottingAllCmd
144 = G4Analysis::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setPlottingToAll"), this);
145 fSetHnPlottingAllCmd->SetGuidance(
146 fHelper->Update("(In)Activate batch plotting of all NDIM_D LOBJECTs"));
147 fSetHnPlottingAllCmd->SetParameterName("Plotting",false);
148}
149
150//_____________________________________________________________________________
151void G4HnMessenger::SetHnFileNameCmd()
152{
153 auto hnId = new G4UIparameter("id", 'i', false);
154 hnId->SetGuidance(fHelper->Update("OBJECT id"));
155 hnId->SetParameterRange("id>=0");
156
157 auto hnFileName = new G4UIparameter("hnFileName", 's', true);
158 hnFileName->SetGuidance(fHelper->Update("OBJECT output file name"));
159 hnFileName->SetDefaultValue("none");
160
161 fSetHnFileNameCmd
162 = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setFileName"), this);
163 fSetHnFileNameCmd->SetGuidance(
164 fHelper->Update("Set the NDIM_D LOBJECT of given id output file name"));
165 fSetHnFileNameCmd->SetParameter(hnId);
166 fSetHnFileNameCmd->SetParameter(hnFileName);
167 fSetHnFileNameCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
168}
169
170//_____________________________________________________________________________
171void G4HnMessenger::SetHnFileNameToAllCmd()
172{
173 fSetHnFileNameAllCmd
174 = G4Analysis::make_unique<G4UIcmdWithAString>(fHelper->Update("/analysis/HNTYPE_/setFileNameToAll"), this);
175 fSetHnFileNameAllCmd->SetGuidance(
176 fHelper->Update("Set output file name for all NDIM_D LOBJECTs"));
177 fSetHnFileNameAllCmd->SetParameterName("FileName",false);
178}
179
180//
181// public methods
182//
183
184//_____________________________________________________________________________
186{
187 if ( command == fSetHnAsciiCmd.get() ) {
188 auto id = fSetHnAsciiCmd->GetNewIntValue(newValues);
189 fManager.SetAscii(id, true);
190 }
191 else if ( command == fSetHnActivationCmd.get() ) {
192 // tokenize parameters in a vector
193 std::vector<G4String> parameters;
194 G4Analysis::Tokenize(newValues, parameters);
195 // check consistency
196 if ( parameters.size() == command->GetParameterEntries() ) {
197 auto counter = 0;
198 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
199 auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
200 fManager.SetActivation(id, activation);
201 }
202 else {
203 // Should never happen but let's check anyway for consistency
204 fHelper->WarnAboutParameters(command, parameters.size());
205 }
206 }
207 else if ( command == fSetHnActivationAllCmd.get() ) {
208 auto activation = fSetHnActivationAllCmd->GetNewBoolValue(newValues);
209 fManager.SetActivation(activation);
210 }
211 else if ( command == fSetHnPlottingCmd.get() ) {
212 // tokenize parameters in a vector
213 std::vector<G4String> parameters;
214 G4Analysis::Tokenize(newValues, parameters);
215 // check consistency
216 if ( parameters.size() == command->GetParameterEntries() ) {
217 auto counter = 0;
218 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
219 auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
220 fManager.SetPlotting(id, activation);
221 }
222 else {
223 // Should never happen but let's check anyway for consistency
224 fHelper->WarnAboutParameters(command, parameters.size());
225 }
226 }
227 else if ( command == fSetHnPlottingAllCmd.get() ) {
228 auto activation = fSetHnPlottingAllCmd->GetNewBoolValue(newValues);
229 fManager.SetPlotting(activation);
230 }
231 else if ( command == fSetHnFileNameCmd.get() ) {
232 // tokenize parameters in a vector
233 std::vector<G4String> parameters;
234 G4Analysis::Tokenize(newValues, parameters);
235 // check consistency
236 if ( parameters.size() == command->GetParameterEntries() ) {
237 auto counter = 0;
238 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
239 auto fileName = parameters[counter++];
240 fManager.SetFileName(id, fileName);
241 }
242 else {
243 // Should never happen but let's check anyway for consistency
244 fHelper->WarnAboutParameters(command, parameters.size());
245 }
246 }
247 else if ( command == fSetHnFileNameAllCmd.get() ) {
248 auto fileName = newValues;
249 fManager.SetFileName(fileName);
250 }
251}
@ G4State_Idle
@ G4State_PreInit
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:202
void SetFileName(G4int id, const G4String &fileName)
Definition: G4HnManager.cc:254
void SetAscii(G4int id, G4bool ascii)
Definition: G4HnManager.cc:216
G4String GetHnType() const
Definition: G4HnManager.hh:140
void SetPlotting(G4int id, G4bool plotting)
Definition: G4HnManager.cc:234
virtual ~G4HnMessenger()
G4HnMessenger(G4HnManager &manager)
virtual void SetNewValue(G4UIcommand *command, G4String value) final
void toLower()
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:543
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:530
void Tokenize(const G4String &line, std::vector< G4String > &tokens)