Geant4_10
G4ProcessTableMessenger.cc
Go to the documentation of this file.
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 71231 2013-06-12 13:06:28Z gcosmo $
28 //
29 //
30 //---------------------------------------------------------------
31 //
32 // G4ProcessTableMessenger.cc
33 //
34 // Description:
35 // This is a messenger class to interface to exchange information
36 // between ProcessTable and UI.
37 //
38 //
39 // History:
40 // 15 Aug. 1998, H. Kurashige
41 // Use STL vector instead of RW vector 1. Mar 00 H.Kurashige
42 // 02 June 2006, add physicsModified in activate/inactivate (mma)
43 //
44 //---------------------------------------------------------------
45 
47 
48 #include "G4UImanager.hh"
49 #include "G4UIdirectory.hh"
51 #include "G4UIcmdWithAnInteger.hh"
52 #include "G4UIcmdWithAString.hh"
53 
54 #include "G4VProcess.hh"
55 #include "G4ProcessManager.hh"
56 #include "G4ProcessTable.hh"
57 #include "G4ParticleTable.hh"
58 
59 #include "G4ios.hh"
60 #include "G4Tokenizer.hh"
61 #include <iomanip>
62 #include <sstream>
63 
65 G4ThreadLocal G4int G4ProcessTableMessenger::NumberOfProcessType = 10;
66 
69  :theProcessTable(pTable),
70  currentProcessTypeName("all"),
71  currentProcessName("all"),
72  currentParticleName("all")
73 {
74  //Commnad /particle/process
75  thisDirectory = new G4UIdirectory("/process/");
76  thisDirectory->SetGuidance("Process Table control commands.");
77 
78 
79  //Commnad /particle/process/list
80  listCmd = new G4UIcmdWithAString("/process/list",this);
81  listCmd->SetGuidance("List up process names");
82  listCmd->SetGuidance(" list [type] ");
83  listCmd->SetGuidance(" type: process type [all:for all proceeses]");
84  listCmd->SetParameterName("type", true);
85  listCmd->SetDefaultValue("all");
86  SetNumberOfProcessType();
87 
88  G4String candidates("all");
89  for (G4int idx = 0; idx < NumberOfProcessType ; idx ++ ) {
90  candidates += " " +
92  }
93  listCmd->SetCandidates((const char*)(candidates));
94 
95  //Commnad /particle/process/Verbose
96  verboseCmd = new G4UIcmdWithAnInteger("/process/verbose",this);
97  verboseCmd->SetGuidance("Set Verbose Level for Process Table");
98  verboseCmd->SetGuidance(" verbose [level]");
99  verboseCmd->SetGuidance(" level: verbose level");
100  verboseCmd->SetParameterName("verbose", true);
101  verboseCmd->SetDefaultValue(1);
102  verboseCmd->SetRange("verbose >=0");
104 
105  //Commnad /particle/process/setVerbose
106  procVerboseCmd = new G4UIcommand("/process/setVerbose",this);
107  procVerboseCmd->SetGuidance("Set verbose level for processes");
108  procVerboseCmd->SetGuidance(" setVerbose level [type or name] ");
109  procVerboseCmd->SetGuidance(" level: verbose level ");
110  procVerboseCmd->SetGuidance(" name : process name ");
111  procVerboseCmd->SetGuidance(" type : process type ");
112  procVerboseCmd->SetGuidance(" [all] for all proceeses ");
113  G4UIparameter* param = new G4UIparameter("verbose",'i',false);
114  procVerboseCmd->SetParameter(param);
115  param = new G4UIparameter("type",'s',true);
116  param->SetDefaultValue("all");
117  procVerboseCmd->SetParameter(param);
119 
120  //Commnad /particle/process/dump
121  dumpCmd = new G4UIcommand("/process/dump",this);
122  dumpCmd->SetGuidance("Dump process information");
123  dumpCmd->SetGuidance(" dump name [particle]");
124  dumpCmd->SetGuidance(" name: process name or type name");
125  dumpCmd->SetGuidance(" particle: particle name [all: for all particles]");
126  param = new G4UIparameter("procName",'s',false);
127  dumpCmd->SetParameter(param);
128  param = new G4UIparameter("particle",'s',true);
129  param->SetDefaultValue("all");
130  dumpCmd->SetParameter(param);
132 
133  //Commnad /particle/process/activate
134  activateCmd = new G4UIcommand("/process/activate",this);
135  activateCmd->SetGuidance("Activate processes ");
136  activateCmd->SetGuidance(" Activate name [particle]");
137  activateCmd->SetGuidance(" name: process name or type name");
138  activateCmd->SetGuidance(" particle: particle name [all: for all particles]");
139  param = new G4UIparameter("procName",'s',false);
140  activateCmd->SetParameter(param);
141  param = new G4UIparameter("particle",'s',true);
142  param->SetDefaultValue("all");
143  activateCmd->SetParameter(param);
145 
146  //Commnad /particle/process/inactivate
147  inactivateCmd = new G4UIcommand("/process/inactivate",this);
148  inactivateCmd->SetGuidance("Inactivate process ");
149  inactivateCmd->SetGuidance("Inactivate processes ");
150  inactivateCmd->SetGuidance(" Inactivate name [particle]");
151  inactivateCmd->SetGuidance(" name: process name or type name");
152  inactivateCmd->SetGuidance(" particle: particle name [all: for all particles]");
153  param = new G4UIparameter("procName",'s',false);
154  inactivateCmd->SetParameter(param);
155  param = new G4UIparameter("particle",'s',true);
156  param->SetDefaultValue("all");
157  inactivateCmd->SetParameter(param);
159 }
160 
163 {
164  delete activateCmd;
165  delete inactivateCmd;
166  delete verboseCmd;
167  delete dumpCmd;
168  delete listCmd;
169  delete procVerboseCmd;
170  delete thisDirectory;
171 }
172 
175 {
176  G4ProcessTable::G4ProcNameVector* procNameVector
177  = theProcessTable->GetNameList();
178  G4int idx;
179 
180  G4int type = -1;
181 
182  if( command == listCmd ){
183  //Commnad /process/list
184  type = -1;
185  if (newValue == "all") {
186  currentProcessTypeName = newValue;
187  } else {
188  type = GetProcessType(newValue);
189  if (type <0) {
190  G4cout << " illegal type !!! " << G4endl;
191  } else {
192  currentProcessTypeName = newValue;
193  }
194  }
195  G4int counter = 0;
196  idx =0;
197  G4ProcessTable::G4ProcNameVector::iterator itr;
198  for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
199  idx +=1;
200  G4ProcessVector* tmpVector = theProcessTable->FindProcesses(*itr);
201  if ( (type <0) || ( ((*tmpVector)(0)->GetProcessType()) == type) ) {
202  if ( counter%4 != 0) G4cout << ",";
203  G4cout << std::setw(19) <<*itr;
204  if ((counter++)%4 == 3) {
205  G4cout << G4endl;
206  }
207  }
208  delete tmpVector;
209  }
210  G4cout << G4endl;
211  //Commnad /process/list
212 
213  } else if( command==procVerboseCmd ) {
214  //Commnad /process/setVerbose
215  G4Tokenizer next( newValue );
216 
217  // check 1st argument
218  G4String tmpS = G4String(next());
219  // inputstream for newValues
220  const char* temp = (const char*)(tmpS);
221  std::istringstream is((char*)temp);
222  G4int level;
223  is >>level;
224 
225  // check 2nd argument
226  currentProcessTypeName = G4String(next());
227  if (currentProcessTypeName.isNull()) currentProcessTypeName = "all";
228  G4bool isProcName = false;
229  G4bool isAll = false;
230  type = -1;
231 
232  if (currentProcessTypeName == "all") {
233  isAll = true;
234  } else {
235  type = GetProcessType(currentProcessTypeName);
236  if (type<0) {
237  isProcName = true;
238  currentProcessName = currentProcessTypeName;
239  currentProcessTypeName = "";
240  }
241  }
242  idx =0;
243  G4ProcessTable::G4ProcNameVector::iterator itr;
244  for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
245  idx +=1;
246  G4ProcessVector* tmpVector = theProcessTable->FindProcesses(*itr);
247  G4VProcess* p = (*tmpVector)(0);
248  if ( isAll ||
249  (!isProcName && ( p->GetProcessType() == type) ) ||
250  ( isProcName && ( p->GetProcessName()== currentProcessName) ) ){
251  p->SetVerboseLevel(level);
252  }
253  delete tmpVector;
254  }
255  //Commnad /process/setVerbose
256 
257  } else if( command==verboseCmd ) {
258  //Commnad /process/verbose
259  theProcessTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
260  //Commnad /process/verbose
261 
262  } else {
263  G4Tokenizer next( newValue );
264 
265  // check 1st argument
266  currentProcessName = G4String(next());
267  G4bool isProcName = false;
268  G4ProcessTable::G4ProcNameVector::iterator itr;
269  for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
270  if ( (*itr) == currentProcessName ) {
271  isProcName = true;
272  break;
273  }
274  }
275  if (!isProcName) {
276  type = GetProcessType(currentProcessName);
277  if (type <0 ) {
278  // no processes with specifed name
279  G4cout << " illegal process (or type) name " << G4endl;
280  currentProcessName = "";
281  return;
282  }
283  }
284 
285  // check 2nd argument
286  currentParticleName = G4String(next());
287  G4bool isParticleFound = false;
288  G4ParticleDefinition* currentParticle = 0;
289  if ( currentParticleName == "all" ) {
290  isParticleFound = true;
291 
292  } else {
293  isParticleFound = G4ParticleTable::GetParticleTable()->contains(currentParticleName);
294  if (isParticleFound) {
295  currentParticle = G4ParticleTable::GetParticleTable()->FindParticle(currentParticleName);
296  }
297 
298  }
299 
300  if ( !isParticleFound ) {
301  // no particle with specifed name
302  G4cout << " illegal particle name " << G4endl;
303  currentParticleName = "";
304  return;
305  }
306 
307  if( command==dumpCmd ) {
308  // process/dump
309  G4ProcessVector* tmpVector;
310  if (isProcName) {
311  tmpVector = theProcessTable->FindProcesses(currentProcessName);
312  } else {
313  tmpVector = theProcessTable->FindProcesses(G4ProcessType(type));
314  }
315  for (G4int i=0; i<tmpVector->length(); i++) {
316  theProcessTable->DumpInfo( (*tmpVector)(i), currentParticle );
317  }
318  delete tmpVector;
319  // process/dump
320 
321  } else if ( (command==activateCmd) || (command==inactivateCmd)) {
322  // process/activate , inactivate
323  G4bool fActive = (command==activateCmd);
324  if (isProcName) {
325  if ( currentParticle == 0 ) {
326  theProcessTable->SetProcessActivation(currentProcessName,
327  fActive);
328  } else {
329  theProcessTable->SetProcessActivation(currentProcessName,
330  currentParticle,
331  fActive);
332  }
333  } else {
334  if ( currentParticle == 0 ) {
335  theProcessTable->SetProcessActivation(G4ProcessType(type),
336  fActive);
337  } else {
338  theProcessTable->SetProcessActivation(G4ProcessType(type),
339  currentParticle,
340  fActive);
341  }
342  }
343  G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
344  // process/activate , inactivate
345  }
346  }
347 }
348 
349 
352 {
353  G4ProcessTable::G4ProcNameVector* procNameVector
354  = theProcessTable->GetNameList();
355 
356  G4String candidates;
357  G4String returnValue('\0');
358 
359  std::ostringstream os;
360  G4UIparameter * param;
361 
362  G4int idx;
363 
364  if( command==verboseCmd ){
365  //Commnad /process/verbose
366  os << theProcessTable->GetVerboseLevel();
367  returnValue = os.str();
368 
369  } else if ( command==listCmd ){
370  //Commnad /process/list
371  candidates = "all";
372  for (idx = 0; idx < NumberOfProcessType ; idx ++ ) {
373  candidates += " " +
375  }
376  listCmd->SetCandidates((const char*)(candidates));
377  returnValue = currentProcessTypeName;
378 
379  } else {
380  //Commnad /process/dump, activate, inactivate
381  // process name
382  param = command->GetParameter(0);
383  candidates = "";
384  G4ProcessTable::G4ProcNameVector::iterator itr;
385  for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
386  candidates += " " + (*itr);
387  }
388  param->SetParameterCandidates((const char*)(candidates));
389  // particle name
390  param = command->GetParameter(1);
391  candidates = "all";
394  piter -> reset();
395  while( (*piter)() ){
396  G4ParticleDefinition *particle = piter->value();
397  candidates += " " + particle->GetParticleName();
398  }
399  param->SetParameterCandidates((const char*)(candidates));
400 
401  returnValue = currentProcessName + " " + currentParticleName;
402 
403  }
404 
405  return returnValue;
406 }
407 
409 G4String G4ProcessTableMessenger::GetProcessTypeName(G4ProcessType aType) const
410 {
411  return G4VProcess::GetProcessTypeName(aType);
412 }
413 
415 G4int G4ProcessTableMessenger::GetProcessType(const G4String& aTypeName) const
416 {
417  G4int type = -1;
418  for (G4int idx = 0; idx < NumberOfProcessType ; idx ++ ) {
419  if (aTypeName == G4VProcess::GetProcessTypeName(G4ProcessType(idx)) ) {
420  type = idx;
421  break;
422  }
423  }
424  return type;
425 }
426 
427 
429 void G4ProcessTableMessenger::SetNumberOfProcessType()
430 {
431  G4bool isFoundEndMark = false;
432  G4int idx;
433  for (idx = 0; idx < 1000 ; idx ++ ) {
435  isFoundEndMark = typeName.contains("---");
436  if ( isFoundEndMark ) break;
437  }
438  if ( isFoundEndMark ) {
439  NumberOfProcessType = idx;
440  } else {
441  G4Exception("G4ProcessTableMessenger::SetNumberOfProcessType()","ProcMan014",
442  FatalException,"No End Mark");
443  }
444 }
445 
446 
447 
448 
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
static const G4String & GetProcessTypeName(G4ProcessType)
Definition: G4VProcess.cc:141
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void DumpInfo(G4VProcess *process, G4ParticleDefinition *particle=0)
static G4int GetNewIntValue(const char *paramString)
void SetParameterCandidates(const char *theString)
const char * p
Definition: xmltok.h:285
void SetDefaultValue(const char *theDefaultValue)
G4ProcessTableMessenger(G4ProcessTable *pTable)
G4ProcessType GetProcessType() const
Definition: G4VProcess.hh:414
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
void SetProcessActivation(const G4String &processName, G4bool fActive)
const G4String & GetParticleName() const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
virtual G4String GetCurrentValue(G4UIcommand *command)
void SetVerboseLevel(G4int value)
bool G4bool
Definition: G4Types.hh:79
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:145
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
G4int length() const
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool contains(const G4ParticleDefinition *particle) const
G4ProcNameVector * GetNameList()
G4bool contains(const std::string &) const
static G4ParticleTable * GetParticleTable()
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
void SetDefaultValue(const char *defVal)
G4int GetVerboseLevel() const
std::vector< G4String > G4ProcNameVector
void SetCandidates(const char *candidateList)
#define G4endl
Definition: G4ios.hh:61
void SetDefaultValue(G4int defVal)
G4ProcessVector * FindProcesses()
G4PTblDicIterator * GetIterator() const
G4bool isNull() const
void SetVerboseLevel(G4int value)
Definition: G4VProcess.hh:437
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
G4ProcessType