Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/hadronic/Hadr04/src/DetectorMessenger.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 /// \file hadronic/Hadr03/src/DetectorMessenger.cc
27 /// \brief Implementation of the DetectorMessenger class
28 //
29 // $Id: DetectorMessenger.cc 70755 2013-06-05 12:17:48Z ihrivnac $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "DetectorMessenger.hh"
35 
36 #include "DetectorConstruction.hh"
37 #include "G4UIdirectory.hh"
38 #include "G4UIcommand.hh"
39 #include "G4UIparameter.hh"
40 #include "G4UIcmdWithAString.hh"
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
47 :G4UImessenger(),
48  fDetector(Det), fTestemDir(0), fDetDir(0), fMaterCmd(0), fSizeCmd(0),
49  fIsotopeCmd(0)
50 {
51  fTestemDir = new G4UIdirectory("/testhadr/");
52  fTestemDir->SetGuidance("commands specific to this example");
53 
54  G4bool broadcast = false;
55  fDetDir = new G4UIdirectory("/testhadr/det/",broadcast);
56  fDetDir->SetGuidance("detector construction commands");
57 
58  fMaterCmd = new G4UIcmdWithAString("/testhadr/det/setMat",this);
59  fMaterCmd->SetGuidance("Select material of the box.");
60  fMaterCmd->SetParameterName("choice",false);
62 
63  fSizeCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSize",this);
64  fSizeCmd->SetGuidance("Set size of the box");
65  fSizeCmd->SetParameterName("Size",false);
66  fSizeCmd->SetRange("Size>0.");
67  fSizeCmd->SetUnitCategory("Length");
69 
70  fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat",this);
71  fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
72  fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material");
73  //
74  G4UIparameter* symbPrm = new G4UIparameter("isotope",'s',false);
75  symbPrm->SetGuidance("isotope symbol");
76  fIsotopeCmd->SetParameter(symbPrm);
77  //
78  G4UIparameter* ZPrm = new G4UIparameter("Z",'i',false);
79  ZPrm->SetGuidance("Z");
80  ZPrm->SetParameterRange("Z>0");
81  fIsotopeCmd->SetParameter(ZPrm);
82  //
83  G4UIparameter* APrm = new G4UIparameter("A",'i',false);
84  APrm->SetGuidance("A");
85  APrm->SetParameterRange("A>0");
86  fIsotopeCmd->SetParameter(APrm);
87  //
88  G4UIparameter* densityPrm = new G4UIparameter("density",'d',false);
89  densityPrm->SetGuidance("density of material");
90  densityPrm->SetParameterRange("density>0.");
91  fIsotopeCmd->SetParameter(densityPrm);
92  //
93  G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false);
94  unitPrm->SetGuidance("unit of density");
96  unitPrm->SetParameterCandidates(unitList);
97  fIsotopeCmd->SetParameter(unitPrm);
98  //
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 
105 {
106  delete fMaterCmd;
107  delete fSizeCmd;
108  delete fIsotopeCmd;
109  delete fDetDir;
110  delete fTestemDir;
111 }
112 
113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
114 
116 {
117  if( command == fMaterCmd )
118  { fDetector->SetMaterial(newValue);}
119 
120  if( command == fSizeCmd )
121  { fDetector->SetSize(fSizeCmd->GetNewDoubleValue(newValue));}
122 
123  if (command == fIsotopeCmd)
124  {
125  G4int Z; G4int A; G4double dens;
126  G4String name, unt;
127  std::istringstream is(newValue);
128  is >> name >> Z >> A >> dens >> unt;
129  dens *= G4UIcommand::ValueOf(unt);
130  fDetector->MaterialWithSingleIsotope (name,name,dens,Z,A);
131  fDetector->SetMaterial(name);
132  }
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
const XML_Char * name
void SetUnitCategory(const char *unitCategory)
static G4double GetNewDoubleValue(const char *paramString)
int G4int
Definition: G4Types.hh:78
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:306
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 AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
G4Material * MaterialWithSingleIsotope(G4String, G4String, G4double, G4int, G4int)
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:294
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:301
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)