Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleMessenger.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 //
27 // $Id$
28 //
29 //
30 //---------------------------------------------------------------
31 //
32 // G4ParticleMessenger.cc
33 //
34 // Description:
35 // This is a messenger class to interface to exchange information
36 // between Particle related classes and UI.
37 //
38 // History:
39 // 13 June 1997, H. Kurashige : The 1st version created.
40 // 10 Nov. 1997 H. Kurashige : fixed bugs
41 // 08 Jan. 1998 H. Kurashige : new UIcommnds
42 // 08 June 1998, H. Kurashige : remove fProcessManagerMessenger
43 // 25 Nov. 1998, H. Kurashige : add /particle/find
44 //---------------------------------------------------------------
45 
46 #include "G4ios.hh" // Include from 'system'
47 #include <iomanip> // Include from 'system'
48 
49 #include "G4ParticleMessenger.hh"
50 #include "G4UImanager.hh"
51 #include "G4UIdirectory.hh"
52 #include "G4UIcmdWithAString.hh"
53 #include "G4UIcmdWithAnInteger.hh"
55 #include "G4ParticleTable.hh"
56 #include "G4IonTable.hh"
57 #include "G4ParticleDefinition.hh"
59 
61 {
62  // get the pointer to ParticleTable
63  if ( pTable == 0) {
64  theParticleTable = G4ParticleTable::GetParticleTable();
65  } else {
66  theParticleTable = pTable;
67  }
68 
69  //Directory /particle/
70  thisDirectory = new G4UIdirectory("/particle/");
71  thisDirectory->SetGuidance("Particle control commands.");
72 
73  //Commnad /particle/select
74  selectCmd = new G4UIcmdWithAString("/particle/select",this);
75  selectCmd->SetGuidance("Select particle ");
76  selectCmd->SetDefaultValue("none");
77  selectCmd->SetParameterName("particle name", false);
79 
80  //Commnad /particle/list
81  listCmd = new G4UIcmdWithAString("/particle/list",this);
82  listCmd->SetGuidance("List name of particles.");
83  listCmd->SetGuidance(" all(default)/lepton/baryon/meson/nucleus/quarks");
84  listCmd->SetParameterName("particle type", true);
85  listCmd->SetDefaultValue("all");
86  listCmd->SetCandidates("all lepton baryon meson nucleus quarks");
88 
89  //Commnad /particle/find
90  findCmd = new G4UIcmdWithAnInteger("/particle/find",this);
91  findCmd->SetGuidance("Find particle by encoding");
92  findCmd->SetDefaultValue(0);
93  findCmd->SetParameterName("encoding", false);
95 
96  //Commnad /particle/createAllIon
97  createAllCmd = new G4UIcmdWithoutParameter("/particle/createAllIon",this);
98  createAllCmd->SetGuidance("Create All ions");
99  createAllCmd->AvailableForStates(G4State_Idle);
100 
101  // -- particle/property/Verbose ---
102  verboseCmd = new G4UIcmdWithAnInteger("/particle/verbose",this);
103  verboseCmd->SetGuidance("Set Verbose level of particle table.");
104  verboseCmd->SetGuidance(" 0 : Silent (default)");
105  verboseCmd->SetGuidance(" 1 : Display warning messages");
106  verboseCmd->SetGuidance(" 2 : Display more");
107  verboseCmd->SetParameterName("verbose_level",true);
108  verboseCmd->SetDefaultValue(0);
109  verboseCmd->SetRange("verbose_level >=0");
110 
111  currentParticle = 0;
112 
113  //UI messenger for Particle Properties
114  fParticlePropertyMessenger = new G4ParticlePropertyMessenger(theParticleTable);
115 
116 }
117 
119 {
120  delete fParticlePropertyMessenger;
121 
122  delete listCmd;
123  delete selectCmd;
124  delete findCmd;
125  delete createAllCmd;
126  delete verboseCmd;
127 
128  delete thisDirectory;
129 }
130 
131 
133 {
134  if( command==listCmd ){
135  //Commnad /particle/List
136  G4int counter = 0;
137  G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator();
138  piter -> reset();
139 
140  while( (*piter)() ){
141  G4ParticleDefinition *particle = piter->value();
142  if ((newValues=="all") || (newValues==particle->GetParticleType())) {
143  G4cout << std::setw(19) << particle->GetParticleName();
144  if ((counter++)%4 == 3) {
145  G4cout << G4endl;
146  } else {
147  G4cout << ",";
148  }
149  }
150  }
151  G4cout << G4endl;
152  if (counter == 0) G4cout << newValues << " is not found " << G4endl;
153 
154  //Command /particle/select
155  // set candidate List
156  G4String candidates("none");
157  piter -> reset();
158  while( (*piter)() ){
159  G4ParticleDefinition *particle = piter->value();
160  candidates += " " + particle->GetParticleName();
161  }
162  selectCmd->SetCandidates((const char *)(candidates));
163 
164  } else if( command==selectCmd ){
165  //Commnad /particle/select
166  currentParticle = theParticleTable->FindParticle(newValues);
167  if(currentParticle == 0) {
168  G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl;
169  }
170 
171  } else if( command==findCmd ){
172  //Commnad /particle/find
173  G4ParticleDefinition* tmp = theParticleTable->FindParticle( findCmd->GetNewIntValue(newValues));
174  if(tmp == 0) {
175  G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl;
176  } else {
177  G4cout << tmp->GetParticleName() << G4endl;
178  tmp->DumpTable();
179  }
180 
181  } else if( command==createAllCmd ) {
182  //Commnad /particle/createAllIon
183  theParticleTable->GetIonTable()->CreateAllIon();
184 
185  } else if( command==verboseCmd ) {
186  //Commnad /particle/verbose
187  theParticleTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValues));
188  }
189 }
190 
192 {
193  if( command==selectCmd ){
194  //Command /particle/select
195  // set candidate List
196  G4String candidates("none");
197  G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator();
198  piter -> reset();
199  while( (*piter)() ){
200  G4ParticleDefinition *particle = piter->value();
201  candidates += " " + particle->GetParticleName();
202  }
203  selectCmd->SetCandidates((const char *)(candidates));
204 
205  static G4String noName("none");
206  // current value
207  if(currentParticle == 0) {
208  // no particle is selected. return null
209  return noName;
210  } else {
211  return currentParticle->GetParticleName();
212  }
213  } else if( command==verboseCmd ){
214  //Commnad /particle/verbose
215  return verboseCmd->ConvertToString(theParticleTable->GetVerboseLevel());
216  }
217  return "";
218 }
219 
220 
221 
222 
223 
224