source: trunk/source/particles/management/src/G4ParticlePropertyMessenger.cc@ 1307

Last change on this file since 1307 was 1196, checked in by garnier, 16 years ago

update CVS release candidate geant4.9.3.01

File size: 7.5 KB
RevLine 
[824]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// $Id: G4ParticlePropertyMessenger.cc,v 1.7 2006/06/29 19:25:59 gunter Exp $
[1196]28// GEANT4 tag $Name: geant4-09-03-cand-01 $
[824]29//
30//
31//---------------------------------------------------------------
32//
33// G4ParticlePropertyMessenger.cc
34//
35// Description:
36// This is a messenger class to interface to exchange information
37// between ParticleDefinition and UI.
38//
39// History:
40// 13 June 1997, H. Kurashige : The 1st version created.
41// 10 Nov. 1997 H. Kurashige : fixed bugs
42// 08 jan. 1998 H. Kurashige : new UIcommnds
43// 19 June 1998 H. Kurashige : adds UnitCategory
44//---------------------------------------------------------------
45
46#include "G4ParticlePropertyMessenger.hh"
47#include "G4UImanager.hh"
48#include "G4UIdirectory.hh"
49#include "G4UIcmdWithoutParameter.hh"
50#include "G4UIcmdWithAnInteger.hh"
51#include "G4UIcmdWithADoubleAndUnit.hh"
52#include "G4UIcmdWithABool.hh"
53#include "G4ParticleDefinition.hh"
54#include "G4DecayTableMessenger.hh"
55#include "G4ParticlePropertyMessenger.hh"
56#include "G4ParticleTable.hh"
57#include "G4ios.hh" // Include from 'system'
58#include <iomanip> // Include from 'system'
59
60G4ParticlePropertyMessenger::G4ParticlePropertyMessenger(G4ParticleTable* pTable)
61 :theParticleTable(pTable),
62 currentParticle(0),
63 fDecayTableMessenger(0)
64{
65 if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable();
66 //Commnad /particle/property/
67 thisDirectory = new G4UIdirectory("/particle/property/");
68 thisDirectory->SetGuidance("Paricle Table control commands.");
69
70 //Commnad /particle/property/dump
71 dumpCmd = new G4UIcmdWithoutParameter("/particle/property/dump",this);
72 dumpCmd->SetGuidance("dump particle properties.");
73
74 //Command /particle/property/stable
75 stableCmd = new G4UIcmdWithABool("/particle/property/stable",this);
76 stableCmd->SetGuidance("Set stable flag.");
77 stableCmd->SetGuidance(" false: Unstable true: Stable");
78 stableCmd->SetParameterName("stable",false);
79 stableCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed);
80
81 //particle/property/lifetime
82 lifetimeCmd = new G4UIcmdWithADoubleAndUnit("/particle/property/lifetime",this);
83 lifetimeCmd->SetGuidance("Set life time.");
84 lifetimeCmd->SetGuidance("Unit of the time can be :");
85 lifetimeCmd->SetGuidance(" s, ms, ns (default)");
86 lifetimeCmd->SetParameterName("life",false);
87 lifetimeCmd->SetDefaultValue(0.0);
88 lifetimeCmd->SetRange("life >0.0");
89 //lifetimeCmd->SetUnitCategory("Time");
90 //lifetimeCmd->SetUnitCandidates("s ms ns");
91 lifetimeCmd->SetDefaultUnit("ns");
92 lifetimeCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed);
93
94 // -- particle/property/Verbose ---
95 verboseCmd = new G4UIcmdWithAnInteger("/particle/property/verbose",this);
96 verboseCmd->SetGuidance("Set Verbose level of particle property.");
97 verboseCmd->SetGuidance(" 0 : Silent (default)");
98 verboseCmd->SetGuidance(" 1 : Display warning messages");
99 verboseCmd->SetGuidance(" 2 : Display more");
100 verboseCmd->SetParameterName("verbose_level",true);
101 verboseCmd->SetDefaultValue(0);
102 verboseCmd->SetRange("verbose_level >=0");
103
104 //UI messenger for Decay Table
105 fDecayTableMessenger = new G4DecayTableMessenger(theParticleTable);
106
107}
108
109G4ParticlePropertyMessenger::~G4ParticlePropertyMessenger()
110{
111 if (fDecayTableMessenger !=0) delete fDecayTableMessenger;
112 fDecayTableMessenger = 0;
113
114 delete stableCmd;
115 delete verboseCmd;
116 delete lifetimeCmd;
117 delete dumpCmd;
118 delete thisDirectory;
119}
120
121void G4ParticlePropertyMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
122{
123 if (SetCurrentParticle()==0) {
124 G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
125 return;
126 }
127
128 if( command == dumpCmd ){
129 //Commnad /particle/property/dump
130 currentParticle->DumpTable();
131
132 } else if (command == lifetimeCmd ) {
133 //Commnad /particle/property/lifetime
134 currentParticle->SetPDGLifeTime(lifetimeCmd->GetNewDoubleValue(newValue));
135
136 } else if (command == stableCmd ) {
137 //Commnad /particle/property/stable
138 if (currentParticle->GetPDGLifeTime()<0.0) {
139 G4cout << "Life time is negative! Command ignored." << G4endl;
140 } else if (currentParticle->GetPDGMass()<=0.0) {
141 G4cout << "Zero Mass! Command ignored." << G4endl;
142 } else {
143 currentParticle->SetPDGStable(stableCmd->GetNewBoolValue(newValue));
144 }
145
146 } else if( command==verboseCmd ) {
147 //Commnad /particle/property/Verbose
148 currentParticle->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
149 }
150}
151
152G4ParticleDefinition* G4ParticlePropertyMessenger::SetCurrentParticle()
153{
154 // set currentParticle pointer
155
156 // get particle name by asking G4ParticleMessenger via UImanager
157
158 G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select");
159
160 if (currentParticle != 0 ){
161 // check whether selection is changed
162 if (currentParticle->GetParticleName() != particleName) {
163 currentParticle = theParticleTable->FindParticle(particleName);
164 }
165 } else {
166 currentParticle = theParticleTable->FindParticle(particleName);
167 }
168 return currentParticle;
169}
170
171G4String G4ParticlePropertyMessenger::GetCurrentValue(G4UIcommand * command)
172{
173 G4String returnValue('\0');
174
175 if (SetCurrentParticle()==0) {
176 // no particle is selected. return null
177 return returnValue;
178 }
179
180 if( command == stableCmd ){
181 //Commnad /particle/property/stable
182 returnValue = stableCmd->ConvertToString( currentParticle->GetPDGStable());
183
184 } else if( command == lifetimeCmd ){
185 //Commnad /particle/property/lifetime
186 returnValue = lifetimeCmd->ConvertToString( currentParticle->GetPDGLifeTime() , "ns" );
187
188 } else if( command==verboseCmd ){
189 //Commnad /particle/property/Verbose
190 returnValue= verboseCmd->ConvertToString(currentParticle ->GetVerboseLevel());
191
192 }
193
194 return returnValue;
195}
196
197
198
199
200
201
202
203
Note: See TracBrowser for help on using the repository browser.