Geant4_10
G4ProcessManagerMessenger.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: G4ProcessManagerMessenger.cc 71231 2013-06-12 13:06:28Z gcosmo $
28 //
29 //
30 //---------------------------------------------------------------
31 //
32 // G4ProcessManagerMessenger.cc
33 //
34 // Description:
35 // This is a messenger class to interface to exchange information
36 // between ProcessManagerand UI.
37 //
38 // History:
39 // 13 June 1997, H. Kurashige : The 1st version created.
40 // 10 Nov. 1997 H. Kurashige : fixed bugs
41 // 08 jan. 1998 H. Kurashige : new UIcommnds
42 // 02 June 2006 M. Maire : add physicsModified in activate/inactivate
43 //
44 //---------------------------------------------------------------
45 
46 
47 #include "G4UImanager.hh"
48 #include "G4UIdirectory.hh"
50 #include "G4UIcmdWithAnInteger.hh"
51 
52 #include "G4VProcess.hh"
53 #include "G4ProcessManager.hh"
54 #include "G4ParticleTable.hh"
55 
57 #include "G4ios.hh" // Include from 'system'
58 #include <iomanip> // Include from 'system'
59 
60 #include <sstream>
61 
63  :theParticleTable(pTable),
64  currentParticle(0),
65  currentProcess(0),
66  theManager(0),
67  theProcessList(0)
68 {
69  if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable();
70 
71  //Commnad /particle/process
72  thisDirectory = new G4UIdirectory("/particle/process/");
73  thisDirectory->SetGuidance("Process Manager control commands.");
74 
75  //Commnad /particle/process/dump
76  dumpCmd = new G4UIcmdWithAnInteger("/particle/process/dump",this);
77  dumpCmd->SetGuidance("dump process manager or process information");
78  dumpCmd->SetGuidance(" dump [process index]");
79  dumpCmd->SetGuidance(" process index: -1 for process manager");
80  dumpCmd->SetParameterName("index", true);
81  dumpCmd->SetDefaultValue(-1);
82 
83  //Commnad /particle/process/Verbose
84  verboseCmd = new G4UIcommand("/particle/process/verbose",this);
85  verboseCmd->SetGuidance("Set Verbose Level for Process or Process Manager");
86  verboseCmd->SetGuidance(" Verbose [Verbose] [process index]");
87  verboseCmd->SetGuidance(" process index: -1 for process manager");
88  G4UIparameter* param = new G4UIparameter("Verbose",'i',true);
89  param->SetDefaultValue(1);
90  verboseCmd->SetParameter(param);
91  param = new G4UIparameter("index",'i',true);
92  param->SetDefaultValue(-1);
93  verboseCmd->SetParameter(param);
95 
96  //Commnad /particle/process/Activate
97  activateCmd = new G4UIcmdWithAnInteger("/particle/process/activate",this);
98  activateCmd->SetGuidance("Activate process ");
99  activateCmd->SetGuidance(" Activate [process index]");
100  activateCmd->SetParameterName("index", false);
101  activateCmd->SetDefaultValue(0);
102  activateCmd->SetRange("index >=0");
104 
105  //Commnad /particle/process/inactivate
106  inactivateCmd = new G4UIcmdWithAnInteger("/particle/process/inactivate",this);
107  inactivateCmd->SetGuidance("Inactivate process ");
108  inactivateCmd->SetGuidance(" inactivate [process index]");
109  inactivateCmd->SetParameterName("index", false);
110  inactivateCmd->SetDefaultValue(0);
111  inactivateCmd->SetRange("index >=0");
113 
114 }
115 
117 {
118  delete activateCmd;
119  delete inactivateCmd;
120  delete verboseCmd;
121  delete dumpCmd;
122  delete thisDirectory;
123 }
124 
125 G4ParticleDefinition* G4ProcessManagerMessenger::SetCurrentParticle()
126 {
127  // set currentParticle pointer
128  // get particle name by asking G4ParticleMessenger
129  G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select");
130 
131  currentParticle = theParticleTable->FindParticle(particleName);
132  if (currentParticle == 0) {
133  theManager = 0;
134  G4cout << "G4ProcessManagerMessenger::SetCurrentParticle() ";
135  G4cout << particleName << " not found " << G4endl;
136  } else {
137  theManager = currentParticle->GetProcessManager();
138  theProcessList = theManager->GetProcessList();
139  }
140  return currentParticle;
141 }
142 
144 {
145  if (SetCurrentParticle()==0) {
146  G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
147  return;
148  }
149  if( command == dumpCmd ){
150  //Commnad /particle/process/dump
151  G4int index = dumpCmd->GetNewIntValue(newValue);
152  if (index <0) {
153  theManager->DumpInfo();
154  } else if ( index < theManager->GetProcessListLength()){
155  currentProcess = (*theProcessList)(index);
156  if (currentProcess == 0) {
157  G4cout << " no process at index of " << index;
158  G4cout << "in the Process Vector" << G4endl;
159  } else {
160  currentProcess->DumpInfo();
161  }
162  } else {
163  G4cout << " illegal index !!! " << G4endl;
164  currentProcess = 0;
165  }
166 
167  } else if( command==activateCmd ) {
168  //Commnad /particle/process/activate
169  theManager->SetProcessActivation(activateCmd->GetNewIntValue(newValue), true);
170  G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
171 
172  } else if( command==inactivateCmd ) {
173  //Commnad /particle/process/inactivate
174  theManager->SetProcessActivation(inactivateCmd->GetNewIntValue(newValue), false);
175  G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
176 
177  } else if( command==verboseCmd ) {
178  //Commnad /particle/process/Verbose
179  // inputstream for newValues
180  const char* temp = (const char*)(newValue);
181  std::istringstream is((char*)temp);
182  G4int Verbose, index;
183  is >>Verbose >>index;
184  if (index <0) {
185  theManager->SetVerboseLevel(Verbose);
186 
187  } else if ( index < theManager->GetProcessListLength()){
188  currentProcess = (*theProcessList)(index);
189  if (currentProcess == 0) {
190  G4cout << " no process at index of " << index;
191  G4cout << "in the Process Vector" << G4endl;
192  } else {
193  currentProcess->SetVerboseLevel(Verbose);
194  }
195  } else {
196  G4cout << " illegal index !!! " << G4endl;
197  currentProcess = 0;
198  }
199  }
200 }
201 
202 
204 {
205  G4String returnValue('\0');
206  if(SetCurrentParticle() == 0) {
207  // no particle is selected. return null strings
208  return returnValue;
209  }
210 
211  std::ostringstream os;
212 
213  if( command==verboseCmd ){
214  //Commnad /particle/process/Verbose
215  os << theManager->GetVerboseLevel();
216  returnValue = os.str();
217  }
218  return returnValue;
219 }
220 
221 
222 
223 
224 
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:168
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
Int_t index
Definition: macro.C:9
static G4int GetNewIntValue(const char *paramString)
void SetDefaultValue(const char *theDefaultValue)
void SetVerboseLevel(G4int value)
G4int GetVerboseLevel() const
G4ProcessManager * GetProcessManager() const
int G4int
Definition: G4Types.hh:78
G4VProcess * SetProcessActivation(G4VProcess *aProcess, G4bool fActive)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
G4ProcessManagerMessenger(G4ParticleTable *pTable=0)
static G4ParticleTable * GetParticleTable()
virtual G4String GetCurrentValue(G4UIcommand *command)
#define G4endl
Definition: G4ios.hh:61
virtual void DumpInfo() const
Definition: G4VProcess.cc:178
void SetDefaultValue(G4int defVal)
void SetVerboseLevel(G4int value)
Definition: G4VProcess.hh:437
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
G4ProcessVector * GetProcessList() const