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