Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4ParticleMessenger class implementation << 27 // 26 // 28 // Author: H. Kurashige, 13 June 1997 - 1st ve << 27 // $Id: G4ParticleMessenger.cc 91885 2015-08-10 07:05:56Z gcosmo $ 29 // ------------------------------------------- << 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 //--------------------------------------------------------------- 30 45 31 #include "G4ParticleMessenger.hh" << 46 #include "G4ios.hh" // Include from 'system' >> 47 #include <iomanip> // Include from 'system' 32 48 33 #include "G4IonTable.hh" << 49 #include "G4ParticleMessenger.hh" 34 #include "G4ParticleDefinition.hh" << 50 #include "G4UImanager.hh" 35 #include "G4ParticlePropertyMessenger.hh" << 51 #include "G4UIdirectory.hh" 36 #include "G4ParticleTable.hh" << 37 #include "G4UIcmdWithAString.hh" 52 #include "G4UIcmdWithAString.hh" 38 #include "G4UIcmdWithAnInteger.hh" 53 #include "G4UIcmdWithAnInteger.hh" 39 #include "G4UIcmdWithoutParameter.hh" 54 #include "G4UIcmdWithoutParameter.hh" 40 #include "G4UIdirectory.hh" << 55 #include "G4ParticleTable.hh" 41 #include "G4UImanager.hh" << 56 #include "G4IonTable.hh" 42 #include "G4ios.hh" << 57 #include "G4ParticleDefinition.hh" 43 << 58 #include "G4ParticlePropertyMessenger.hh" 44 #include <iomanip> // Include from 'system' << 45 59 46 G4ParticleMessenger::G4ParticleMessenger(G4Par 60 G4ParticleMessenger::G4ParticleMessenger(G4ParticleTable* pTable) 47 { 61 { 48 // get the pointer to ParticleTable 62 // get the pointer to ParticleTable 49 if (pTable == nullptr) { << 63 if ( pTable == 0) { 50 theParticleTable = G4ParticleTable::GetPar 64 theParticleTable = G4ParticleTable::GetParticleTable(); 51 } << 65 } else { 52 else { << 53 theParticleTable = pTable; 66 theParticleTable = pTable; 54 } 67 } 55 << 68 56 // Directory /particle/ << 69 //Directory /particle/ 57 thisDirectory = new G4UIdirectory("/particle 70 thisDirectory = new G4UIdirectory("/particle/"); 58 thisDirectory->SetGuidance("Particle control 71 thisDirectory->SetGuidance("Particle control commands."); 59 72 60 // Command /particle/select << 73 //Commnad /particle/select 61 selectCmd = new G4UIcmdWithAString("/particl << 74 selectCmd = new G4UIcmdWithAString("/particle/select",this); 62 selectCmd->SetGuidance("Select particle "); 75 selectCmd->SetGuidance("Select particle "); 63 selectCmd->SetDefaultValue("none"); 76 selectCmd->SetDefaultValue("none"); 64 selectCmd->SetParameterName("particle name", 77 selectCmd->SetParameterName("particle name", false); 65 selectCmd->AvailableForStates(G4State_PreIni << 78 selectCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 66 79 67 // Command /particle/list << 80 //Commnad /particle/list 68 listCmd = new G4UIcmdWithAString("/particle/ << 81 listCmd = new G4UIcmdWithAString("/particle/list",this); 69 listCmd->SetGuidance("List name of particles 82 listCmd->SetGuidance("List name of particles."); 70 listCmd->SetGuidance(" all(default)/lepton/b 83 listCmd->SetGuidance(" all(default)/lepton/baryon/meson/nucleus/quarks"); 71 listCmd->SetParameterName("particle type", t 84 listCmd->SetParameterName("particle type", true); 72 listCmd->SetDefaultValue("all"); 85 listCmd->SetDefaultValue("all"); 73 listCmd->SetCandidates("all lepton baryon me 86 listCmd->SetCandidates("all lepton baryon meson nucleus quarks"); 74 listCmd->AvailableForStates(G4State_PreInit, << 87 listCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 75 88 76 // Command /particle/find << 89 //Commnad /particle/find 77 findCmd = new G4UIcmdWithAnInteger("/particl << 90 findCmd = new G4UIcmdWithAnInteger("/particle/find",this); 78 findCmd->SetGuidance("Find particle by encod 91 findCmd->SetGuidance("Find particle by encoding"); 79 findCmd->SetDefaultValue(0); 92 findCmd->SetDefaultValue(0); 80 findCmd->SetParameterName("encoding", false) 93 findCmd->SetParameterName("encoding", false); 81 findCmd->AvailableForStates(G4State_PreInit, << 94 findCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 82 95 83 // Command /particle/createAllIon << 96 //Commnad /particle/createAllIon 84 createAllIonCmd = new G4UIcmdWithoutParamete << 97 createAllIonCmd = new G4UIcmdWithoutParameter("/particle/createAllIon",this); 85 createAllIonCmd->SetGuidance("Create All ion 98 createAllIonCmd->SetGuidance("Create All ions (ground state)"); 86 createAllIonCmd->AvailableForStates(G4State_ 99 createAllIonCmd->AvailableForStates(G4State_Idle); 87 createAllIonCmd->SetToBeBroadcasted(false); 100 createAllIonCmd->SetToBeBroadcasted(false); 88 101 89 // Command /particle/createAllIsomer << 102 //Commnad /particle/createAllIsomer 90 createAllIsomerCmd = new G4UIcmdWithoutParam << 103 createAllIsomerCmd = new G4UIcmdWithoutParameter("/particle/createAllIsomer",this); 91 createAllIsomerCmd->SetGuidance("Create All 104 createAllIsomerCmd->SetGuidance("Create All isomers"); 92 createAllIsomerCmd->AvailableForStates(G4Sta 105 createAllIsomerCmd->AvailableForStates(G4State_Idle); 93 createAllIsomerCmd->SetToBeBroadcasted(false 106 createAllIsomerCmd->SetToBeBroadcasted(false); 94 107 95 // -- particle/property/Verbose --- 108 // -- particle/property/Verbose --- 96 verboseCmd = new G4UIcmdWithAnInteger("/part << 109 verboseCmd = new G4UIcmdWithAnInteger("/particle/verbose",this); 97 verboseCmd->SetGuidance("Set Verbose level o 110 verboseCmd->SetGuidance("Set Verbose level of particle table."); 98 verboseCmd->SetGuidance(" 0 : Silent (defaul 111 verboseCmd->SetGuidance(" 0 : Silent (default)"); 99 verboseCmd->SetGuidance(" 1 : Display warnin 112 verboseCmd->SetGuidance(" 1 : Display warning messages"); 100 verboseCmd->SetGuidance(" 2 : Display more") 113 verboseCmd->SetGuidance(" 2 : Display more"); 101 verboseCmd->SetParameterName("verbose_level" << 114 verboseCmd->SetParameterName("verbose_level",true); 102 verboseCmd->SetDefaultValue(0); 115 verboseCmd->SetDefaultValue(0); 103 verboseCmd->SetRange("verbose_level >=0"); 116 verboseCmd->SetRange("verbose_level >=0"); 104 117 105 // UI messenger for Particle Properties << 118 currentParticle = 0; >> 119 >> 120 //UI messenger for Particle Properties 106 fParticlePropertyMessenger = new G4ParticleP 121 fParticlePropertyMessenger = new G4ParticlePropertyMessenger(theParticleTable); >> 122 107 } 123 } 108 124 109 G4ParticleMessenger::~G4ParticleMessenger() 125 G4ParticleMessenger::~G4ParticleMessenger() 110 { 126 { 111 delete fParticlePropertyMessenger; 127 delete fParticlePropertyMessenger; 112 128 113 delete listCmd; << 129 delete listCmd; 114 delete selectCmd; 130 delete selectCmd; 115 delete findCmd; 131 delete findCmd; 116 delete createAllIonCmd; 132 delete createAllIonCmd; 117 delete createAllIsomerCmd; 133 delete createAllIsomerCmd; 118 delete verboseCmd; 134 delete verboseCmd; 119 135 120 delete thisDirectory; 136 delete thisDirectory; 121 } 137 } 122 138 123 void G4ParticleMessenger::SetNewValue(G4UIcomm << 139 >> 140 void G4ParticleMessenger::SetNewValue(G4UIcommand * command,G4String newValues) 124 { 141 { 125 if (command == listCmd) { << 142 if( command==listCmd ){ 126 // Command /particle/List << 143 //Commnad /particle/List 127 G4int counter = 0; 144 G4int counter = 0; 128 G4ParticleTable::G4PTblDicIterator* piter << 145 G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator(); 129 piter->reset(); << 146 piter -> reset(); 130 << 147 131 while ((*piter)()) // Loop checking, 09.0 << 148 while( (*piter)() ){// Loop checking, 09.08.2015, K.Kurashige 132 { << 149 G4ParticleDefinition *particle = piter->value(); 133 G4ParticleDefinition* particle = piter-> << 150 if ((newValues=="all") || (newValues==particle->GetParticleType())) { 134 if ((newValues == "all") || (newValues = << 135 G4cout << std::setw(19) << particle->G 151 G4cout << std::setw(19) << particle->GetParticleName(); 136 if ((counter++) % 4 == 3) { << 152 if ((counter++)%4 == 3) { 137 G4cout << G4endl; << 153 G4cout << G4endl; 138 } << 154 } else { 139 else { << 155 G4cout << ","; 140 G4cout << ","; << 156 } 141 } << 142 } 157 } 143 } 158 } 144 G4cout << G4endl; 159 G4cout << G4endl; 145 if (counter == 0) { << 160 if (counter == 0) G4cout << newValues << " is not found " << G4endl; 146 G4cout << newValues << " is not found " << 161 147 } << 162 //Command /particle/select 148 << 149 // Command /particle/select << 150 // set candidate List 163 // set candidate List 151 G4String candidates("none"); 164 G4String candidates("none"); 152 piter->reset(); << 165 piter -> reset(); 153 while ((*piter)()) // Loop checking, 09.0 << 166 while( (*piter)() ){// Loop checking, 09.08.2015, K.Kurashige 154 { << 167 G4ParticleDefinition *particle = piter->value(); 155 G4ParticleDefinition* particle = piter-> << 156 candidates += " " + particle->GetParticl 168 candidates += " " + particle->GetParticleName(); 157 } 169 } 158 selectCmd->SetCandidates((const char*)(can << 170 selectCmd->SetCandidates((const char *)(candidates)); 159 } << 171 160 else if (command == selectCmd) { << 172 } else if( command==selectCmd ){ 161 // Command /particle/select << 173 //Commnad /particle/select 162 theParticleTable->SelectParticle(newValues << 174 currentParticle = theParticleTable->FindParticle(newValues); 163 } << 175 if(currentParticle == 0) { 164 else if (command == findCmd) { << 165 // Command /particle/find << 166 G4ParticleDefinition* tmp = theParticleTab << 167 if (tmp == nullptr) { << 168 G4cout << "Unknown particle [" << newVal 176 G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl; 169 } << 177 } 170 else { << 178 >> 179 } else if( command==findCmd ){ >> 180 //Commnad /particle/find >> 181 G4ParticleDefinition* tmp = theParticleTable->FindParticle( findCmd->GetNewIntValue(newValues)); >> 182 if(tmp == 0) { >> 183 G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl; >> 184 } else { 171 G4cout << tmp->GetParticleName() << G4en 185 G4cout << tmp->GetParticleName() << G4endl; 172 tmp->DumpTable(); 186 tmp->DumpTable(); 173 } 187 } 174 } << 188 175 else if (command == createAllIonCmd) { << 189 } else if( command==createAllIonCmd ) { 176 // Command /particle/createAllIon << 190 //Commnad /particle/createAllIon 177 theParticleTable->GetIonTable()->CreateAll 191 theParticleTable->GetIonTable()->CreateAllIon(); 178 } << 192 179 else if (command == createAllIsomerCmd) { << 193 } else if( command==createAllIsomerCmd ) { 180 // Command /particle/createAllIsomer << 194 //Commnad /particle/createAllIsomer 181 theParticleTable->GetIonTable()->CreateAll 195 theParticleTable->GetIonTable()->CreateAllIsomer(); 182 } << 196 183 else if (command == verboseCmd) { << 197 } else if( command==verboseCmd ) { 184 // Command /particle/verbose << 198 //Commnad /particle/verbose 185 theParticleTable->SetVerboseLevel(verboseC 199 theParticleTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValues)); 186 } << 200 } 187 } 201 } 188 202 189 G4String G4ParticleMessenger::GetCurrentValue( << 203 G4String G4ParticleMessenger::GetCurrentValue(G4UIcommand * command) 190 { 204 { 191 if (command == selectCmd) { << 205 if( command==selectCmd ){ 192 // Command /particle/select << 206 //Command /particle/select 193 // set candidate List 207 // set candidate List 194 G4String candidates("none"); 208 G4String candidates("none"); 195 G4ParticleTable::G4PTblDicIterator* piter << 209 G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator(); 196 piter->reset(); << 210 piter -> reset(); 197 while ((*piter)()) // Loop checking, 09.0 << 211 while( (*piter)() ){// Loop checking, 09.08.2015, K.Kurashige 198 { << 212 G4ParticleDefinition *particle = piter->value(); 199 G4ParticleDefinition* particle = piter-> << 200 candidates += " " + particle->GetParticl 213 candidates += " " + particle->GetParticleName(); 201 } 214 } 202 selectCmd->SetCandidates((const char*)(can << 215 selectCmd->SetCandidates((const char *)(candidates)); 203 216 204 const G4ParticleDefinition* currentParticl << 217 static const G4String noName("none"); 205 return (currentParticle == nullptr) ? G4St << 218 // current value 206 } << 219 if(currentParticle == 0) { 207 if (command == verboseCmd) { << 220 // no particle is selected. return null 208 // Command /particle/verbose << 221 return noName; >> 222 } else { >> 223 return currentParticle->GetParticleName(); >> 224 } >> 225 } else if( command==verboseCmd ){ >> 226 //Commnad /particle/verbose 209 return verboseCmd->ConvertToString(thePart 227 return verboseCmd->ConvertToString(theParticleTable->GetVerboseLevel()); 210 } 228 } 211 return ""; 229 return ""; 212 } 230 } >> 231 >> 232 >> 233 >> 234 >> 235 >> 236 213 237