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