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