Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 // $Id: G4HnMessenger.cc 66310 2012-12-17 11:56:35Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4HnMessenger.hh"
31 #include "G4HnManager.hh"
32 #include "G4AnalysisUtilities.hh"
34 
35 #include "G4UIcommand.hh"
36 #include "G4UIparameter.hh"
37 #include "G4UIcmdWithAnInteger.hh"
38 #include "G4UIcmdWithABool.hh"
39 
40 using 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 {
54  G4String hnType = fManager.GetHnType();
55  hnType.toLower();
56  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>(hnType);
57 
58  SetHnAsciiCmd();
59  SetHnActivationCmd();
60  SetHnActivationToAllCmd();
61  SetHnPlottingCmd();
62  SetHnPlottingToAllCmd();
63 }
64 
65 //_____________________________________________________________________________
67 {}
68 
69 //
70 // private functions
71 //
72 
73 //_____________________________________________________________________________
74 void G4HnMessenger::SetHnAsciiCmd()
75 {
76  fSetHnAsciiCmd
77  = G4Analysis::make_unique<G4UIcmdWithAnInteger>(fHelper->Update("/analysis/HNTYPE_/setAscii"), this);
78  fSetHnAsciiCmd->SetGuidance(
79  fHelper->Update("Print NDIM_D LOBJECT of given id on ascii file."));
80 
81  fSetHnAsciiCmd->SetParameterName("id",false);
82  fSetHnAsciiCmd->SetRange("id>=0");
83  fSetHnAsciiCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
84 }
85 
86 //_____________________________________________________________________________
87 void G4HnMessenger::SetHnActivationCmd()
88 {
89  auto hnId = new G4UIparameter("id", 'i', false);
90  hnId->SetGuidance(fHelper->Update("OBJECT id"));
91  hnId->SetParameterRange("id>=0");
92 
93  auto hnActivation = new G4UIparameter("hnActivation", 's', true);
94  hnActivation->SetGuidance(fHelper->Update("OBJECT activation"));
95  hnActivation->SetDefaultValue("none");
96 
97  fSetHnActivationCmd
98  = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setActivation"), this);
99  fSetHnActivationCmd->SetGuidance(
100  fHelper->Update("Set activation for the NDIM_D LOBJECT of given id"));
101  fSetHnActivationCmd->SetParameter(hnId);
102  fSetHnActivationCmd->SetParameter(hnActivation);
103  fSetHnActivationCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
104 }
105 
106 //_____________________________________________________________________________
107 void G4HnMessenger::SetHnActivationToAllCmd()
108 {
109  fSetHnActivationAllCmd
110  = G4Analysis::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setActivationToAll"), this);
111  fSetHnActivationAllCmd->SetGuidance(
112  fHelper->Update("Set activation to all NDIM_D LOBJECTs"));
113  fSetHnActivationAllCmd->SetParameterName("Activation",false);
114 }
115 
116 //_____________________________________________________________________________
117 void G4HnMessenger::SetHnPlottingCmd()
118 {
119  auto hnId = new G4UIparameter("id", 'i', false);
120  hnId->SetGuidance(fHelper->Update("OBJECT id"));
121  hnId->SetParameterRange("id>=0");
122 
123  auto hnPlotting = new G4UIparameter("hnPlotting", 's', true);
124  hnPlotting->SetGuidance(fHelper->Update("(In)Activate OBJECT plotting"));
125  hnPlotting->SetDefaultValue("none");
126 
127  fSetHnPlottingCmd
128  = G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setPlotting"), this);
129  fSetHnPlottingCmd->SetGuidance(
130  fHelper->Update("(In)Activate batch plotting of the NDIM_D LOBJECT of given id"));
131  fSetHnPlottingCmd->SetParameter(hnId);
132  fSetHnPlottingCmd->SetParameter(hnPlotting);
133  fSetHnPlottingCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
134 }
135 
136 //_____________________________________________________________________________
137 void G4HnMessenger::SetHnPlottingToAllCmd()
138 {
139  fSetHnPlottingAllCmd
140  = G4Analysis::make_unique<G4UIcmdWithABool>(fHelper->Update("/analysis/HNTYPE_/setPlottingToAll"), this);
141  fSetHnPlottingAllCmd->SetGuidance(
142  fHelper->Update("(In)Activate batch plotting of all NDIM_D LOBJECTs"));
143  fSetHnPlottingAllCmd->SetParameterName("Plotting",false);
144 }
145 
146 //
147 // public methods
148 //
149 
150 //_____________________________________________________________________________
152 {
153  if ( command == fSetHnAsciiCmd.get() ) {
154  auto id = fSetHnAsciiCmd->GetNewIntValue(newValues);
155  fManager.SetAscii(id, true);
156  }
157  else if ( command == fSetHnActivationCmd.get() ) {
158  // tokenize parameters in a vector
159  std::vector<G4String> parameters;
160  G4Analysis::Tokenize(newValues, parameters);
161  // check consistency
162  if ( G4int(parameters.size()) == command->GetParameterEntries() ) {
163  auto counter = 0;
164  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
165  auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
166  fManager.SetActivation(id, activation);
167  }
168  else {
169  // Should never happen but let's check anyway for consistency
170  fHelper->WarnAboutParameters(command, parameters.size());
171  }
172  }
173  else if ( command == fSetHnActivationAllCmd.get() ) {
174  auto activation = fSetHnActivationAllCmd->GetNewBoolValue(newValues);
175  fManager.SetActivation(activation);
176  }
177  else if ( command == fSetHnPlottingCmd.get() ) {
178  // tokenize parameters in a vector
179  std::vector<G4String> parameters;
180  G4Analysis::Tokenize(newValues, parameters);
181  // check consistency
182  if ( G4int(parameters.size()) == command->GetParameterEntries() ) {
183  auto counter = 0;
184  auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
185  auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
186  fManager.SetPlotting(id, activation);
187  }
188  else {
189  // Should never happen but let's check anyway for consistency
190  fHelper->WarnAboutParameters(command, parameters.size());
191  }
192  }
193  else if ( command == fSetHnPlottingAllCmd.get() ) {
194  auto activation = fSetHnPlottingAllCmd->GetNewBoolValue(newValues);
195  fManager.SetPlotting(activation);
196  }
197 }
G4String GetHnType() const
Definition: G4HnManager.hh:118
virtual void SetNewValue(G4UIcommand *command, G4String value) final
int G4int
Definition: G4Types.hh:78
void SetPlotting(G4bool plotting)
Definition: G4HnManager.cc:200
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:437
virtual ~G4HnMessenger()
void SetAscii(G4int id, G4bool ascii)
Definition: G4HnManager.cc:164
void toLower()
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:447
G4HnMessenger(G4HnManager &manager)
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:141