Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RunMessenger.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$
28//
29
30#include "G4RunMessenger.hh"
31#include "G4RunManager.hh"
32#include "G4UIdirectory.hh"
34#include "G4UIcmdWithAString.hh"
36#include "G4UIcmdWithABool.hh"
37#include "G4UIcommand.hh"
38#include "G4UIparameter.hh"
39#include "G4UImanager.hh"
41#include "G4ios.hh"
42#include "G4MaterialScanner.hh"
43#include "G4Tokenizer.hh"
44#include "Randomize.hh"
45#include <sstream>
46
48:runManager(runMgr)
49{
50 runDirectory = new G4UIdirectory("/run/");
51 runDirectory->SetGuidance("Run control commands.");
52
53 initCmd = new G4UIcmdWithoutParameter("/run/initialize",this);
54 initCmd->SetGuidance("Initialize G4 kernel.");
56
57 beamOnCmd = new G4UIcommand("/run/beamOn",this);
58 beamOnCmd->SetGuidance("Start a Run.");
59 beamOnCmd->SetGuidance("If G4 kernel is not initialized, it will be initialized.");
60 beamOnCmd->SetGuidance("Default number of events to be processed is 1.");
61 beamOnCmd->SetGuidance("The second and third arguments can be used for");
62 beamOnCmd->SetGuidance("executing a macro file at the end of each event.");
63 beamOnCmd->SetGuidance("If the second argument, i.e. name of the macro");
64 beamOnCmd->SetGuidance("file, is given but the third argument is not,");
65 beamOnCmd->SetGuidance("the macro file will be executed for all of the");
66 beamOnCmd->SetGuidance("event.");
67 beamOnCmd->SetGuidance("If the third argument (nSelect) is given, the");
68 beamOnCmd->SetGuidance("macro file will be executed only for the first");
69 beamOnCmd->SetGuidance("nSelect events.");
71 G4UIparameter* p1 = new G4UIparameter("numberOfEvent",'i',true);
72 p1->SetDefaultValue(1);
73 p1->SetParameterRange("numberOfEvent >= 0");
74 beamOnCmd->SetParameter(p1);
75 G4UIparameter* p2 = new G4UIparameter("macroFile",'s',true);
76 p2->SetDefaultValue("***NULL***");
77 beamOnCmd->SetParameter(p2);
78 G4UIparameter* p3 = new G4UIparameter("nSelect",'i',true);
79 p3->SetDefaultValue(-1);
80 p3->SetParameterRange("nSelect>=-1");
81 beamOnCmd->SetParameter(p3);
82
83 verboseCmd = new G4UIcmdWithAnInteger("/run/verbose",this);
84 verboseCmd->SetGuidance("Set the Verbose level of G4RunManager.");
85 verboseCmd->SetGuidance(" 0 : Silent (default)");
86 verboseCmd->SetGuidance(" 1 : Display main topics");
87 verboseCmd->SetGuidance(" 2 : Display main topics and run summary");
88 verboseCmd->SetParameterName("level",true);
89 verboseCmd->SetDefaultValue(0);
90 verboseCmd->SetRange("level >=0 && level <=2");
91
92 dumpRegCmd = new G4UIcmdWithAString("/run/dumpRegion",this);
93 dumpRegCmd->SetGuidance("Dump region information.");
94 dumpRegCmd->SetGuidance("In case name of a region is not given, all regions will be displayed.");
95 dumpRegCmd->SetParameterName("regionName", true);
96 dumpRegCmd->SetDefaultValue("**ALL**");
98
99 dumpCoupleCmd = new G4UIcmdWithoutParameter("/run/dumpCouples",this);
100 dumpCoupleCmd->SetGuidance("Dump material-cuts-couple information.");
101 dumpCoupleCmd->SetGuidance("Note that material-cuts-couple information is updated");
102 dumpCoupleCmd->SetGuidance("after BeamOn has started.");
103 dumpCoupleCmd->AvailableForStates(G4State_Idle);
104
105 optCmd = new G4UIcmdWithABool("/run/optimizeGeometry",this);
106 optCmd->SetGuidance("Set the optimization flag for geometry.");
107 optCmd->SetGuidance("If it is set to TRUE, G4GeometryManager will optimize");
108 optCmd->SetGuidance("the geometry definitions.");
109 optCmd->SetGuidance("GEANT4 is initialized with this flag as TRUE.");
110 optCmd->SetParameterName("optimizeFlag",true);
111 optCmd->SetDefaultValue(true);
113
114 brkBoECmd = new G4UIcmdWithABool("/run/breakAtBeginOfEvent",this);
115 brkBoECmd->SetGuidance("Set a break point at the begining of every event.");
116 brkBoECmd->SetParameterName("flag",true);
117 brkBoECmd->SetDefaultValue(true);
118
119 brkEoECmd = new G4UIcmdWithABool("/run/breakAtEndOfEvent",this);
120 brkEoECmd->SetGuidance("Set a break point at the end of every event.");
121 brkEoECmd->SetParameterName("flag",true);
122 brkEoECmd->SetDefaultValue(true);
123
124 abortCmd = new G4UIcmdWithABool("/run/abort",this);
125 abortCmd->SetGuidance("Abort current run processing.");
126 abortCmd->SetGuidance("If softAbort is false (default), currently processing event will be immediately aborted,");
127 abortCmd->SetGuidance("while softAbort is true, abortion occurs after processing the current event.");
129 abortCmd->SetParameterName("softAbort",true);
130 abortCmd->SetDefaultValue(false);
131
132 abortEventCmd = new G4UIcmdWithoutParameter("/run/abortCurrentEvent",this);
133 abortEventCmd->SetGuidance("Abort currently processing event.");
135
136 geomCmd = new G4UIcmdWithoutParameter("/run/geometryModified",this);
137 geomCmd->SetGuidance("Force geometry to be closed again.");
138 geomCmd->SetGuidance("This command must be applied");
139 geomCmd->SetGuidance(" if geometry has been modified after the");
140 geomCmd->SetGuidance(" first initialization (or BeamOn).");
142
143 physCmd = new G4UIcmdWithoutParameter("/run/physicsModified",this);
144 physCmd->SetGuidance("Force all physics tables recalculated again.");
145 physCmd->SetGuidance("This command must be applied");
146 physCmd->SetGuidance(" if physics process has been modified after the");
147 physCmd->SetGuidance(" first initialization (or BeamOn).");
149
150 cutCmd = new G4UIcmdWithoutParameter("/run/cutoffModified",this);
151 cutCmd->SetGuidance("/run/cutoffModified becomes obsolete.");
152 cutCmd->SetGuidance("It is safe to remove invoking this command.");
153
154 constScoreCmd = new G4UIcmdWithoutParameter("/run/constructScoringWorlds",this);
155 constScoreCmd->SetGuidance("Constrct scoring parallel world(s) if defined.");
156 constScoreCmd->SetGuidance("This command is not mandatory, but automatically called when a run starts.");
157 constScoreCmd->SetGuidance("But the user may use this to visualize the scoring world(s) before a run to start.");
158 constScoreCmd->AvailableForStates(G4State_Idle);
159
160 materialScanner = new G4MaterialScanner();
161
162 randomDirectory = new G4UIdirectory("/random/");
163 randomDirectory->SetGuidance("Random number status control commands.");
164
165 seedCmd = new G4UIcmdWithAString("/random/setSeeds",this);
166 seedCmd->SetGuidance("Initialize the random number generator with integer seed stream.");
167 seedCmd->SetGuidance("Number of integers should be more than 1.");
168 seedCmd->SetGuidance("Actual number of integers to be used depends on the individual random number engine.");
169 seedCmd->SetParameterName("IntArray",false);
171
172 randDirCmd = new G4UIcmdWithAString("/random/setDirectoryName",this);
173 randDirCmd->SetGuidance("Define the directory name of the rndm status files.");
174 randDirCmd->SetGuidance("Directory will be created if it does not exist.");
175 randDirCmd->SetParameterName("fileName",true);
176 randDirCmd->SetDefaultValue("./");
178
179 savingFlagCmd = new G4UIcmdWithABool("/random/setSavingFlag",this);
180 savingFlagCmd->SetGuidance("The randomNumberStatus will be saved at :");
181 savingFlagCmd->SetGuidance("begining of run (currentRun.rndm) and "
182 "begining of event (currentEvent.rndm) ");
183 savingFlagCmd->SetParameterName("flag",true);
184 savingFlagCmd->SetDefaultValue(true);
185
186 saveThisRunCmd = new G4UIcmdWithoutParameter("/random/saveThisRun",this);
187 saveThisRunCmd->SetGuidance("copy currentRun.rndm to runXXX.rndm");
189
190 saveThisEventCmd = new G4UIcmdWithoutParameter("/random/saveThisEvent",this);
191 saveThisEventCmd->SetGuidance("copy currentEvent.rndm to runXXXevtYYY.rndm");
192 saveThisEventCmd->AvailableForStates(G4State_EventProc);
193
194 restoreRandCmd = new G4UIcmdWithAString("/random/resetEngineFrom",this);
195 restoreRandCmd->SetGuidance("Reset the status of the rndm engine from a file.");
196 restoreRandCmd->SetGuidance("See CLHEP manual for detail.");
197 restoreRandCmd->SetGuidance("The engine status must be stored beforehand.");
198 restoreRandCmd->SetGuidance("Directory of the status file should be set by"
199 " /random/setDirectoryName.");
200 restoreRandCmd->SetParameterName("fileName",true);
201 restoreRandCmd->SetDefaultValue("currentRun.rndm");
203
204 randEvtCmd = new G4UIcmdWithAnInteger("/run/storeRndmStatToEvent",this);
205 randEvtCmd->SetGuidance("Flag to store rndm status to G4Event object.");
206 randEvtCmd->SetGuidance(" flag = 0 : not store (default)");
207 randEvtCmd->SetGuidance(" flag = 1 : status before primary particle generation is stored");
208 randEvtCmd->SetGuidance(" flag = 2 : status before event processing (after primary particle generation) is stored");
209 randEvtCmd->SetGuidance(" flag = 3 : both are stored");
210 randEvtCmd->SetGuidance("Note: Some performance overhead may be seen by storing rndm status, in particular");
211 randEvtCmd->SetGuidance("for the case of simplest geometry and small number of tracks per event.");
212 randEvtCmd->SetParameterName("flag",true);
213 randEvtCmd->SetDefaultValue(0);
214 randEvtCmd->SetRange("flag>=0 && flag<3");
216
217 //old commands for the rndm engine status handling
218 //
219 randDirOld = new G4UIcmdWithAString("/run/randomNumberStatusDirectory",this);
220 randDirOld->SetGuidance("Define the directory name of the rndm status files.");
221 randDirOld->SetGuidance("Directory must be creates before storing the files.");
222 randDirOld->SetGuidance("OBSOLETE --- Please use commands in /random/ directory");
223 randDirOld->SetParameterName("fileName",true);
224 randDirOld->SetDefaultValue("./");
226
227 storeRandOld = new G4UIcmdWithAnInteger("/run/storeRandomNumberStatus",this);
228 storeRandOld->SetGuidance("The randomNumberStatus will be saved at :");
229 storeRandOld->SetGuidance("begining of run (currentRun.rndm) and "
230 "begining of event (currentEvent.rndm) ");
231 storeRandOld->SetGuidance("OBSOLETE --- Please use commands in /random/ directory");
232 storeRandOld->SetParameterName("flag",true);
233 storeRandOld->SetDefaultValue(1);
234
235 restoreRandOld = new G4UIcmdWithAString("/run/restoreRandomNumberStatus",this);
236 restoreRandOld->SetGuidance("Reset the status of the rndm engine from a file.");
237 restoreRandOld->SetGuidance("See CLHEP manual for detail.");
238 restoreRandOld->SetGuidance("The engine status must be stored beforehand.");
239 restoreRandOld->SetGuidance("Directory of the status file should be set by"
240 " /random/setDirectoryName.");
241 restoreRandOld->SetGuidance("OBSOLETE --- Please use commands in /random/ directory");
242 restoreRandOld->SetParameterName("fileName",true);
243 restoreRandOld->SetDefaultValue("currentRun.rndm");
245}
246
248{
249 delete materialScanner;
250 delete beamOnCmd;
251 delete verboseCmd;
252 delete optCmd;
253 delete dumpRegCmd;
254 delete dumpCoupleCmd;
255 delete brkBoECmd;
256 delete brkEoECmd;
257 delete abortCmd;
258 delete abortEventCmd;
259 delete initCmd;
260 delete geomCmd;
261 delete physCmd;
262 delete cutCmd;
263 delete randEvtCmd;
264 delete randDirOld; delete storeRandOld; delete restoreRandOld;
265 delete constScoreCmd;
266 delete runDirectory;
267
268 delete randDirCmd;
269 delete seedCmd;
270 delete savingFlagCmd;
271 delete saveThisRunCmd;
272 delete saveThisEventCmd;
273 delete restoreRandCmd;
274 delete randomDirectory;
275}
276
278{
279 if( command==beamOnCmd )
280 {
281 G4int nev;
282 G4int nst;
283 const char* nv = (const char*)newValue;
284 std::istringstream is(nv);
285 is >> nev >> macroFileName >> nst;
286 if(macroFileName=="***NULL***")
287 { runManager->BeamOn(nev); }
288 else
289 { runManager->BeamOn(nev,macroFileName,nst); }
290 }
291 else if( command==verboseCmd )
292 { runManager->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue)); }
293 else if( command==dumpRegCmd )
294 {
295 if(newValue=="**ALL**")
296 { runManager->DumpRegion(); }
297 else
298 { runManager->DumpRegion(newValue); }
299 }
300 else if( command==dumpCoupleCmd)
301 {
303 }
304 else if( command==optCmd )
305 { runManager->SetGeometryToBeOptimized(optCmd->GetNewBoolValue(newValue)); }
306 else if( command==brkBoECmd )
308 else if( command==brkEoECmd )
310 else if( command==abortCmd )
311 { runManager->AbortRun(abortCmd->GetNewBoolValue(newValue)); }
312 else if( command==abortEventCmd )
313 { runManager->AbortEvent(); }
314 else if( command==initCmd )
315 { runManager->Initialize(); }
316 else if( command==geomCmd )
317 { runManager->GeometryHasBeenModified(); }
318 else if( command==physCmd )
319 { runManager->PhysicsHasBeenModified(); }
320 else if( command==cutCmd )
321 { runManager->CutOffHasBeenModified(); }
322
323 else if( command==seedCmd )
324 {
325 G4Tokenizer next(newValue);
326 G4int idx=0;
327 long seeds[100];
328 G4String vl;
329 while(!(vl=next()).isNull())
330 { seeds[idx] = (long)(StoI(vl)); idx++; }
331 if(idx<2)
332 { G4cerr << "/random/setSeeds should have at least two integers. Command ignored." << G4endl; }
333 else
334 {
335 seeds[idx] = 0;
337 }
338 }
339 else if( command==randDirCmd )
340 { runManager->SetRandomNumberStoreDir(newValue); }
341 else if( command==savingFlagCmd )
342 { runManager->SetRandomNumberStore(savingFlagCmd->GetNewBoolValue(newValue)); }
343 else if( command==saveThisRunCmd )
344 { runManager->rndmSaveThisRun(); }
345 else if( command==saveThisEventCmd )
346 { runManager->rndmSaveThisEvent(); }
347 else if( command==restoreRandCmd )
348 { runManager->RestoreRandomNumberStatus(newValue); }
349 else if( command==randEvtCmd )
350 { runManager->StoreRandomNumberStatusToG4Event(randEvtCmd->GetNewIntValue(newValue)); }
351
352 else if( command==randDirOld )
353 {G4cout << "warning: deprecated command. Use /random/setDirectoryName"
354 << G4endl;
355 // runManager->SetRandomNumberStoreDir(newValue);
356 }
357 else if( command==storeRandOld )
358 {G4cout << "warning: deprecated command. Use /random/setSavingFlag"
359 << G4endl;
360 // G4int frequency = storeRandOld->GetNewIntValue(newValue);
361 // G4bool flag = false;
362 // if(frequency != 0) flag = true;
363 // runManager->SetRandomNumberStore(flag);
364 }
365 else if( command==restoreRandOld )
366 {G4cout << "warning: deprecated command. Use /random/resetEngineFrom"
367 << G4endl;
368 // runManager->RestoreRandomNumberStatus(newValue);
369 }
370 else if( command==constScoreCmd )
371 { runManager->ConstructScoringWorlds(); }
372
373}
374
376{
377 G4String cv;
378
379 if( command==verboseCmd )
380 { cv = verboseCmd->ConvertToString(runManager->GetVerboseLevel()); }
381 else if( command==randDirCmd )
382 { cv = runManager->GetRandomNumberStoreDir(); }
383 else if( command==randEvtCmd )
384 { cv = randEvtCmd->ConvertToString(runManager->GetFlagRandomNumberStatusToG4Event()); }
385
386 return cv;
387}
388
@ G4State_EventProc
@ G4State_Idle
@ G4State_GeomClosed
@ G4State_PreInit
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
static void setTheSeeds(const long *seeds, int aux=-1)
Definition: Random.cc:141
static G4ProductionCutsTable * GetProductionCutsTable()
virtual void AbortRun(G4bool softAbort=false)
virtual void Initialize()
virtual void RestoreRandomNumberStatus(const G4String &fileN)
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
void SetRandomNumberStoreDir(const G4String &dir)
virtual void rndmSaveThisEvent()
virtual void AbortEvent()
virtual void rndmSaveThisRun()
void PhysicsHasBeenModified()
void GeometryHasBeenModified()
void SetVerboseLevel(G4int vl)
const G4String & GetRandomNumberStoreDir() const
void SetGeometryToBeOptimized(G4bool vl)
void StoreRandomNumberStatusToG4Event(G4int vl)
void CutOffHasBeenModified()
G4int GetFlagRandomNumberStatusToG4Event() const
void SetRandomNumberStore(G4bool flag)
void DumpRegion(const G4String &rname) const
G4int GetVerboseLevel() const
void ConstructScoringWorlds()
G4RunMessenger(G4RunManager *runMgr)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValues)
static G4bool GetNewBoolValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(G4bool defVal)
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:349
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:219
void SetPauseAtBeginOfEvent(G4bool vl)
Definition: G4UImanager.hh:183
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:51
void SetPauseAtEndOfEvent(G4bool vl)
Definition: G4UImanager.hh:187
G4int StoI(G4String s)
void SetDefaultValue(const char *theDefaultValue)
void SetParameterRange(const char *theRange)