00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "G4ios.hh"
00047 #include <iomanip>
00048
00049 #include "G4ParticleMessenger.hh"
00050 #include "G4UImanager.hh"
00051 #include "G4UIdirectory.hh"
00052 #include "G4UIcmdWithAString.hh"
00053 #include "G4UIcmdWithAnInteger.hh"
00054 #include "G4UIcmdWithoutParameter.hh"
00055 #include "G4ParticleTable.hh"
00056 #include "G4IonTable.hh"
00057 #include "G4ParticleDefinition.hh"
00058 #include "G4ParticlePropertyMessenger.hh"
00059
00060 G4ParticleMessenger::G4ParticleMessenger(G4ParticleTable* pTable)
00061 {
00062
00063 if ( pTable == 0) {
00064 theParticleTable = G4ParticleTable::GetParticleTable();
00065 } else {
00066 theParticleTable = pTable;
00067 }
00068
00069
00070 thisDirectory = new G4UIdirectory("/particle/");
00071 thisDirectory->SetGuidance("Particle control commands.");
00072
00073
00074 selectCmd = new G4UIcmdWithAString("/particle/select",this);
00075 selectCmd->SetGuidance("Select particle ");
00076 selectCmd->SetDefaultValue("none");
00077 selectCmd->SetParameterName("particle name", false);
00078 selectCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00079
00080
00081 listCmd = new G4UIcmdWithAString("/particle/list",this);
00082 listCmd->SetGuidance("List name of particles.");
00083 listCmd->SetGuidance(" all(default)/lepton/baryon/meson/nucleus/quarks");
00084 listCmd->SetParameterName("particle type", true);
00085 listCmd->SetDefaultValue("all");
00086 listCmd->SetCandidates("all lepton baryon meson nucleus quarks");
00087 listCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00088
00089
00090 findCmd = new G4UIcmdWithAnInteger("/particle/find",this);
00091 findCmd->SetGuidance("Find particle by encoding");
00092 findCmd->SetDefaultValue(0);
00093 findCmd->SetParameterName("encoding", false);
00094 findCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00095
00096
00097 createAllCmd = new G4UIcmdWithoutParameter("/particle/createAllIon",this);
00098 createAllCmd->SetGuidance("Create All ions");
00099 createAllCmd->AvailableForStates(G4State_Idle);
00100
00101
00102 verboseCmd = new G4UIcmdWithAnInteger("/particle/verbose",this);
00103 verboseCmd->SetGuidance("Set Verbose level of particle table.");
00104 verboseCmd->SetGuidance(" 0 : Silent (default)");
00105 verboseCmd->SetGuidance(" 1 : Display warning messages");
00106 verboseCmd->SetGuidance(" 2 : Display more");
00107 verboseCmd->SetParameterName("verbose_level",true);
00108 verboseCmd->SetDefaultValue(0);
00109 verboseCmd->SetRange("verbose_level >=0");
00110
00111 currentParticle = 0;
00112
00113
00114 fParticlePropertyMessenger = new G4ParticlePropertyMessenger(theParticleTable);
00115
00116 }
00117
00118 G4ParticleMessenger::~G4ParticleMessenger()
00119 {
00120 delete fParticlePropertyMessenger;
00121
00122 delete listCmd;
00123 delete selectCmd;
00124 delete findCmd;
00125 delete createAllCmd;
00126 delete verboseCmd;
00127
00128 delete thisDirectory;
00129 }
00130
00131
00132 void G4ParticleMessenger::SetNewValue(G4UIcommand * command,G4String newValues)
00133 {
00134 if( command==listCmd ){
00135
00136 G4int counter = 0;
00137 G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator();
00138 piter -> reset();
00139
00140 while( (*piter)() ){
00141 G4ParticleDefinition *particle = piter->value();
00142 if ((newValues=="all") || (newValues==particle->GetParticleType())) {
00143 G4cout << std::setw(19) << particle->GetParticleName();
00144 if ((counter++)%4 == 3) {
00145 G4cout << G4endl;
00146 } else {
00147 G4cout << ",";
00148 }
00149 }
00150 }
00151 G4cout << G4endl;
00152 if (counter == 0) G4cout << newValues << " is not found " << G4endl;
00153
00154
00155
00156 G4String candidates("none");
00157 piter -> reset();
00158 while( (*piter)() ){
00159 G4ParticleDefinition *particle = piter->value();
00160 candidates += " " + particle->GetParticleName();
00161 }
00162 selectCmd->SetCandidates((const char *)(candidates));
00163
00164 } else if( command==selectCmd ){
00165
00166 currentParticle = theParticleTable->FindParticle(newValues);
00167 if(currentParticle == 0) {
00168 G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl;
00169 }
00170
00171 } else if( command==findCmd ){
00172
00173 G4ParticleDefinition* tmp = theParticleTable->FindParticle( findCmd->GetNewIntValue(newValues));
00174 if(tmp == 0) {
00175 G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl;
00176 } else {
00177 G4cout << tmp->GetParticleName() << G4endl;
00178 tmp->DumpTable();
00179 }
00180
00181 } else if( command==createAllCmd ) {
00182
00183 theParticleTable->GetIonTable()->CreateAllIon();
00184
00185 } else if( command==verboseCmd ) {
00186
00187 theParticleTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValues));
00188 }
00189 }
00190
00191 G4String G4ParticleMessenger::GetCurrentValue(G4UIcommand * command)
00192 {
00193 if( command==selectCmd ){
00194
00195
00196 G4String candidates("none");
00197 G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator();
00198 piter -> reset();
00199 while( (*piter)() ){
00200 G4ParticleDefinition *particle = piter->value();
00201 candidates += " " + particle->GetParticleName();
00202 }
00203 selectCmd->SetCandidates((const char *)(candidates));
00204
00205 static G4String noName("none");
00206
00207 if(currentParticle == 0) {
00208
00209 return noName;
00210 } else {
00211 return currentParticle->GetParticleName();
00212 }
00213 } else if( command==verboseCmd ){
00214
00215 return verboseCmd->ConvertToString(theParticleTable->GetVerboseLevel());
00216 }
00217 return "";
00218 }
00219
00220
00221
00222
00223
00224