Geant4 Cross Reference |
>> 1 // This code implementation is the intellectual property of >> 2 // the GEANT4 collaboration. 1 // 3 // 2 // ******************************************* << 4 // By copying, distributing or modifying the Program (or any work 3 // * License and Disclaimer << 5 // based on the Program) you indicate your acceptance of this statement, 4 // * << 6 // and all its terms. 5 // * The Geant4 software is copyright of th << 6 // * the Geant4 Collaboration. It is provided << 7 // * conditions of the Geant4 Software License << 8 // * LICENSE and available at http://cern.ch/ << 9 // * include a list of copyright holders. << 10 // * << 11 // * Neither the authors of this software syst << 12 // * institutes,nor the agencies providing fin << 13 // * work make any representation or warran << 14 // * regarding this software system or assum << 15 // * use. Please see the license in the file << 16 // * for the full disclaimer and the limitatio << 17 // * << 18 // * This code implementation is the result << 19 // * technical work of the GEANT4 collaboratio << 20 // * By using, copying, modifying or distri << 21 // * any work based on the software) you ag << 22 // * use in resulting scientific publicati << 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* << 25 // 7 // 26 // G4ProcessManagerMessenger class implementat << 8 // $Id: G4ProcessManagerMessenger.cc,v 1.4 1999/12/15 14:53:43 gunter Exp $ >> 9 // GEANT4 tag $Name: geant4-03-00 $ >> 10 // >> 11 // >> 12 //--------------------------------------------------------------- >> 13 // >> 14 // G4ProcessManagerMessenger.cc 27 // 15 // 28 // Description: 16 // Description: 29 // This is a messenger class to interface t 17 // This is a messenger class to interface to exchange information 30 // between ProcessManagerand UI. 18 // between ProcessManagerand UI. 31 // 19 // 32 // Author: H.Kurashige, 13 June 1997 << 20 // History: 33 //-------------------------------------------- << 21 // 13 June 1997, H. Kurashige : The 1st version created. >> 22 // 10 Nov. 1997 H. Kurashige : fixed bugs >> 23 // 08 jan. 1998 H. Kurashige : new UIcommnds >> 24 // >> 25 //--------------------------------------------------------------- >> 26 34 27 35 #include "G4UImanager.hh" 28 #include "G4UImanager.hh" 36 #include "G4UIdirectory.hh" 29 #include "G4UIdirectory.hh" 37 #include "G4UIcmdWithoutParameter.hh" 30 #include "G4UIcmdWithoutParameter.hh" 38 #include "G4UIcmdWithAnInteger.hh" 31 #include "G4UIcmdWithAnInteger.hh" 39 32 40 #include "G4VProcess.hh" 33 #include "G4VProcess.hh" 41 #include "G4ProcessManager.hh" 34 #include "G4ProcessManager.hh" 42 #include "G4ParticleTable.hh" 35 #include "G4ParticleTable.hh" 43 36 44 #include "G4ProcessManagerMessenger.hh" 37 #include "G4ProcessManagerMessenger.hh" 45 #include "G4ios.hh" // Include 38 #include "G4ios.hh" // Include from 'system' 46 #include <iomanip> // Include << 39 #include "g4std/iomanip" // Include from 'system' 47 #include <sstream> << 40 >> 41 #include "g4std/strstream" 48 42 49 //-------------------------------------------- << 50 G4ProcessManagerMessenger::G4ProcessManagerMes 43 G4ProcessManagerMessenger::G4ProcessManagerMessenger(G4ParticleTable* pTable) 51 : theParticleTable(pTable) << 44 :theParticleTable(pTable), >> 45 currentParticle(0), >> 46 currentProcess(0), >> 47 theManager(0), >> 48 theProcessList(0) 52 { 49 { 53 if ( theParticleTable == nullptr) << 50 if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable(); 54 theParticleTable = G4ParticleTable::GetPar << 55 51 56 // Command /particle/process << 52 //Commnad /particle/process 57 thisDirectory = new G4UIdirectory("/particle 53 thisDirectory = new G4UIdirectory("/particle/process/"); 58 thisDirectory->SetGuidance("Process Manager 54 thisDirectory->SetGuidance("Process Manager control commands."); 59 55 60 // Command /particle/process/dump << 56 //Commnad /particle/process/dump 61 dumpCmd = new G4UIcmdWithAnInteger("/particl 57 dumpCmd = new G4UIcmdWithAnInteger("/particle/process/dump",this); 62 dumpCmd->SetGuidance("dump process manager o 58 dumpCmd->SetGuidance("dump process manager or process information"); 63 dumpCmd->SetGuidance(" dump [process index] 59 dumpCmd->SetGuidance(" dump [process index]"); 64 dumpCmd->SetGuidance(" process index: -1 f 60 dumpCmd->SetGuidance(" process index: -1 for process manager"); 65 dumpCmd->SetParameterName("index", true); 61 dumpCmd->SetParameterName("index", true); 66 dumpCmd->SetDefaultValue(-1); 62 dumpCmd->SetDefaultValue(-1); 67 63 68 // Command /particle/process/verbose << 64 //Commnad /particle/process/Verbose 69 verboseCmd = new G4UIcommand("/particle/proc 65 verboseCmd = new G4UIcommand("/particle/process/verbose",this); 70 verboseCmd->SetGuidance("Set Verbose Level f 66 verboseCmd->SetGuidance("Set Verbose Level for Process or Process Manager"); 71 verboseCmd->SetGuidance(" Verbose [Verbose] 67 verboseCmd->SetGuidance(" Verbose [Verbose] [process index]"); 72 verboseCmd->SetGuidance(" process index: - 68 verboseCmd->SetGuidance(" process index: -1 for process manager"); 73 G4UIparameter* param = new G4UIparameter("Ve 69 G4UIparameter* param = new G4UIparameter("Verbose",'i',true); 74 param->SetDefaultValue(1); 70 param->SetDefaultValue(1); 75 verboseCmd->SetParameter(param); 71 verboseCmd->SetParameter(param); 76 param = new G4UIparameter("index",'i',true); 72 param = new G4UIparameter("index",'i',true); 77 param->SetDefaultValue(-1); 73 param->SetDefaultValue(-1); 78 verboseCmd->SetParameter(param); 74 verboseCmd->SetParameter(param); 79 verboseCmd->AvailableForStates(G4State_PreIn << 75 verboseCmd->AvailableForStates(PreInit,Init,Idle,GeomClosed,EventProc); 80 76 81 // Command /particle/process/activate << 77 //Commnad /particle/process/Activate 82 activateCmd = new G4UIcmdWithAnInteger("/par 78 activateCmd = new G4UIcmdWithAnInteger("/particle/process/activate",this); 83 activateCmd->SetGuidance("Activate process 79 activateCmd->SetGuidance("Activate process "); 84 activateCmd->SetGuidance(" Activate [process 80 activateCmd->SetGuidance(" Activate [process index]"); 85 activateCmd->SetParameterName("index", false 81 activateCmd->SetParameterName("index", false); 86 activateCmd->SetDefaultValue(0); 82 activateCmd->SetDefaultValue(0); 87 activateCmd->SetRange("index >=0"); 83 activateCmd->SetRange("index >=0"); 88 activateCmd->AvailableForStates(G4State_Idle << 84 activateCmd->AvailableForStates(Idle,GeomClosed,EventProc); 89 85 90 // Command /particle/process/inactivate << 86 //Commnad /particle/process/inactivate 91 inactivateCmd = new G4UIcmdWithAnInteger("/p 87 inactivateCmd = new G4UIcmdWithAnInteger("/particle/process/inactivate",this); 92 inactivateCmd->SetGuidance("Inactivate proce 88 inactivateCmd->SetGuidance("Inactivate process "); 93 inactivateCmd->SetGuidance(" inactivate [pro 89 inactivateCmd->SetGuidance(" inactivate [process index]"); 94 inactivateCmd->SetParameterName("index", fal 90 inactivateCmd->SetParameterName("index", false); 95 inactivateCmd->SetDefaultValue(0); 91 inactivateCmd->SetDefaultValue(0); 96 inactivateCmd->SetRange("index >=0"); 92 inactivateCmd->SetRange("index >=0"); 97 inactivateCmd->AvailableForStates(G4State_Id << 93 inactivateCmd->AvailableForStates(Idle,GeomClosed,EventProc); >> 94 98 } 95 } 99 96 100 //-------------------------------------------- << 101 G4ProcessManagerMessenger::~G4ProcessManagerMe 97 G4ProcessManagerMessenger::~G4ProcessManagerMessenger() 102 { 98 { 103 delete activateCmd; 99 delete activateCmd; 104 delete inactivateCmd; 100 delete inactivateCmd; 105 delete verboseCmd; 101 delete verboseCmd; 106 delete dumpCmd; 102 delete dumpCmd; 107 delete thisDirectory; 103 delete thisDirectory; 108 } 104 } 109 105 110 //-------------------------------------------- << 106 G4ParticleDefinition* G4ProcessManagerMessenger::SetCurrentParticle() 111 const G4ParticleDefinition* G4ProcessManagerMe << 112 { 107 { 113 // access to selected particle in the G4Part << 108 // set currentParticle pointer 114 currentParticle = theParticleTable->GetSelec << 109 // get particle name by asking G4ParticleMessenger 115 if (currentParticle == nullptr) << 110 G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select"); 116 { << 111 117 theManager = nullptr; << 112 currentParticle = theParticleTable->FindParticle(particleName); 118 G4cout << "G4ProcessManagerMessenger::SetC << 113 if (currentParticle == 0) { 119 } << 114 theManager = 0; 120 else << 115 G4cout << "G4ProcessManagerMessenger::SetCurrentParticle() "; 121 { << 116 G4cout << particleName << " not found " << G4endl; >> 117 } else { 122 theManager = currentParticle->GetProcessMa 118 theManager = currentParticle->GetProcessManager(); 123 theProcessList = theManager->GetProcessLis 119 theProcessList = theManager->GetProcessList(); 124 } 120 } 125 return currentParticle; 121 return currentParticle; 126 } 122 } 127 123 128 //-------------------------------------------- << 124 void G4ProcessManagerMessenger::SetNewValue(G4UIcommand * command,G4String newValue) 129 void G4ProcessManagerMessenger::SetNewValue(G4 << 130 { 125 { 131 G4ExceptionDescription ed; << 126 if (SetCurrentParticle()==0) { 132 if (SetCurrentParticle() == nullptr) << 127 G4cout << "Particle is not selected yet !! Command ignored." << G4endl; 133 { << 134 ed << "Particle is not selected yet !! C << 135 command->CommandFailed(ed); << 136 return; 128 return; 137 } 129 } 138 if( command == dumpCmd ) << 130 if( command == dumpCmd ){ 139 { << 131 //Commnad /particle/process/dump 140 // Command /particle/process/dump << 141 G4int index = dumpCmd->GetNewIntValue(newV 132 G4int index = dumpCmd->GetNewIntValue(newValue); 142 if (index <0) << 133 if (index <0) { 143 { << 144 theManager->DumpInfo(); 134 theManager->DumpInfo(); 145 } << 135 } else if ( index < theManager->GetProcessListLength()){ 146 else if ( index < theManager->GetProcessLi << 147 { << 148 currentProcess = (*theProcessList)(inde 136 currentProcess = (*theProcessList)(index); 149 if (currentProcess == nullptr) << 137 if (currentProcess == 0) { 150 { << 138 G4cout << " no process at index of " << index; 151 ed << " no process at index of " << index << 139 G4cout << "in the Process Vector" << G4endl; 152 << " in the Process Vector"; << 140 } else { 153 command->CommandFailed(ed); << 154 } << 155 else << 156 { << 157 currentProcess->DumpInfo(); 141 currentProcess->DumpInfo(); 158 } 142 } 159 } << 143 } else { 160 else << 144 G4cout << " illegal index !!! " << G4endl; 161 { << 145 currentProcess = 0; 162 ed << " illegal index !!! "; << 163 command->CommandFailed(ed); << 164 currentProcess = nullptr; << 165 } 146 } 166 147 167 } << 148 } else if( command==activateCmd ) { 168 else if( command==activateCmd ) << 149 //Commnad /particle/process/Activate 169 { << 170 // Command /particle/process/activate << 171 theManager->SetProcessActivation(activateC 150 theManager->SetProcessActivation(activateCmd->GetNewIntValue(newValue), true); 172 G4UImanager::GetUIpointer()->ApplyCommand( << 151 173 << 152 } else if( command==inactivateCmd ) { 174 } << 153 //Commnad /particle/process/inactivate 175 else if( command==inactivateCmd ) << 176 { << 177 // Command /particle/process/inactivate << 178 theManager->SetProcessActivation(inactivat 154 theManager->SetProcessActivation(inactivateCmd->GetNewIntValue(newValue), false); 179 G4UImanager::GetUIpointer()->ApplyCommand( << 155 } else if( command==verboseCmd ) { 180 << 156 //Commnad /particle/process/Verbose 181 } << 182 else if( command==verboseCmd ) << 183 { << 184 // Command /particle/process/Verbose << 185 // inputstream for newValues 157 // inputstream for newValues 186 const char* temp = (const char*)(newValue) 158 const char* temp = (const char*)(newValue); 187 std::istringstream is((char*)temp); << 159 G4std::istrstream is((char*)temp); 188 G4int Verbose, index; 160 G4int Verbose, index; 189 is >>Verbose >>index; 161 is >>Verbose >>index; 190 if (index <0) << 162 if (index <0) { 191 { << 192 theManager->SetVerboseLevel(Verbose); 163 theManager->SetVerboseLevel(Verbose); 193 164 194 } << 165 } else if ( index < theManager->GetProcessListLength()){ 195 else if ( index < theManager->GetProcessLi << 196 { << 197 currentProcess = (*theProcessList)(inde 166 currentProcess = (*theProcessList)(index); 198 if (currentProcess == nullptr) << 167 if (currentProcess == 0) { 199 { << 168 G4cout << " no process at index of " << index; 200 ed << " no process at index of " << index << 169 G4cout << "in the Process Vector" << G4endl; 201 << " in the Process Vector"; << 170 } else { 202 command->CommandFailed(ed); << 203 } << 204 else << 205 { << 206 currentProcess->SetVerboseLevel(Verbose); 171 currentProcess->SetVerboseLevel(Verbose); 207 } 172 } 208 } << 173 } else { 209 else << 174 G4cout << " illegal index !!! " << G4endl; 210 { << 175 currentProcess = 0; 211 ed << " illegal index !!! "; << 212 command->CommandFailed(ed); << 213 currentProcess = nullptr; << 214 } 176 } 215 } 177 } 216 } 178 } 217 179 218 //-------------------------------------------- << 219 G4String G4ProcessManagerMessenger::GetCurrent << 220 { << 221 if(SetCurrentParticle() == nullptr) return " << 222 180 223 if( command==verboseCmd ) << 181 G4String G4ProcessManagerMessenger::GetCurrentValue(G4UIcommand * command) 224 { << 182 { 225 // Command /particle/process/Verbose << 183 G4String returnValue('\0'); 226 return verboseCmd->ConvertToString(theMana << 184 if(SetCurrentParticle() == 0) { >> 185 // no particle is selected. return null strings >> 186 return returnValue; 227 } 187 } 228 else << 188 229 { << 189 char line[255]; 230 return ""; << 190 G4std::ostrstream os(line,255); 231 } << 191 >> 192 if( command==verboseCmd ){ >> 193 //Commnad /particle/process/Verbose >> 194 os << theManager->GetVerboseLevel() << '\0'; >> 195 returnValue = G4String(line); >> 196 } >> 197 return returnValue; 232 } 198 } >> 199 >> 200 >> 201 >> 202 >> 203 233 204