ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ProcessTableMessenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ProcessTableMessenger.cc
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 //
28 //
29 //---------------------------------------------------------------
30 //
31 // G4ProcessTableMessenger.cc
32 //
33 // Description:
34 // This is a messenger class to interface to exchange information
35 // between ProcessTable and UI.
36 //
37 //
38 // History:
39 // 15 Aug. 1998, H. Kurashige
40 // Use STL vector instead of RW vector 1. Mar 00 H.Kurashige
41 // 02 June 2006, add physicsModified in activate/inactivate (mma)
42 //
43 //---------------------------------------------------------------
44 
46 
47 #include "G4UImanager.hh"
48 #include "G4UIdirectory.hh"
50 #include "G4UIcmdWithAnInteger.hh"
51 #include "G4UIcmdWithAString.hh"
52 
53 #include "G4VProcess.hh"
54 #include "G4ProcessManager.hh"
55 #include "G4ProcessTable.hh"
56 #include "G4ParticleTable.hh"
57 
58 #include "G4ios.hh"
59 #include "G4Tokenizer.hh"
60 #include <iomanip>
61 #include <sstream>
62 
65 
68  :theProcessTable(pTable),
69  currentProcessTypeName("all"),
70  currentProcessName("all"),
71  currentParticleName("all")
72 {
73  //Commnad /particle/process
74  thisDirectory = new G4UIdirectory("/process/");
75  thisDirectory->SetGuidance("Process Table control commands.");
76 
77 
78  //Commnad /particle/process/list
79  listCmd = new G4UIcmdWithAString("/process/list",this);
80  listCmd->SetGuidance("List up process names");
81  listCmd->SetGuidance(" list [type] ");
82  listCmd->SetGuidance(" type: process type [all:for all processes]");
83  listCmd->SetParameterName("type", true);
84  listCmd->SetDefaultValue("all");
86 
87  G4String candidates("all");
88  for (G4int idx = 0; idx < NumberOfProcessType ; idx ++ ) {
89  candidates += " " +
91  }
92  listCmd->SetCandidates((const char*)(candidates));
93 
94  //Commnad /particle/process/verbose
95  verboseCmd = new G4UIcmdWithAnInteger("/process/verbose",this);
96  verboseCmd->SetGuidance("Set Verbose Level for Process Table");
97  verboseCmd->SetGuidance(" verbose [level]");
98  verboseCmd->SetGuidance(" level: verbose level");
99  verboseCmd->SetParameterName("verbose", true);
101  verboseCmd->SetRange("verbose >=0");
103 
104  //Commnad /particle/process/setVerbose
105  procVerboseCmd = new G4UIcommand("/process/setVerbose",this);
106  procVerboseCmd->SetGuidance("Set verbose level for processes");
107  procVerboseCmd->SetGuidance(" setVerbose level [type or name] ");
108  procVerboseCmd->SetGuidance(" level: verbose level ");
109  procVerboseCmd->SetGuidance(" name : process name ");
110  procVerboseCmd->SetGuidance(" type : process type ");
111  procVerboseCmd->SetGuidance(" [all] for all processes ");
112  G4UIparameter* param = new G4UIparameter("verbose",'i',false);
114  param = new G4UIparameter("type",'s',true);
115  param->SetDefaultValue("all");
118 
119  //Commnad /particle/process/dump
120  dumpCmd = new G4UIcommand("/process/dump",this);
121  dumpCmd->SetGuidance("Dump process information");
122  dumpCmd->SetGuidance(" dump name [particle]");
123  dumpCmd->SetGuidance(" name: process name or type name");
124  dumpCmd->SetGuidance(" particle: particle name [all: for all particles]");
125  param = new G4UIparameter("procName",'s',false);
126  dumpCmd->SetParameter(param);
127  param = new G4UIparameter("particle",'s',true);
128  param->SetDefaultValue("all");
129  dumpCmd->SetParameter(param);
131 
132  //Commnad /process/activate
133  activateCmd = new G4UIcommand("/process/activate",this);
134  activateCmd->SetGuidance("Activate processes ");
135  activateCmd->SetGuidance(" Activate name [particle]");
136  activateCmd->SetGuidance(" name: process name or type name");
137  activateCmd->SetGuidance(" particle: particle name [all: for all particles]");
138  param = new G4UIparameter("procName",'s',false);
139  activateCmd->SetParameter(param);
140  param = new G4UIparameter("particle",'s',true);
141  param->SetDefaultValue("all");
142  activateCmd->SetParameter(param);
144 
145  //Commnad /process/inactivate
146  inactivateCmd = new G4UIcommand("/process/inactivate",this);
147  inactivateCmd->SetGuidance("Inactivate process ");
148  inactivateCmd->SetGuidance("Inactivate processes ");
149  inactivateCmd->SetGuidance(" Inactivate name [particle]");
150  inactivateCmd->SetGuidance(" name: process name or type name");
151  inactivateCmd->SetGuidance(" particle: particle name [all: for all particles]");
152  param = new G4UIparameter("procName",'s',false);
153  inactivateCmd->SetParameter(param);
154  param = new G4UIparameter("particle",'s',true);
155  param->SetDefaultValue("all");
156  inactivateCmd->SetParameter(param);
158 }
159 
162 {
163  delete activateCmd;
164  delete inactivateCmd;
165  delete verboseCmd;
166  delete dumpCmd;
167  delete listCmd;
168  delete procVerboseCmd;
169  delete thisDirectory;
170 }
171 
174 {
175  G4ProcessTable::G4ProcNameVector* procNameVector
177  G4int idx;
178  G4int type = -1;
180 
181  if( command == listCmd ){
182  //Commnad /process/list
183  type = -1;
184  if (newValue == "all") {
185  currentProcessTypeName = newValue;
186  } else {
187  type = GetProcessType(newValue);
188  if (type <0) {
189  G4cout << " illegal type !!! " << G4endl;
190  } else {
191  currentProcessTypeName = newValue;
192  }
193  }
194  G4int counter = 0;
195  idx =0;
196  G4ProcessTable::G4ProcNameVector::iterator itr;
197  for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
198  idx +=1;
199  G4ProcessVector* tmpVector = theProcessTable->FindProcesses(*itr);
200  if ( (type <0) || ( ((*tmpVector)(0)->GetProcessType()) == type) ) {
201  if ( counter%4 != 0) G4cout << ",";
202  G4cout << std::setw(19) <<*itr;
203  if ((counter++)%4 == 3) {
204  G4cout << G4endl;
205  }
206  }
207  delete tmpVector;
208  }
209  G4cout << G4endl;
210  //Commnad /process/list
211 
212  } else if( command==procVerboseCmd ) {
213  //Commnad /process/setVerbose
214  G4Tokenizer next( newValue );
215 
216  // check 1st argument
217  G4String tmpS = G4String(next());
218  // inputstream for newValues
219  const char* temp = (const char*)(tmpS);
220  std::istringstream is((char*)temp);
221  G4int level;
222  is >>level;
223 
224  // check 2nd argument
227  G4bool isProcName = false;
228  G4bool isAll = false;
229  type = -1;
230 
231  if (currentProcessTypeName == "all") {
232  isAll = true;
233  } else {
235  if (type<0) {
236  isProcName = true;
239  }
240  }
241  idx =0;
242  for (auto itr=procNameVector->cbegin(); itr!=procNameVector->cend(); ++itr)
243  {
244  idx +=1;
245  G4ProcessVector* tmpVector = theProcessTable->FindProcesses(*itr);
246  G4VProcess* p = (*tmpVector)(0);
247  if ( isAll ||
248  (!isProcName && ( p->GetProcessType() == type) ) ||
249  ( isProcName && ( p->GetProcessName()== currentProcessName) ) ){
250  p->SetVerboseLevel(level);
251  }
252  delete tmpVector;
253  }
254  //Commnad /process/setVerbose
255 
256  } else if( command==verboseCmd ) {
257  //Commnad /process/verbose
259  //Commnad /process/verbose
260 
261  } else {
262  G4Tokenizer next( newValue );
263 
264  // check 1st argument
265  currentProcessName = G4String(next());
266  G4bool isProcName = false;
267  G4ProcessTable::G4ProcNameVector::iterator itr;
268  for (itr=procNameVector->begin(); itr!=procNameVector->end(); ++itr) {
269  if ( (*itr) == currentProcessName ) {
270  isProcName = true;
271  break;
272  }
273  }
274  if (!isProcName) {
276  if (type <0 ) {
277  // no processes with specifed name
278  ed << " illegal process (or type) name ["
279  << currentProcessName << "]";
280  command->CommandFailed(ed);
281  currentProcessName = "";
282  return;
283  }
284  }
285 
286  // check 2nd argument
287  currentParticleName = G4String(next());
288  G4bool isParticleFound = false;
289  G4ParticleDefinition* currentParticle = nullptr;
290  if ( currentParticleName == "all" ) {
291  isParticleFound = true;
292 
293  } else {
295  if (isParticleFound) {
297  }
298 
299  }
300 
301  if ( !isParticleFound ) {
302  // no particle with specifed name
303  ed << " illegal particle name [" << currentParticleName << "]";
304  command->CommandFailed(ed);
305  currentParticleName = "";
306  return;
307  }
308 
309  if( command==dumpCmd ) {
310  // process/dump
311  G4ProcessVector* tmpVector;
312  if (isProcName) {
314  } else {
315  tmpVector = theProcessTable->FindProcesses(G4ProcessType(type));
316  }
317  for (std::size_t i=0; i<tmpVector->length(); ++i) {
318  theProcessTable->DumpInfo( (*tmpVector)(i), currentParticle );
319  }
320  delete tmpVector;
321  // process/dump
322 
323  } else if ( (command==activateCmd) || (command==inactivateCmd)) {
324  // process/activate , inactivate
325  G4bool fActive = (command==activateCmd);
326  if (isProcName) {
327  if ( currentParticle == nullptr ) {
329  fActive);
330  } else {
332  currentParticle,
333  fActive);
334  }
335  } else {
336  if ( currentParticle == nullptr ) {
338  fActive);
339  } else {
341  currentParticle,
342  fActive);
343  }
344  }
345  G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
346  // process/activate , inactivate
347  }
348  }
349 }
350 
351 
354 {
355  if( command==verboseCmd ){
356  //Commnad /process/verbose
358 
359  } else if ( command==listCmd ){
360  //Commnad /process/list
361  return currentProcessTypeName;
362 
363  } else {
364  //Commnad /process/dump, activate, inactivate
365  return (currentProcessName + " " + currentParticleName);
366 
367  }
368 
369  return "";
370 }
371 
374 {
375  return G4VProcess::GetProcessTypeName(aType);
376 }
377 
380 {
381  G4int type = -1;
382  for (G4int idx = 0; idx < NumberOfProcessType ; ++idx ) {
383  if (aTypeName == G4VProcess::GetProcessTypeName(G4ProcessType(idx)) ) {
384  type = idx;
385  break;
386  }
387  }
388  return type;
389 }
390 
391 
394 {
395  G4bool isFoundEndMark = false;
396  G4int idx;
397  for (idx = 0; idx < 1000 ; ++idx ) {
399  isFoundEndMark = typeName.contains("---");
400  if ( isFoundEndMark ) break;
401  }
402  if ( isFoundEndMark ) {
404  } else {
405  G4Exception("G4ProcessTableMessenger::SetNumberOfProcessType()",
406  "ProcMan014",
407  FatalException,"No End Mark");
408  }
409 }
410 
411 
412 
413