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