source: trunk/source/processes/management/src/G4ProcessTableMessenger.cc@ 1330

Last change on this file since 1330 was 1228, checked in by garnier, 16 years ago

update geant4.9.3 tag

File size: 14.8 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4ProcessTableMessenger.cc,v 1.18 2008/03/14 02:55:04 kurasige Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30//
31//---------------------------------------------------------------
32//
33// G4ProcessTableMessenger.cc
34//
35// Description:
36// This is a messenger class to interface to exchange information
37// between ProcessTable and UI.
38//
39//
40// History:
41// 15 Aug. 1998, H. Kurashige
42// Use STL vector instead of RW vector 1. Mar 00 H.Kurashige
43// 02 June 2006, add physicsModified in activate/inactivate (mma)
44//
45//---------------------------------------------------------------
46
47#include "G4ProcessTableMessenger.hh"
48
49#include "G4UImanager.hh"
50#include "G4UIdirectory.hh"
51#include "G4UIcmdWithoutParameter.hh"
52#include "G4UIcmdWithAnInteger.hh"
53#include "G4UIcmdWithAString.hh"
54
55#include "G4VProcess.hh"
56#include "G4ProcessManager.hh"
57#include "G4ProcessTable.hh"
58#include "G4ParticleTable.hh"
59
60#include "G4ios.hh"
61#include "G4Tokenizer.hh"
62#include <iomanip>
63#include <sstream>
64
65/////////////////////////////////////////
66G4int G4ProcessTableMessenger::NumberOfProcessType = 10;
67
68//////////////////////////
69G4ProcessTableMessenger::G4ProcessTableMessenger(G4ProcessTable* pTable)
70 :theProcessTable(pTable),
71 currentProcessTypeName("all"),
72 currentProcessName("all"),
73 currentParticleName("all")
74{
75 //Commnad /particle/process
76 thisDirectory = new G4UIdirectory("/process/");
77 thisDirectory->SetGuidance("Process Table control commands.");
78
79
80 //Commnad /particle/process/list
81 listCmd = new G4UIcmdWithAString("/process/list",this);
82 listCmd->SetGuidance("List up process names");
83 listCmd->SetGuidance(" list [type] ");
84 listCmd->SetGuidance(" type: process type [all:for all proceeses]");
85 listCmd->SetParameterName("type", true);
86 listCmd->SetDefaultValue("all");
87 SetNumberOfProcessType();
88
89 G4String candidates("all");
90 for (G4int idx = 0; idx < NumberOfProcessType ; idx ++ ) {
91 candidates += " " +
92 G4VProcess::GetProcessTypeName(G4ProcessType(idx));
93 }
94 listCmd->SetCandidates((const char*)(candidates));
95
96 //Commnad /particle/process/Verbose
97 verboseCmd = new G4UIcmdWithAnInteger("/process/verbose",this);
98 verboseCmd->SetGuidance("Set Verbose Level for Process Table");
99 verboseCmd->SetGuidance(" verbose [level]");
100 verboseCmd->SetGuidance(" level: verbose level");
101 verboseCmd->SetParameterName("verbose", true);
102 verboseCmd->SetDefaultValue(1);
103 verboseCmd->SetRange("verbose >=0");
104 verboseCmd->AvailableForStates(G4State_PreInit,G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
105
106 //Commnad /particle/process/setVerbose
107 procVerboseCmd = new G4UIcommand("/process/setVerbose",this);
108 procVerboseCmd->SetGuidance("Set verbose level for processes");
109 procVerboseCmd->SetGuidance(" setVerbose level [type or name] ");
110 procVerboseCmd->SetGuidance(" level: verbose level ");
111 procVerboseCmd->SetGuidance(" name : process name ");
112 procVerboseCmd->SetGuidance(" type : process type ");
113 procVerboseCmd->SetGuidance(" [all] for all proceeses ");
114 G4UIparameter* param = new G4UIparameter("verbose",'i',false);
115 procVerboseCmd->SetParameter(param);
116 param = new G4UIparameter("type",'s',true);
117 param->SetDefaultValue("all");
118 procVerboseCmd->SetParameter(param);
119 procVerboseCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
120
121 //Commnad /particle/process/dump
122 dumpCmd = new G4UIcommand("/process/dump",this);
123 dumpCmd->SetGuidance("Dump process information");
124 dumpCmd->SetGuidance(" dump name [particle]");
125 dumpCmd->SetGuidance(" name: process name or type name");
126 dumpCmd->SetGuidance(" particle: particle name [all: for all particles]");
127 param = new G4UIparameter("procName",'s',false);
128 dumpCmd->SetParameter(param);
129 param = new G4UIparameter("particle",'s',true);
130 param->SetDefaultValue("all");
131 dumpCmd->SetParameter(param);
132 dumpCmd->AvailableForStates(G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
133
134 //Commnad /particle/process/activate
135 activateCmd = new G4UIcommand("/process/activate",this);
136 activateCmd->SetGuidance("Activate processes ");
137 activateCmd->SetGuidance(" Activate name [particle]");
138 activateCmd->SetGuidance(" name: process name or type name");
139 activateCmd->SetGuidance(" particle: particle name [all: for all particles]");
140 param = new G4UIparameter("procName",'s',false);
141 activateCmd->SetParameter(param);
142 param = new G4UIparameter("particle",'s',true);
143 param->SetDefaultValue("all");
144 activateCmd->SetParameter(param);
145 activateCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
146
147 //Commnad /particle/process/inactivate
148 inactivateCmd = new G4UIcommand("/process/inactivate",this);
149 inactivateCmd->SetGuidance("Inactivate process ");
150 inactivateCmd->SetGuidance("Inactivate processes ");
151 inactivateCmd->SetGuidance(" Inactivate name [particle]");
152 inactivateCmd->SetGuidance(" name: process name or type name");
153 inactivateCmd->SetGuidance(" particle: particle name [all: for all particles]");
154 param = new G4UIparameter("procName",'s',false);
155 inactivateCmd->SetParameter(param);
156 param = new G4UIparameter("particle",'s',true);
157 param->SetDefaultValue("all");
158 inactivateCmd->SetParameter(param);
159 inactivateCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
160}
161
162//////////////////
163G4ProcessTableMessenger::~G4ProcessTableMessenger()
164{
165 delete activateCmd;
166 delete inactivateCmd;
167 delete verboseCmd;
168 delete dumpCmd;
169 delete listCmd;
170 delete procVerboseCmd;
171 delete thisDirectory;
172}
173
174///////////////
175void G4ProcessTableMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
176{
177 G4ProcessTable::G4ProcNameVector* procNameVector
178 = theProcessTable->GetNameList();
179 G4int idx;
180
181 G4ProcessVector* tmpVector=0;
182 G4int type = -1;
183
184 if( command == listCmd ){
185 //Commnad /process/list
186 type = -1;
187 if (newValue == "all") {
188 currentProcessTypeName = newValue;
189 } else {
190 type = GetProcessType(newValue);
191 if (type <0) {
192 G4cout << " illegal type !!! " << G4endl;
193 } else {
194 currentProcessTypeName = newValue;
195 }
196 }
197 G4int counter = 0;
198 idx =0;
199 G4ProcessTable::G4ProcNameVector::iterator itr;
200 for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
201 idx +=1;
202 tmpVector = theProcessTable->FindProcesses(*itr);
203 if ( (type <0) || ( ((*tmpVector)(0)->GetProcessType()) == type) ) {
204 if ( counter%4 != 0) G4cout << ",";
205 G4cout << std::setw(19) <<*itr;
206 if ((counter++)%4 == 3) {
207 G4cout << G4endl;
208 }
209 }
210 }
211 G4cout << G4endl;
212 delete tmpVector;
213 //Commnad /process/list
214
215 } else if( command==procVerboseCmd ) {
216 //Commnad /process/setVerbose
217 G4Tokenizer next( newValue );
218
219 // check 1st argument
220 G4String tmpS = G4String(next());
221 // inputstream for newValues
222 const char* temp = (const char*)(tmpS);
223 std::istringstream is((char*)temp);
224 G4int level;
225 is >>level;
226
227 // check 2nd argument
228 currentProcessTypeName = G4String(next());
229 if (currentProcessTypeName.isNull()) currentProcessTypeName = "all";
230 G4bool isProcName = false;
231 G4bool isAll = false;
232 type = -1;
233
234 if (currentProcessTypeName == "all") {
235 isAll = true;
236 } else {
237 type = GetProcessType(currentProcessTypeName);
238 if (type<0) {
239 isProcName = true;
240 currentProcessName = currentProcessTypeName;
241 currentProcessTypeName = "";
242 }
243 }
244 idx =0;
245 G4ProcessTable::G4ProcNameVector::iterator itr;
246 for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
247 idx +=1;
248 tmpVector = theProcessTable->FindProcesses(*itr);
249 G4VProcess* p = (*tmpVector)(0);
250 if ( isAll ||
251 (!isProcName && ( p->GetProcessType() == type) ) ||
252 ( isProcName && ( p->GetProcessName()== currentProcessName) ) ){
253 p->SetVerboseLevel(level);
254 }
255 }
256 delete tmpVector;
257 //Commnad /process/setVerbose
258
259 } else if( command==verboseCmd ) {
260 //Commnad /process/verbose
261 theProcessTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
262 //Commnad /process/verbose
263
264 } else {
265 G4Tokenizer next( newValue );
266
267 // check 1st argument
268 currentProcessName = G4String(next());
269 G4bool isNameFound = false;
270 G4bool isProcName = false;
271 G4ProcessTable::G4ProcNameVector::iterator itr;
272 for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
273 if ( (*itr) == currentProcessName ) {
274 isNameFound = true;
275 isProcName = true;
276 break;
277 }
278 }
279 if (!isProcName) {
280 type = GetProcessType(currentProcessName);
281 if (type >=0) {
282 isNameFound = true;
283 } else {
284 // no processes with specifed name
285 G4cout << " illegal process (or type) name " << G4endl;
286 currentProcessName = "";
287 return;
288 }
289 }
290
291 // check 2nd argument
292 currentParticleName = G4String(next());
293 G4bool isParticleFound = false;
294 G4ParticleDefinition* currentParticle = 0;
295 if ( currentParticleName == "all" ) {
296 isParticleFound = true;
297
298 } else {
299 isParticleFound = G4ParticleTable::GetParticleTable()->contains(currentParticleName);
300 if (isParticleFound) {
301 currentParticle = G4ParticleTable::GetParticleTable()->FindParticle(currentParticleName);
302 }
303
304 }
305
306 if ( !isParticleFound ) {
307 // no particle with specifed name
308 G4cout << " illegal particle name " << G4endl;
309 currentParticleName = "";
310 return;
311 }
312
313 if( command==dumpCmd ) {
314 // process/dump
315 if (isProcName) {
316 tmpVector = theProcessTable->FindProcesses(currentProcessName);
317 } else {
318 tmpVector = theProcessTable->FindProcesses(G4ProcessType(type));
319 }
320 for (G4int i=0; i<tmpVector->length(); i++) {
321 theProcessTable->DumpInfo( (*tmpVector)(i), currentParticle );
322 }
323 delete tmpVector;
324 // process/dump
325
326 } else if ( (command==activateCmd) || (command==inactivateCmd)) {
327 // process/activate , inactivate
328 G4bool fActive = (command==activateCmd);
329 if (isProcName) {
330 if ( currentParticle == 0 ) {
331 theProcessTable->SetProcessActivation(currentProcessName,
332 fActive);
333 } else {
334 theProcessTable->SetProcessActivation(currentProcessName,
335 currentParticle,
336 fActive);
337 }
338 } else {
339 if ( currentParticle == 0 ) {
340 theProcessTable->SetProcessActivation(G4ProcessType(type),
341 fActive);
342 } else {
343 theProcessTable->SetProcessActivation(G4ProcessType(type),
344 currentParticle,
345 fActive);
346 }
347 }
348 G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
349 // process/activate , inactivate
350 }
351 }
352}
353
354
355//////////////////
356G4String G4ProcessTableMessenger::GetCurrentValue(G4UIcommand * command)
357{
358 G4ProcessTable::G4ProcNameVector* procNameVector
359 = theProcessTable->GetNameList();
360
361 G4String candidates;
362 G4String returnValue('\0');
363
364 std::ostringstream os;
365 G4UIparameter * param;
366
367 G4int idx;
368
369 if( command==verboseCmd ){
370 //Commnad /process/verbose
371 os << theProcessTable->GetVerboseLevel();
372 returnValue = os.str();
373
374 } else if ( command==listCmd ){
375 //Commnad /process/list
376 candidates = "all";
377 for (idx = 0; idx < NumberOfProcessType ; idx ++ ) {
378 candidates += " " +
379 G4VProcess::GetProcessTypeName(G4ProcessType(idx));
380 }
381 listCmd->SetCandidates((const char*)(candidates));
382 returnValue = currentProcessTypeName;
383
384 } else {
385 //Commnad /process/dump, activate, inactivate
386 // process name
387 param = command->GetParameter(0);
388 candidates = "";
389 G4ProcessTable::G4ProcNameVector::iterator itr;
390 for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
391 candidates += " " + (*itr);
392 }
393 param->SetParameterCandidates((const char*)(candidates));
394 // particle name
395 param = command->GetParameter(1);
396 candidates = "all";
397 G4ParticleTable::G4PTblDicIterator *piter
398 = G4ParticleTable::GetParticleTable()->GetIterator();
399 piter -> reset();
400 while( (*piter)() ){
401 G4ParticleDefinition *particle = piter->value();
402 candidates += " " + particle->GetParticleName();
403 }
404 param->SetParameterCandidates((const char*)(candidates));
405
406 returnValue = currentProcessName + " " + currentParticleName;
407
408 }
409
410 return returnValue;
411}
412
413/////////////////
414G4String G4ProcessTableMessenger::GetProcessTypeName(G4ProcessType aType) const
415{
416 return G4VProcess::GetProcessTypeName(aType);
417}
418
419/////////////////
420G4int G4ProcessTableMessenger::GetProcessType(const G4String& aTypeName) const
421{
422 G4int type = -1;
423 for (G4int idx = 0; idx < NumberOfProcessType ; idx ++ ) {
424 if (aTypeName == G4VProcess::GetProcessTypeName(G4ProcessType(idx)) ) {
425 type = idx;
426 break;
427 }
428 }
429 return type;
430}
431
432
433/////////////////
434void G4ProcessTableMessenger::SetNumberOfProcessType()
435{
436 G4bool isFoundEndMark = false;
437 G4int idx;
438 for (idx = 0; idx < 1000 ; idx ++ ) {
439 G4String typeName = G4VProcess::GetProcessTypeName(G4ProcessType(idx));
440 isFoundEndMark = typeName.contains("---");
441 if ( isFoundEndMark ) break;
442 }
443 if ( isFoundEndMark ) {
444 NumberOfProcessType = idx;
445 } else {
446 G4Exception("G4ProcessTableMessenger::SetNumberOfProcessType()","No End Mark",
447 FatalException,"");
448 }
449}
450
451
452
453
Note: See TracBrowser for help on using the repository browser.