G4ParticleMessenger.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 //
00030 //---------------------------------------------------------------
00031 //
00032 //  G4ParticleMessenger.cc
00033 //
00034 //  Description:
00035 //    This is a messenger class to interface to exchange information
00036 //    between Particle related classes and UI.
00037 //
00038 //  History:
00039 //    13 June 1997, H. Kurashige   : The 1st version created.
00040 //    10 Nov. 1997  H. Kurashige   : fixed bugs 
00041 //    08 Jan. 1998  H. Kurashige   : new UIcommnds 
00042 //    08 June 1998, H. Kurashige   : remove fProcessManagerMessenger
00043 //    25 Nov. 1998, H. Kurashige   : add /particle/find
00044 //---------------------------------------------------------------
00045 
00046 #include "G4ios.hh"                 // Include from 'system'
00047 #include <iomanip>                  // Include from 'system'
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   // get the pointer to ParticleTable
00063   if ( pTable == 0) {
00064     theParticleTable = G4ParticleTable::GetParticleTable();
00065   } else {
00066     theParticleTable = pTable;
00067   }
00068  
00069   //Directory   /particle/
00070   thisDirectory = new G4UIdirectory("/particle/");
00071   thisDirectory->SetGuidance("Particle control commands.");
00072 
00073   //Commnad   /particle/select
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   //Commnad   /particle/list
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   //Commnad   /particle/find 
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   //Commnad   /particle/createAllIon
00097   createAllCmd = new G4UIcmdWithoutParameter("/particle/createAllIon",this);
00098   createAllCmd->SetGuidance("Create All ions");
00099   createAllCmd->AvailableForStates(G4State_Idle);
00100 
00101   // -- particle/property/Verbose ---
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   //UI messenger for Particle Properties
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     //Commnad   /particle/List
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    //Command  /particle/select
00155     // set candidate List
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     //Commnad   /particle/select
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     //Commnad   /particle/find
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     //Commnad   /particle/createAllIon
00183     theParticleTable->GetIonTable()->CreateAllIon();
00184 
00185   } else if( command==verboseCmd ) {
00186     //Commnad   /particle/verbose
00187     theParticleTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValues));
00188   }    
00189 }
00190 
00191 G4String G4ParticleMessenger::GetCurrentValue(G4UIcommand * command)
00192 {
00193   if( command==selectCmd ){
00194     //Command  /particle/select
00195     // set candidate List
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     // current value
00207     if(currentParticle == 0) {
00208       // no particle is selected. return null 
00209       return noName;
00210     } else {
00211       return currentParticle->GetParticleName();
00212     }
00213   } else if( command==verboseCmd ){
00214     //Commnad   /particle/verbose
00215     return verboseCmd->ConvertToString(theParticleTable->GetVerboseLevel());
00216   }
00217   return "";
00218 }
00219 
00220 
00221 
00222 
00223 
00224 

Generated on Mon May 27 17:49:16 2013 for Geant4 by  doxygen 1.4.7