00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "G4UImanager.hh"
00048 #include "G4UIdirectory.hh"
00049 #include "G4UIcmdWithoutParameter.hh"
00050 #include "G4UIcmdWithAnInteger.hh"
00051
00052 #include "G4VProcess.hh"
00053 #include "G4ProcessManager.hh"
00054 #include "G4ParticleTable.hh"
00055
00056 #include "G4ProcessManagerMessenger.hh"
00057 #include "G4ios.hh"
00058 #include <iomanip>
00059
00060 #include <sstream>
00061
00062 G4ProcessManagerMessenger::G4ProcessManagerMessenger(G4ParticleTable* pTable)
00063 :theParticleTable(pTable),
00064 currentParticle(0),
00065 currentProcess(0),
00066 theManager(0),
00067 theProcessList(0)
00068 {
00069 if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable();
00070
00071
00072 thisDirectory = new G4UIdirectory("/particle/process/");
00073 thisDirectory->SetGuidance("Process Manager control commands.");
00074
00075
00076 dumpCmd = new G4UIcmdWithAnInteger("/particle/process/dump",this);
00077 dumpCmd->SetGuidance("dump process manager or process information");
00078 dumpCmd->SetGuidance(" dump [process index]");
00079 dumpCmd->SetGuidance(" process index: -1 for process manager");
00080 dumpCmd->SetParameterName("index", true);
00081 dumpCmd->SetDefaultValue(-1);
00082
00083
00084 verboseCmd = new G4UIcommand("/particle/process/verbose",this);
00085 verboseCmd->SetGuidance("Set Verbose Level for Process or Process Manager");
00086 verboseCmd->SetGuidance(" Verbose [Verbose] [process index]");
00087 verboseCmd->SetGuidance(" process index: -1 for process manager");
00088 G4UIparameter* param = new G4UIparameter("Verbose",'i',true);
00089 param->SetDefaultValue(1);
00090 verboseCmd->SetParameter(param);
00091 param = new G4UIparameter("index",'i',true);
00092 param->SetDefaultValue(-1);
00093 verboseCmd->SetParameter(param);
00094 verboseCmd->AvailableForStates(G4State_PreInit,G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00095
00096
00097 activateCmd = new G4UIcmdWithAnInteger("/particle/process/activate",this);
00098 activateCmd->SetGuidance("Activate process ");
00099 activateCmd->SetGuidance(" Activate [process index]");
00100 activateCmd->SetParameterName("index", false);
00101 activateCmd->SetDefaultValue(0);
00102 activateCmd->SetRange("index >=0");
00103 activateCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00104
00105
00106 inactivateCmd = new G4UIcmdWithAnInteger("/particle/process/inactivate",this);
00107 inactivateCmd->SetGuidance("Inactivate process ");
00108 inactivateCmd->SetGuidance(" inactivate [process index]");
00109 inactivateCmd->SetParameterName("index", false);
00110 inactivateCmd->SetDefaultValue(0);
00111 inactivateCmd->SetRange("index >=0");
00112 inactivateCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00113
00114 }
00115
00116 G4ProcessManagerMessenger::~G4ProcessManagerMessenger()
00117 {
00118 delete activateCmd;
00119 delete inactivateCmd;
00120 delete verboseCmd;
00121 delete dumpCmd;
00122 delete thisDirectory;
00123 }
00124
00125 G4ParticleDefinition* G4ProcessManagerMessenger::SetCurrentParticle()
00126 {
00127
00128
00129 G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select");
00130
00131 currentParticle = theParticleTable->FindParticle(particleName);
00132 if (currentParticle == 0) {
00133 theManager = 0;
00134 G4cout << "G4ProcessManagerMessenger::SetCurrentParticle() ";
00135 G4cout << particleName << " not found " << G4endl;
00136 } else {
00137 theManager = currentParticle->GetProcessManager();
00138 theProcessList = theManager->GetProcessList();
00139 }
00140 return currentParticle;
00141 }
00142
00143 void G4ProcessManagerMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
00144 {
00145 if (SetCurrentParticle()==0) {
00146 G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
00147 return;
00148 }
00149 if( command == dumpCmd ){
00150
00151 G4int index = dumpCmd->GetNewIntValue(newValue);
00152 if (index <0) {
00153 theManager->DumpInfo();
00154 } else if ( index < theManager->GetProcessListLength()){
00155 currentProcess = (*theProcessList)(index);
00156 if (currentProcess == 0) {
00157 G4cout << " no process at index of " << index;
00158 G4cout << "in the Process Vector" << G4endl;
00159 } else {
00160 currentProcess->DumpInfo();
00161 }
00162 } else {
00163 G4cout << " illegal index !!! " << G4endl;
00164 currentProcess = 0;
00165 }
00166
00167 } else if( command==activateCmd ) {
00168
00169 theManager->SetProcessActivation(activateCmd->GetNewIntValue(newValue), true);
00170 G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
00171
00172 } else if( command==inactivateCmd ) {
00173
00174 theManager->SetProcessActivation(inactivateCmd->GetNewIntValue(newValue), false);
00175 G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
00176
00177 } else if( command==verboseCmd ) {
00178
00179
00180 const char* temp = (const char*)(newValue);
00181 std::istringstream is((char*)temp);
00182 G4int Verbose, index;
00183 is >>Verbose >>index;
00184 if (index <0) {
00185 theManager->SetVerboseLevel(Verbose);
00186
00187 } else if ( index < theManager->GetProcessListLength()){
00188 currentProcess = (*theProcessList)(index);
00189 if (currentProcess == 0) {
00190 G4cout << " no process at index of " << index;
00191 G4cout << "in the Process Vector" << G4endl;
00192 } else {
00193 currentProcess->SetVerboseLevel(Verbose);
00194 }
00195 } else {
00196 G4cout << " illegal index !!! " << G4endl;
00197 currentProcess = 0;
00198 }
00199 }
00200 }
00201
00202
00203 G4String G4ProcessManagerMessenger::GetCurrentValue(G4UIcommand * command)
00204 {
00205 G4String returnValue('\0');
00206 if(SetCurrentParticle() == 0) {
00207
00208 return returnValue;
00209 }
00210
00211 std::ostringstream os;
00212
00213 if( command==verboseCmd ){
00214
00215 os << theManager->GetVerboseLevel();
00216 returnValue = os.str();
00217 }
00218 return returnValue;
00219 }
00220
00221
00222
00223
00224