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 // 26 // 27 // Author: Mathieu Karamitros (kara (AT) cenbg 27 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 28 // 28 // 29 // History: 29 // History: 30 // ----------- 30 // ----------- 31 // 31 // 32 // ------------------------------------------- 32 // ------------------------------------------------------------------- 33 #include <G4Scheduler.hh> 33 #include <G4Scheduler.hh> 34 #include <G4SchedulerMessenger.hh> 34 #include <G4SchedulerMessenger.hh> 35 #include "G4UIdirectory.hh" 35 #include "G4UIdirectory.hh" 36 #include "G4UIcmdWithoutParameter.hh" 36 #include "G4UIcmdWithoutParameter.hh" 37 #include "G4UIcmdWithAnInteger.hh" 37 #include "G4UIcmdWithAnInteger.hh" 38 #include "G4UIcmdWithADoubleAndUnit.hh" 38 #include "G4UIcmdWithADoubleAndUnit.hh" 39 #include "G4UIcmdWithABool.hh" 39 #include "G4UIcmdWithABool.hh" 40 #include "G4UIcmdWithAString.hh" 40 #include "G4UIcmdWithAString.hh" 41 #include "G4UIcommand.hh" 41 #include "G4UIcommand.hh" 42 #include "G4UIparameter.hh" 42 #include "G4UIparameter.hh" 43 #include "G4ios.hh" 43 #include "G4ios.hh" 44 44 45 G4SchedulerMessenger::G4SchedulerMessenger(G4S 45 G4SchedulerMessenger::G4SchedulerMessenger(G4Scheduler* stepMgr) 46 : fScheduler(stepMgr) 46 : fScheduler(stepMgr) 47 { 47 { 48 fITDirectory = std::make_unique<G4UIdirector 48 fITDirectory = std::make_unique<G4UIdirectory>("/scheduler/"); 49 fITDirectory->SetGuidance("Control commands 49 fITDirectory->SetGuidance("Control commands for the time scheduler " 50 "(dna chemistry ap 50 "(dna chemistry applications)."); 51 51 52 // Set end time 52 // Set end time 53 fEndTime = std::make_unique<G4UIcmdWithADoub 53 fEndTime = std::make_unique<G4UIcmdWithADoubleAndUnit>("/scheduler/endTime", this); 54 fEndTime->SetGuidance("Set time at which the 54 fEndTime->SetGuidance("Set time at which the simulation must stop."); 55 fEndTime->AvailableForStates(G4State_PreInit 55 fEndTime->AvailableForStates(G4State_PreInit, G4State_Idle); 56 fEndTime->SetUnitCategory("Time"); 56 fEndTime->SetUnitCategory("Time"); 57 fEndTime->SetDefaultUnit("picosecond"); 57 fEndTime->SetDefaultUnit("picosecond"); 58 fEndTime->SetDefaultValue(1); 58 fEndTime->SetDefaultValue(1); 59 59 60 // Set time tolerance 60 // Set time tolerance 61 fTimeTolerance = std::make_unique<G4UIcmdWit 61 fTimeTolerance = std::make_unique<G4UIcmdWithADoubleAndUnit>("/scheduler/timeTolerance", this); 62 fTimeTolerance->SetGuidance( 62 fTimeTolerance->SetGuidance( 63 "This command aims at resolving issues rel 63 "This command aims at resolving issues related to" 64 " floating points. If two time events are 64 " floating points. If two time events are separated by less than the " 65 "selected tolerance, they are assumed to b 65 "selected tolerance, they are assumed to belong to the same time step."); 66 fTimeTolerance->AvailableForStates(G4State_P 66 fTimeTolerance->AvailableForStates(G4State_PreInit, G4State_Idle); 67 fTimeTolerance->SetUnitCategory("Time"); 67 fTimeTolerance->SetUnitCategory("Time"); 68 fTimeTolerance->SetDefaultUnit("picosecond") 68 fTimeTolerance->SetDefaultUnit("picosecond"); 69 fTimeTolerance->SetDefaultValue(1); 69 fTimeTolerance->SetDefaultValue(1); 70 70 71 // Initialize 71 // Initialize 72 fInitCmd = std::make_unique<G4UIcmdWithoutPa 72 fInitCmd = std::make_unique<G4UIcmdWithoutParameter>("/scheduler/initialize", this); 73 fInitCmd->SetGuidance("Initialize G4Schedule 73 fInitCmd->SetGuidance("Initialize G4Scheduler. This is done " 74 "for standalone applic 74 "for standalone application only (no physics)."); 75 fInitCmd->AvailableForStates(G4State_PreInit 75 fInitCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 76 76 77 // Set Max Null time Step 77 // Set Max Null time Step 78 fMaxNULLTimeSteps = std::make_unique<G4UIcmd 78 fMaxNULLTimeSteps = std::make_unique<G4UIcmdWithAnInteger>("/scheduler/maxNullTimeSteps", this); 79 fMaxNULLTimeSteps->SetGuidance( 79 fMaxNULLTimeSteps->SetGuidance( 80 "Set maximum allowed zero time steps. Afte 80 "Set maximum allowed zero time steps. After this " 81 "threshold, the simulation is stopped."); 81 "threshold, the simulation is stopped."); 82 fMaxNULLTimeSteps->SetParameterName("numberO 82 fMaxNULLTimeSteps->SetParameterName("numberOfNullTimeSteps", true); 83 fMaxNULLTimeSteps->SetDefaultValue(10000); 83 fMaxNULLTimeSteps->SetDefaultValue(10000); 84 fMaxNULLTimeSteps->SetRange("numberOfNullTim 84 fMaxNULLTimeSteps->SetRange("numberOfNullTimeSteps >=0 "); 85 85 86 fMaxStepNumber = std::make_unique<G4UIcmdWit 86 fMaxStepNumber = std::make_unique<G4UIcmdWithAnInteger>("/scheduler/maxStepNumber", this); 87 fMaxStepNumber->SetGuidance( 87 fMaxStepNumber->SetGuidance( 88 "Set the maximum number of time steps. Aft 88 "Set the maximum number of time steps. After this " 89 "threshold, the simulation is stopped."); 89 "threshold, the simulation is stopped."); 90 fMaxStepNumber->SetParameterName("maximumNum 90 fMaxStepNumber->SetParameterName("maximumNumberOfSteps", true); 91 fMaxStepNumber->SetDefaultValue(-1); 91 fMaxStepNumber->SetDefaultValue(-1); 92 92 93 // Beam On 93 // Beam On 94 fProcessCmd = std::make_unique<G4UIcmdWithou 94 fProcessCmd = std::make_unique<G4UIcmdWithoutParameter>("/scheduler/process", this); 95 fProcessCmd->SetGuidance( 95 fProcessCmd->SetGuidance( 96 "Process stacked tracks in G4Scheduler. Th 96 "Process stacked tracks in G4Scheduler. This is done " 97 "for standalone application only (no physi 97 "for standalone application only (no physics)."); 98 fProcessCmd->AvailableForStates(G4State_PreI 98 fProcessCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 99 99 100 // Verbose 100 // Verbose 101 fVerboseCmd = std::make_unique<G4UIcmdWithAn 101 fVerboseCmd = std::make_unique<G4UIcmdWithAnInteger>("/scheduler/verbose", this); 102 fVerboseCmd->SetGuidance("Set the Verbose le 102 fVerboseCmd->SetGuidance("Set the Verbose level of G4Scheduler."); 103 fVerboseCmd->SetGuidance(" 0 : Silent (defau 103 fVerboseCmd->SetGuidance(" 0 : Silent (default)"); 104 fVerboseCmd->SetGuidance(" 1 : Display react 104 fVerboseCmd->SetGuidance(" 1 : Display reactions"); 105 fVerboseCmd->SetGuidance(" 2 "); 105 fVerboseCmd->SetGuidance(" 2 "); 106 fVerboseCmd->SetParameterName("level", true) 106 fVerboseCmd->SetParameterName("level", true); 107 fVerboseCmd->SetDefaultValue(1); 107 fVerboseCmd->SetDefaultValue(1); 108 108 109 fWhyDoYouStop = std::make_unique<G4UIcmdWith 109 fWhyDoYouStop = std::make_unique<G4UIcmdWithoutParameter>("/scheduler/whyDoYouStop", this); 110 fWhyDoYouStop->SetGuidance("Will print infor 110 fWhyDoYouStop->SetGuidance("Will print information on why the scheduler is " 111 "stopping the pro 111 "stopping the process"); 112 112 113 fUseDefaultTimeSteps = std::make_unique<G4UI 113 fUseDefaultTimeSteps = std::make_unique<G4UIcmdWithABool>("/scheduler/useDefaultTimeSteps", this); 114 fUseDefaultTimeSteps->SetGuidance( 114 fUseDefaultTimeSteps->SetGuidance( 115 "Let the G4 processes decided for the next 115 "Let the G4 processes decided for the next " 116 "time step interval. This command would be 116 "time step interval. This command would be interesting if no reaction has " 117 "been set and if one will want to track do 117 "been set and if one will want to track down Brownian objects. " 118 "NB: This command gets in conflicts with t 118 "NB: This command gets in conflicts with the declaration of time steps."); 119 119 120 fResetScavenger = std::make_unique<G4UIcmdWi 120 fResetScavenger = std::make_unique<G4UIcmdWithABool>("/scheduler/ResetScavengerForEachBeamOn", this); 121 fResetScavenger->SetGuidance( 121 fResetScavenger->SetGuidance( 122 "Reset Scavenger information apres each Be 122 "Reset Scavenger information apres each BeamOn."); 123 fResetScavenger->SetDefaultValue(true); 123 fResetScavenger->SetDefaultValue(true); 124 124 125 } 125 } 126 126 127 G4SchedulerMessenger::~G4SchedulerMessenger() 127 G4SchedulerMessenger::~G4SchedulerMessenger() = default; 128 128 129 void G4SchedulerMessenger::SetNewValue(G4UIcom 129 void G4SchedulerMessenger::SetNewValue(G4UIcommand* command, G4String newValue) 130 { 130 { 131 if(command == fProcessCmd.get()) 131 if(command == fProcessCmd.get()) 132 { 132 { 133 fScheduler->Process(); 133 fScheduler->Process(); 134 } 134 } 135 else if(command == fEndTime.get()) 135 else if(command == fEndTime.get()) 136 { 136 { 137 fScheduler->SetEndTime(fEndTime->GetNewDou 137 fScheduler->SetEndTime(fEndTime->GetNewDoubleValue(newValue)); 138 } 138 } 139 else if(command == fTimeTolerance.get()) 139 else if(command == fTimeTolerance.get()) 140 { 140 { 141 fScheduler->SetTimeTolerance(fTimeToleranc 141 fScheduler->SetTimeTolerance(fTimeTolerance->GetNewDoubleValue(newValue)); 142 } 142 } 143 else if(command == fVerboseCmd.get()) 143 else if(command == fVerboseCmd.get()) 144 { 144 { 145 fScheduler->SetVerbose(fVerboseCmd->GetNew 145 fScheduler->SetVerbose(fVerboseCmd->GetNewIntValue(newValue)); 146 } 146 } 147 else if(command == fInitCmd.get()) 147 else if(command == fInitCmd.get()) 148 { 148 { 149 fScheduler->Initialize(); 149 fScheduler->Initialize(); 150 } 150 } 151 else if(command == fMaxNULLTimeSteps.get()) 151 else if(command == fMaxNULLTimeSteps.get()) 152 { 152 { 153 fScheduler->SetMaxZeroTimeAllowed( 153 fScheduler->SetMaxZeroTimeAllowed( 154 fMaxNULLTimeSteps->GetNewIntValue(newVal 154 fMaxNULLTimeSteps->GetNewIntValue(newValue)); 155 } 155 } 156 else if(command == fMaxStepNumber.get()) 156 else if(command == fMaxStepNumber.get()) 157 { 157 { 158 fScheduler->SetMaxNbSteps(fMaxStepNumber-> 158 fScheduler->SetMaxNbSteps(fMaxStepNumber->GetNewIntValue(newValue)); 159 } 159 } 160 else if(command == fWhyDoYouStop.get()) 160 else if(command == fWhyDoYouStop.get()) 161 { 161 { 162 fScheduler->WhyDoYouStop(); 162 fScheduler->WhyDoYouStop(); 163 } 163 } 164 else if(command == fUseDefaultTimeSteps.get( 164 else if(command == fUseDefaultTimeSteps.get()) 165 { 165 { 166 fScheduler->UseDefaultTimeSteps( 166 fScheduler->UseDefaultTimeSteps( 167 fUseDefaultTimeSteps->GetNewBoolValue(ne 167 fUseDefaultTimeSteps->GetNewBoolValue(newValue)); 168 } 168 } 169 else if(command == fResetScavenger.get()) 169 else if(command == fResetScavenger.get()) 170 { 170 { 171 fScheduler->ResetScavenger(fResetScavenger 171 fScheduler->ResetScavenger(fResetScavenger->GetNewBoolValue(newValue)); 172 } 172 } 173 } 173 } 174 174 175 G4String G4SchedulerMessenger::GetCurrentValue 175 G4String G4SchedulerMessenger::GetCurrentValue(G4UIcommand* command) 176 { 176 { 177 G4String cv; 177 G4String cv; 178 178 179 if(command == fVerboseCmd.get()) 179 if(command == fVerboseCmd.get()) 180 { 180 { 181 cv = fVerboseCmd->ConvertToString(fSchedul 181 cv = fVerboseCmd->ConvertToString(fScheduler->GetVerbose()); 182 } 182 } 183 else if(command == fEndTime.get()) 183 else if(command == fEndTime.get()) 184 { 184 { 185 cv = fEndTime->ConvertToString(fScheduler- 185 cv = fEndTime->ConvertToString(fScheduler->GetEndTime()); 186 } 186 } 187 else if(command == fTimeTolerance.get()) 187 else if(command == fTimeTolerance.get()) 188 { 188 { 189 cv = fTimeTolerance->ConvertToString(fSche 189 cv = fTimeTolerance->ConvertToString(fScheduler->GetTimeTolerance()); 190 } 190 } 191 else if(command == fInitCmd.get()) 191 else if(command == fInitCmd.get()) 192 { 192 { 193 cv = fInitCmd->ConvertToString(fScheduler- 193 cv = fInitCmd->ConvertToString(fScheduler->IsInitialized()); 194 } 194 } 195 else if(command == fMaxNULLTimeSteps.get()) 195 else if(command == fMaxNULLTimeSteps.get()) 196 { 196 { 197 cv = 197 cv = 198 fMaxNULLTimeSteps->ConvertToString(fSche 198 fMaxNULLTimeSteps->ConvertToString(fScheduler->GetMaxZeroTimeAllowed()); 199 } 199 } 200 else if(command == fMaxStepNumber.get()) 200 else if(command == fMaxStepNumber.get()) 201 { 201 { 202 cv = fMaxStepNumber->ConvertToString(fSche 202 cv = fMaxStepNumber->ConvertToString(fScheduler->GetMaxNbSteps()); 203 } 203 } 204 else if(command == fUseDefaultTimeSteps.get( 204 else if(command == fUseDefaultTimeSteps.get()) 205 { 205 { 206 cv = fUseDefaultTimeSteps->ConvertToString 206 cv = fUseDefaultTimeSteps->ConvertToString( 207 fScheduler->AreDefaultTimeStepsUsed()); 207 fScheduler->AreDefaultTimeStepsUsed()); 208 } 208 } 209 return cv; 209 return cv; 210 } 210 } 211 211