| [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 | //
|
|---|
| [850] | 27 | // $Id: G4ParticleMessenger.cc,v 1.10 2008/06/08 12:43:19 kurasige Exp $
|
|---|
| [992] | 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $
|
|---|
| [824] | 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 "G4ParticleTable.hh"
|
|---|
| 56 | #include "G4ParticleDefinition.hh"
|
|---|
| 57 | #include "G4ParticlePropertyMessenger.hh"
|
|---|
| 58 |
|
|---|
| 59 | G4ParticleMessenger::G4ParticleMessenger(G4ParticleTable* pTable)
|
|---|
| 60 | {
|
|---|
| 61 | // get the pointer to ParticleTable
|
|---|
| 62 | if ( pTable == 0) {
|
|---|
| 63 | theParticleTable = G4ParticleTable::GetParticleTable();
|
|---|
| 64 | } else {
|
|---|
| 65 | theParticleTable = pTable;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | //Directory /particle/
|
|---|
| 69 | thisDirectory = new G4UIdirectory("/particle/");
|
|---|
| 70 | thisDirectory->SetGuidance("Particle control commands.");
|
|---|
| 71 |
|
|---|
| 72 | //Commnad /particle/select
|
|---|
| 73 | selectCmd = new G4UIcmdWithAString("/particle/select",this);
|
|---|
| 74 | selectCmd->SetGuidance("Select particle ");
|
|---|
| 75 | selectCmd->SetDefaultValue("none");
|
|---|
| 76 | selectCmd->SetParameterName("particle name", false);
|
|---|
| 77 |
|
|---|
| 78 | //Commnad /particle/list
|
|---|
| 79 | listCmd = new G4UIcmdWithAString("/particle/list",this);
|
|---|
| 80 | listCmd->SetGuidance("List name of particles.");
|
|---|
| 81 | listCmd->SetGuidance(" all(default)/lepton/baryon/meson/nucleus/quarks");
|
|---|
| 82 | listCmd->SetParameterName("particle type", true);
|
|---|
| 83 | listCmd->SetDefaultValue("all");
|
|---|
| 84 | listCmd->SetCandidates("all lepton baryon meson nucleus quarks");
|
|---|
| 85 |
|
|---|
| 86 | //Commnad /particle/find
|
|---|
| 87 | findCmd = new G4UIcmdWithAnInteger("/particle/find",this);
|
|---|
| 88 | findCmd->SetGuidance("Find particle by encoding");
|
|---|
| 89 | findCmd->SetDefaultValue(0);
|
|---|
| 90 | findCmd->SetParameterName("encoding", false);
|
|---|
| 91 |
|
|---|
| [850] | 92 | // -- particle/property/Verbose ---
|
|---|
| 93 | verboseCmd = new G4UIcmdWithAnInteger("/particle/verbose",this);
|
|---|
| 94 | verboseCmd->SetGuidance("Set Verbose level of particle table.");
|
|---|
| 95 | verboseCmd->SetGuidance(" 0 : Silent (default)");
|
|---|
| 96 | verboseCmd->SetGuidance(" 1 : Display warning messages");
|
|---|
| 97 | verboseCmd->SetGuidance(" 2 : Display more");
|
|---|
| 98 | verboseCmd->SetParameterName("verbose_level",true);
|
|---|
| 99 | verboseCmd->SetDefaultValue(0);
|
|---|
| 100 | verboseCmd->SetRange("verbose_level >=0");
|
|---|
| 101 |
|
|---|
| [824] | 102 | currentParticle = 0;
|
|---|
| 103 |
|
|---|
| 104 | //UI messenger for Particle Properties
|
|---|
| 105 | fParticlePropertyMessenger = new G4ParticlePropertyMessenger(theParticleTable);
|
|---|
| 106 |
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | G4ParticleMessenger::~G4ParticleMessenger()
|
|---|
| 110 | {
|
|---|
| 111 | delete fParticlePropertyMessenger;
|
|---|
| [850] | 112 |
|
|---|
| [824] | 113 | delete listCmd;
|
|---|
| 114 | delete selectCmd;
|
|---|
| [850] | 115 | delete findCmd;
|
|---|
| 116 | delete verboseCmd;
|
|---|
| 117 |
|
|---|
| [824] | 118 | delete thisDirectory;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 | void G4ParticleMessenger::SetNewValue(G4UIcommand * command,G4String newValues)
|
|---|
| 123 | {
|
|---|
| 124 | if( command==listCmd ){
|
|---|
| 125 | //Commnad /particle/List
|
|---|
| 126 | G4int counter = 0;
|
|---|
| 127 | G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator();
|
|---|
| 128 | piter -> reset();
|
|---|
| 129 |
|
|---|
| 130 | while( (*piter)() ){
|
|---|
| 131 | G4ParticleDefinition *particle = piter->value();
|
|---|
| 132 | if ((newValues=="all") || (newValues==particle->GetParticleType())) {
|
|---|
| 133 | G4cout << std::setw(19) << particle->GetParticleName();
|
|---|
| 134 | if ((counter++)%4 == 3) {
|
|---|
| 135 | G4cout << G4endl;
|
|---|
| 136 | } else {
|
|---|
| 137 | G4cout << ",";
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 | G4cout << G4endl;
|
|---|
| 142 | if (counter == 0) G4cout << newValues << " is not found " << G4endl;
|
|---|
| 143 |
|
|---|
| 144 | //Command /particle/select
|
|---|
| 145 | // set candidate List
|
|---|
| 146 | G4String candidates("none");
|
|---|
| 147 | piter -> reset();
|
|---|
| 148 | while( (*piter)() ){
|
|---|
| 149 | G4ParticleDefinition *particle = piter->value();
|
|---|
| 150 | candidates += " " + particle->GetParticleName();
|
|---|
| 151 | }
|
|---|
| 152 | selectCmd->SetCandidates((const char *)(candidates));
|
|---|
| 153 |
|
|---|
| 154 | } else if( command==selectCmd ){
|
|---|
| 155 | //Commnad /particle/select
|
|---|
| 156 | currentParticle = theParticleTable->FindParticle(newValues);
|
|---|
| 157 | if(currentParticle == 0) {
|
|---|
| 158 | G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl;
|
|---|
| 159 | }
|
|---|
| 160 | } else if( command==findCmd ){
|
|---|
| 161 | //Commnad /particle/find
|
|---|
| 162 | G4ParticleDefinition* tmp = theParticleTable->FindParticle( findCmd->GetNewIntValue(newValues));
|
|---|
| 163 | if(tmp == 0) {
|
|---|
| 164 | G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl;
|
|---|
| 165 | } else {
|
|---|
| 166 | G4cout << tmp->GetParticleName() << G4endl;
|
|---|
| 167 | tmp->DumpTable();
|
|---|
| 168 | }
|
|---|
| [850] | 169 | } else if( command==verboseCmd ) {
|
|---|
| 170 | //Commnad /particle/verbose
|
|---|
| 171 | theParticleTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValues));
|
|---|
| [824] | 172 | }
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | G4String G4ParticleMessenger::GetCurrentValue(G4UIcommand * command)
|
|---|
| 176 | {
|
|---|
| 177 | if( command==selectCmd ){
|
|---|
| 178 | //Command /particle/select
|
|---|
| 179 | // set candidate List
|
|---|
| 180 | G4String candidates("none");
|
|---|
| 181 | G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator();
|
|---|
| 182 | piter -> reset();
|
|---|
| 183 | while( (*piter)() ){
|
|---|
| 184 | G4ParticleDefinition *particle = piter->value();
|
|---|
| 185 | candidates += " " + particle->GetParticleName();
|
|---|
| 186 | }
|
|---|
| 187 | selectCmd->SetCandidates((const char *)(candidates));
|
|---|
| 188 |
|
|---|
| 189 | static G4String noName("none");
|
|---|
| 190 | // current value
|
|---|
| 191 | if(currentParticle == 0) {
|
|---|
| 192 | // no particle is selected. return null
|
|---|
| 193 | return noName;
|
|---|
| 194 | } else {
|
|---|
| 195 | return currentParticle->GetParticleName();
|
|---|
| 196 | }
|
|---|
| [850] | 197 | } else if( command==verboseCmd ){
|
|---|
| 198 | //Commnad /particle/verbose
|
|---|
| 199 | return verboseCmd->ConvertToString(theParticleTable->GetVerboseLevel());
|
|---|
| [824] | 200 | }
|
|---|
| 201 | return "";
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|