Geant4_10
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 
33 #include "G4UIcommand.hh"
34 #include "G4UIparameter.hh"
35 #include "G4UIcmdWithAnInteger.hh"
36 #include "G4UIcmdWithABool.hh"
37 
38 #include <iostream>
39 
40 //_____________________________________________________________________________
42  : G4UImessenger(),
43  fManager(manager),
44  fSetHnAsciiCmd(0),
45  fSetHnActivationCmd(0),
46  fSetHnActivationAllCmd(0)
47 {
48 
49  SetHnAsciiCmd();
50  SetHnActivationCmd();
51  SetHnActivationToAllCmd();
52 }
53 
54 //_____________________________________________________________________________
56 {
57  delete fSetHnAsciiCmd;
58  delete fSetHnActivationCmd;
59  delete fSetHnActivationAllCmd;
60 }
61 
62 //
63 // private functions
64 //
65 
66 //_____________________________________________________________________________
67 G4String G4HnMessenger::GetCmdDirectoryName() const
68 {
69  G4String hnType = fManager->GetHnType();
70  hnType.toLower();
71  G4String name("/analysis/");
72  name.append(hnType);
73  name.append("/");
74  return name;
75 }
76 
77 //_____________________________________________________________________________
78 G4String G4HnMessenger::GetHnDescription() const
79 {
80  G4String hnDescription = fManager->GetHnType();
81  hnDescription.erase(0);
82  hnDescription.append("D");
83  return hnDescription;
84 }
85 
86 //_____________________________________________________________________________
87 void G4HnMessenger::SetHnAsciiCmd()
88 {
89  G4String name = GetCmdDirectoryName();
90  name.append("setAscii");
91  fSetHnAsciiCmd = new G4UIcmdWithAnInteger(name, this);
92 
93  G4String guidance("Print ");
94  guidance.append(GetHnDescription());
95  guidance.append(" histogram of #Id on ascii file.");
96 
97  fSetHnAsciiCmd->SetGuidance(guidance);
98  fSetHnAsciiCmd->SetParameterName("Id",false);
99  fSetHnAsciiCmd->SetRange("Id>=0");
101 }
102 
103 //_____________________________________________________________________________
104 void G4HnMessenger::SetHnActivationCmd()
105 {
106  G4String name = GetCmdDirectoryName();
107  name.append("setActivationToAll");
108  fSetHnAsciiCmd = new G4UIcmdWithAnInteger(name, this);
109 
110  G4String guidance("Set activation to all ");
111  guidance.append(GetHnDescription());
112  guidance.append(" histograms.");
113 
114  fSetHnActivationAllCmd = new G4UIcmdWithABool(name, this);
115  fSetHnActivationAllCmd->SetGuidance(guidance);
116  fSetHnActivationAllCmd->SetParameterName("Activation",false);
117 }
118 
119 //_____________________________________________________________________________
120 void G4HnMessenger::SetHnActivationToAllCmd()
121 {
122  G4UIparameter* hnId = new G4UIparameter("idActivation", 'i', false);
123  hnId->SetGuidance("Histogram id");
124  hnId->SetParameterRange("idActivation>=0");
125 
126  G4UIparameter* hnActivation = new G4UIparameter("hnActivation", 's', true);
127  hnActivation->SetGuidance("Histogram activation");
128  hnActivation->SetDefaultValue("none");
129 
130  G4String name = GetCmdDirectoryName();
131  name.append("setActivation");
132  fSetHnActivationCmd = new G4UIcommand(name, this);
133 
134  G4String guidance("Set activation for the ");
135  guidance.append(GetHnDescription());
136  guidance.append(" histogram of #Id");
137 
138  fSetHnActivationCmd->SetGuidance(guidance);
139  fSetHnActivationCmd->SetParameter(hnId);
140  fSetHnActivationCmd->SetParameter(hnActivation);
141  fSetHnActivationCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
142 }
143 
144 //
145 // public methods
146 //
147 
148 //_____________________________________________________________________________
150 {
151  if ( command == fSetHnAsciiCmd ) {
152  G4int id = fSetHnAsciiCmd->GetNewIntValue(newValues);
153  fManager->SetAscii(id, true);
154  }
155  else if ( command == fSetHnActivationCmd ) {
156  G4int id;
157  G4String sactivation;
158  std::istringstream is(newValues.data());
159  is >> id >> sactivation;
160  G4bool activation = G4UIcommand::ConvertToBool(sactivation);
161  fManager->SetActivation(id, activation);
162  }
163  else if ( command == fSetHnActivationAllCmd ) {
164  G4bool activation = fSetHnActivationAllCmd->GetNewBoolValue(newValues);
165  fManager->SetActivation(activation);
166  }
167 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
G4String GetHnType() const
Definition: G4HnManager.hh:114
void SetParameterRange(const char *theRange)
void SetDefaultValue(const char *theDefaultValue)
const XML_Char * name
Definition: expat.h:151
int G4int
Definition: G4Types.hh:78
static G4bool GetNewBoolValue(const char *paramString)
G4HnMessenger(G4HnManager *manager)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:411
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:161
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
void toLower()
const char * data() const
G4String & append(const G4String &)
void SetGuidance(const char *theGuidance)
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:140
virtual void SetNewValue(G4UIcommand *command, G4String value)