Geant4  10.01.p03
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"
33 
34 #include "G4UIcommand.hh"
35 #include "G4UIparameter.hh"
36 #include "G4UIcmdWithAnInteger.hh"
37 #include "G4UIcmdWithABool.hh"
38 
39 #include <iostream>
40 
41 namespace {
42 
43 void Exception(G4UIcommand* command, G4int nofParameters)
44 {
45  G4ExceptionDescription description;
46  description
47  << "Got wrong number of \"" << command->GetCommandName()
48  << "\" parameters: " << nofParameters
49  << " instead of " << command->GetParameterEntries()
50  << " expected" << G4endl;
51  G4Exception("G4HnMessenger::SetNewValue",
52  "Analysis_W013", JustWarning, description);
53 }
54 
55 }
56 
57 //_____________________________________________________________________________
59  : G4UImessenger(),
60  fManager(manager),
61  fSetHnAsciiCmd(0),
62  fSetHnActivationCmd(0),
63  fSetHnActivationAllCmd(0)
64 {
65 
66  SetHnAsciiCmd();
69 }
70 
71 //_____________________________________________________________________________
73 {
74  delete fSetHnAsciiCmd;
75  delete fSetHnActivationCmd;
77 }
78 
79 //
80 // private functions
81 //
82 
83 //_____________________________________________________________________________
85 {
86  G4String hnType = fManager->GetHnType();
87  hnType.toLower();
88  G4String name("/analysis/");
89  name.append(hnType);
90  name.append("/");
91  return name;
92 }
93 
94 //_____________________________________________________________________________
96 {
97  G4String hnDescription = fManager->GetHnType();
98  hnDescription.erase(0);
99  hnDescription.append("D");
100  return hnDescription;
101 }
102 
103 //_____________________________________________________________________________
105 {
107  name.append("setAscii");
108  fSetHnAsciiCmd = new G4UIcmdWithAnInteger(name, this);
109 
110  G4String guidance("Print ");
111  guidance.append(GetHnDescription());
112  guidance.append(" histogram of #Id on ascii file.");
113 
114  fSetHnAsciiCmd->SetGuidance(guidance);
115  fSetHnAsciiCmd->SetParameterName("Id",false);
116  fSetHnAsciiCmd->SetRange("Id>=0");
118 }
119 
120 //_____________________________________________________________________________
122 {
123  G4UIparameter* hnId = new G4UIparameter("idActivation", 'i', false);
124  hnId->SetGuidance("Histogram id");
125  hnId->SetParameterRange("idActivation>=0");
126 
127  G4UIparameter* hnActivation = new G4UIparameter("hnActivation", 's', true);
128  hnActivation->SetGuidance("Histogram activation");
129  hnActivation->SetDefaultValue("none");
130 
132  name.append("setActivation");
133  fSetHnActivationCmd = new G4UIcommand(name, this);
134 
135  G4String guidance("Set activation for the ");
136  guidance.append(GetHnDescription());
137  guidance.append(" histogram of #Id");
138 
139  fSetHnActivationCmd->SetGuidance(guidance);
141  fSetHnActivationCmd->SetParameter(hnActivation);
143 }
144 
145 //_____________________________________________________________________________
147 {
149  name.append("setActivationToAll");
150  fSetHnActivationAllCmd = new G4UIcmdWithABool(name, this);
151 
152  G4String guidance("Set activation to all ");
153  guidance.append(GetHnDescription());
154  guidance.append(" histograms.");
155 
157  fSetHnActivationAllCmd->SetParameterName("Activation",false);
158 }
159 
160 //
161 // public methods
162 //
163 
164 //_____________________________________________________________________________
166 {
167  if ( command == fSetHnAsciiCmd ) {
168  G4int id = fSetHnAsciiCmd->GetNewIntValue(newValues);
169  fManager->SetAscii(id, true);
170  }
171  else if ( command == fSetHnActivationCmd ) {
172  // tokenize parameters in a vector
173  std::vector<G4String> parameters;
174  G4Analysis::Tokenize(newValues, parameters);
175  // check consistency
176  if ( G4int(parameters.size()) == command->GetParameterEntries() ) {
177  G4int counter = 0;
178  G4int id = G4UIcommand::ConvertToInt(parameters[counter++]);
179  G4bool activation = G4UIcommand::ConvertToBool(parameters[counter++]);
180  fManager->SetActivation(id, activation);
181  }
182  else {
183  // Should never happen but let's check anyway for consistency
184  Exception(command, parameters.size());
185  }
186  }
187  else if ( command == fSetHnActivationAllCmd ) {
188  G4bool activation = fSetHnActivationAllCmd->GetNewBoolValue(newValues);
189  fManager->SetActivation(activation);
190  }
191 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
G4String GetHnType() const
Definition: G4HnManager.hh:131
void SetParameterRange(const char *theRange)
G4String name
Definition: TRTMaterials.hh:40
void SetDefaultValue(const char *theDefaultValue)
int G4int
Definition: G4Types.hh:78
static G4bool GetNewBoolValue(const char *paramString)
G4HnMessenger(G4HnManager *manager)
G4UIcommand * fSetHnActivationCmd
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetHnAsciiCmd()
G4String GetCmdDirectoryName() const
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:425
G4HnManager * fManager
Associated class.
virtual ~G4HnMessenger()
bool G4bool
Definition: G4Types.hh:79
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetAscii(G4int id, G4bool ascii)
Definition: G4HnManager.cc:209
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:239
void toLower()
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:141
void Exception(const char *originOfException, const char *exceptionCode, UExceptionSeverity severity, int level, const char *description)
Definition: UUtils.cc:122
G4UIcmdWithAnInteger * fSetHnAsciiCmd
G4String GetHnDescription() const
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4String & append(const G4String &)
void SetHnActivationCmd()
#define G4endl
Definition: G4ios.hh:61
void SetGuidance(const char *theGuidance)
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4UIcmdWithABool * fSetHnActivationAllCmd
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:188
virtual void SetNewValue(G4UIcommand *command, G4String value)
void SetHnActivationToAllCmd()