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 #include "G4ProcessTableMessenger.hh"
00047
00048 #include "G4UImanager.hh"
00049 #include "G4UIdirectory.hh"
00050 #include "G4UIcmdWithoutParameter.hh"
00051 #include "G4UIcmdWithAnInteger.hh"
00052 #include "G4UIcmdWithAString.hh"
00053
00054 #include "G4VProcess.hh"
00055 #include "G4ProcessManager.hh"
00056 #include "G4ProcessTable.hh"
00057 #include "G4ParticleTable.hh"
00058
00059 #include "G4ios.hh"
00060 #include "G4Tokenizer.hh"
00061 #include <iomanip>
00062 #include <sstream>
00063
00065 G4int G4ProcessTableMessenger::NumberOfProcessType = 10;
00066
00068 G4ProcessTableMessenger::G4ProcessTableMessenger(G4ProcessTable* pTable)
00069 :theProcessTable(pTable),
00070 currentProcessTypeName("all"),
00071 currentProcessName("all"),
00072 currentParticleName("all")
00073 {
00074
00075 thisDirectory = new G4UIdirectory("/process/");
00076 thisDirectory->SetGuidance("Process Table control commands.");
00077
00078
00079
00080 listCmd = new G4UIcmdWithAString("/process/list",this);
00081 listCmd->SetGuidance("List up process names");
00082 listCmd->SetGuidance(" list [type] ");
00083 listCmd->SetGuidance(" type: process type [all:for all proceeses]");
00084 listCmd->SetParameterName("type", true);
00085 listCmd->SetDefaultValue("all");
00086 SetNumberOfProcessType();
00087
00088 G4String candidates("all");
00089 for (G4int idx = 0; idx < NumberOfProcessType ; idx ++ ) {
00090 candidates += " " +
00091 G4VProcess::GetProcessTypeName(G4ProcessType(idx));
00092 }
00093 listCmd->SetCandidates((const char*)(candidates));
00094
00095
00096 verboseCmd = new G4UIcmdWithAnInteger("/process/verbose",this);
00097 verboseCmd->SetGuidance("Set Verbose Level for Process Table");
00098 verboseCmd->SetGuidance(" verbose [level]");
00099 verboseCmd->SetGuidance(" level: verbose level");
00100 verboseCmd->SetParameterName("verbose", true);
00101 verboseCmd->SetDefaultValue(1);
00102 verboseCmd->SetRange("verbose >=0");
00103 verboseCmd->AvailableForStates(G4State_PreInit,G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00104
00105
00106 procVerboseCmd = new G4UIcommand("/process/setVerbose",this);
00107 procVerboseCmd->SetGuidance("Set verbose level for processes");
00108 procVerboseCmd->SetGuidance(" setVerbose level [type or name] ");
00109 procVerboseCmd->SetGuidance(" level: verbose level ");
00110 procVerboseCmd->SetGuidance(" name : process name ");
00111 procVerboseCmd->SetGuidance(" type : process type ");
00112 procVerboseCmd->SetGuidance(" [all] for all proceeses ");
00113 G4UIparameter* param = new G4UIparameter("verbose",'i',false);
00114 procVerboseCmd->SetParameter(param);
00115 param = new G4UIparameter("type",'s',true);
00116 param->SetDefaultValue("all");
00117 procVerboseCmd->SetParameter(param);
00118 procVerboseCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00119
00120
00121 dumpCmd = new G4UIcommand("/process/dump",this);
00122 dumpCmd->SetGuidance("Dump process information");
00123 dumpCmd->SetGuidance(" dump name [particle]");
00124 dumpCmd->SetGuidance(" name: process name or type name");
00125 dumpCmd->SetGuidance(" particle: particle name [all: for all particles]");
00126 param = new G4UIparameter("procName",'s',false);
00127 dumpCmd->SetParameter(param);
00128 param = new G4UIparameter("particle",'s',true);
00129 param->SetDefaultValue("all");
00130 dumpCmd->SetParameter(param);
00131 dumpCmd->AvailableForStates(G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00132
00133
00134 activateCmd = new G4UIcommand("/process/activate",this);
00135 activateCmd->SetGuidance("Activate processes ");
00136 activateCmd->SetGuidance(" Activate name [particle]");
00137 activateCmd->SetGuidance(" name: process name or type name");
00138 activateCmd->SetGuidance(" particle: particle name [all: for all particles]");
00139 param = new G4UIparameter("procName",'s',false);
00140 activateCmd->SetParameter(param);
00141 param = new G4UIparameter("particle",'s',true);
00142 param->SetDefaultValue("all");
00143 activateCmd->SetParameter(param);
00144 activateCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00145
00146
00147 inactivateCmd = new G4UIcommand("/process/inactivate",this);
00148 inactivateCmd->SetGuidance("Inactivate process ");
00149 inactivateCmd->SetGuidance("Inactivate processes ");
00150 inactivateCmd->SetGuidance(" Inactivate name [particle]");
00151 inactivateCmd->SetGuidance(" name: process name or type name");
00152 inactivateCmd->SetGuidance(" particle: particle name [all: for all particles]");
00153 param = new G4UIparameter("procName",'s',false);
00154 inactivateCmd->SetParameter(param);
00155 param = new G4UIparameter("particle",'s',true);
00156 param->SetDefaultValue("all");
00157 inactivateCmd->SetParameter(param);
00158 inactivateCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00159 }
00160
00162 G4ProcessTableMessenger::~G4ProcessTableMessenger()
00163 {
00164 delete activateCmd;
00165 delete inactivateCmd;
00166 delete verboseCmd;
00167 delete dumpCmd;
00168 delete listCmd;
00169 delete procVerboseCmd;
00170 delete thisDirectory;
00171 }
00172
00174 void G4ProcessTableMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
00175 {
00176 G4ProcessTable::G4ProcNameVector* procNameVector
00177 = theProcessTable->GetNameList();
00178 G4int idx;
00179
00180 G4int type = -1;
00181
00182 if( command == listCmd ){
00183
00184 type = -1;
00185 if (newValue == "all") {
00186 currentProcessTypeName = newValue;
00187 } else {
00188 type = GetProcessType(newValue);
00189 if (type <0) {
00190 G4cout << " illegal type !!! " << G4endl;
00191 } else {
00192 currentProcessTypeName = newValue;
00193 }
00194 }
00195 G4int counter = 0;
00196 idx =0;
00197 G4ProcessTable::G4ProcNameVector::iterator itr;
00198 for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
00199 idx +=1;
00200 G4ProcessVector* tmpVector = theProcessTable->FindProcesses(*itr);
00201 if ( (type <0) || ( ((*tmpVector)(0)->GetProcessType()) == type) ) {
00202 if ( counter%4 != 0) G4cout << ",";
00203 G4cout << std::setw(19) <<*itr;
00204 if ((counter++)%4 == 3) {
00205 G4cout << G4endl;
00206 }
00207 }
00208 delete tmpVector;
00209 }
00210 G4cout << G4endl;
00211
00212
00213 } else if( command==procVerboseCmd ) {
00214
00215 G4Tokenizer next( newValue );
00216
00217
00218 G4String tmpS = G4String(next());
00219
00220 const char* temp = (const char*)(tmpS);
00221 std::istringstream is((char*)temp);
00222 G4int level;
00223 is >>level;
00224
00225
00226 currentProcessTypeName = G4String(next());
00227 if (currentProcessTypeName.isNull()) currentProcessTypeName = "all";
00228 G4bool isProcName = false;
00229 G4bool isAll = false;
00230 type = -1;
00231
00232 if (currentProcessTypeName == "all") {
00233 isAll = true;
00234 } else {
00235 type = GetProcessType(currentProcessTypeName);
00236 if (type<0) {
00237 isProcName = true;
00238 currentProcessName = currentProcessTypeName;
00239 currentProcessTypeName = "";
00240 }
00241 }
00242 idx =0;
00243 G4ProcessTable::G4ProcNameVector::iterator itr;
00244 for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
00245 idx +=1;
00246 G4ProcessVector* tmpVector = theProcessTable->FindProcesses(*itr);
00247 G4VProcess* p = (*tmpVector)(0);
00248 if ( isAll ||
00249 (!isProcName && ( p->GetProcessType() == type) ) ||
00250 ( isProcName && ( p->GetProcessName()== currentProcessName) ) ){
00251 p->SetVerboseLevel(level);
00252 }
00253 delete tmpVector;
00254 }
00255
00256
00257 } else if( command==verboseCmd ) {
00258
00259 theProcessTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
00260
00261
00262 } else {
00263 G4Tokenizer next( newValue );
00264
00265
00266 currentProcessName = G4String(next());
00267 G4bool isProcName = false;
00268 G4ProcessTable::G4ProcNameVector::iterator itr;
00269 for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
00270 if ( (*itr) == currentProcessName ) {
00271 isProcName = true;
00272 break;
00273 }
00274 }
00275 if (!isProcName) {
00276 type = GetProcessType(currentProcessName);
00277 if (type <0 ) {
00278
00279 G4cout << " illegal process (or type) name " << G4endl;
00280 currentProcessName = "";
00281 return;
00282 }
00283 }
00284
00285
00286 currentParticleName = G4String(next());
00287 G4bool isParticleFound = false;
00288 G4ParticleDefinition* currentParticle = 0;
00289 if ( currentParticleName == "all" ) {
00290 isParticleFound = true;
00291
00292 } else {
00293 isParticleFound = G4ParticleTable::GetParticleTable()->contains(currentParticleName);
00294 if (isParticleFound) {
00295 currentParticle = G4ParticleTable::GetParticleTable()->FindParticle(currentParticleName);
00296 }
00297
00298 }
00299
00300 if ( !isParticleFound ) {
00301
00302 G4cout << " illegal particle name " << G4endl;
00303 currentParticleName = "";
00304 return;
00305 }
00306
00307 if( command==dumpCmd ) {
00308
00309 G4ProcessVector* tmpVector;
00310 if (isProcName) {
00311 tmpVector = theProcessTable->FindProcesses(currentProcessName);
00312 } else {
00313 tmpVector = theProcessTable->FindProcesses(G4ProcessType(type));
00314 }
00315 for (G4int i=0; i<tmpVector->length(); i++) {
00316 theProcessTable->DumpInfo( (*tmpVector)(i), currentParticle );
00317 }
00318 delete tmpVector;
00319
00320
00321 } else if ( (command==activateCmd) || (command==inactivateCmd)) {
00322
00323 G4bool fActive = (command==activateCmd);
00324 if (isProcName) {
00325 if ( currentParticle == 0 ) {
00326 theProcessTable->SetProcessActivation(currentProcessName,
00327 fActive);
00328 } else {
00329 theProcessTable->SetProcessActivation(currentProcessName,
00330 currentParticle,
00331 fActive);
00332 }
00333 } else {
00334 if ( currentParticle == 0 ) {
00335 theProcessTable->SetProcessActivation(G4ProcessType(type),
00336 fActive);
00337 } else {
00338 theProcessTable->SetProcessActivation(G4ProcessType(type),
00339 currentParticle,
00340 fActive);
00341 }
00342 }
00343 G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
00344
00345 }
00346 }
00347 }
00348
00349
00351 G4String G4ProcessTableMessenger::GetCurrentValue(G4UIcommand * command)
00352 {
00353 G4ProcessTable::G4ProcNameVector* procNameVector
00354 = theProcessTable->GetNameList();
00355
00356 G4String candidates;
00357 G4String returnValue('\0');
00358
00359 std::ostringstream os;
00360 G4UIparameter * param;
00361
00362 G4int idx;
00363
00364 if( command==verboseCmd ){
00365
00366 os << theProcessTable->GetVerboseLevel();
00367 returnValue = os.str();
00368
00369 } else if ( command==listCmd ){
00370
00371 candidates = "all";
00372 for (idx = 0; idx < NumberOfProcessType ; idx ++ ) {
00373 candidates += " " +
00374 G4VProcess::GetProcessTypeName(G4ProcessType(idx));
00375 }
00376 listCmd->SetCandidates((const char*)(candidates));
00377 returnValue = currentProcessTypeName;
00378
00379 } else {
00380
00381
00382 param = command->GetParameter(0);
00383 candidates = "";
00384 G4ProcessTable::G4ProcNameVector::iterator itr;
00385 for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
00386 candidates += " " + (*itr);
00387 }
00388 param->SetParameterCandidates((const char*)(candidates));
00389
00390 param = command->GetParameter(1);
00391 candidates = "all";
00392 G4ParticleTable::G4PTblDicIterator *piter
00393 = G4ParticleTable::GetParticleTable()->GetIterator();
00394 piter -> reset();
00395 while( (*piter)() ){
00396 G4ParticleDefinition *particle = piter->value();
00397 candidates += " " + particle->GetParticleName();
00398 }
00399 param->SetParameterCandidates((const char*)(candidates));
00400
00401 returnValue = currentProcessName + " " + currentParticleName;
00402
00403 }
00404
00405 return returnValue;
00406 }
00407
00409 G4String G4ProcessTableMessenger::GetProcessTypeName(G4ProcessType aType) const
00410 {
00411 return G4VProcess::GetProcessTypeName(aType);
00412 }
00413
00415 G4int G4ProcessTableMessenger::GetProcessType(const G4String& aTypeName) const
00416 {
00417 G4int type = -1;
00418 for (G4int idx = 0; idx < NumberOfProcessType ; idx ++ ) {
00419 if (aTypeName == G4VProcess::GetProcessTypeName(G4ProcessType(idx)) ) {
00420 type = idx;
00421 break;
00422 }
00423 }
00424 return type;
00425 }
00426
00427
00429 void G4ProcessTableMessenger::SetNumberOfProcessType()
00430 {
00431 G4bool isFoundEndMark = false;
00432 G4int idx;
00433 for (idx = 0; idx < 1000 ; idx ++ ) {
00434 G4String typeName = G4VProcess::GetProcessTypeName(G4ProcessType(idx));
00435 isFoundEndMark = typeName.contains("---");
00436 if ( isFoundEndMark ) break;
00437 }
00438 if ( isFoundEndMark ) {
00439 NumberOfProcessType = idx;
00440 } else {
00441 G4Exception("G4ProcessTableMessenger::SetNumberOfProcessType()","ProcMan014",
00442 FatalException,"No End Mark");
00443 }
00444 }
00445
00446
00447
00448