Geant4  10.00.p03
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: G4RunMessenger.cc 84434 2014-10-15 13:42:33Z gcosmo $
28 //
29 
30 #include "G4RunMessenger.hh"
31 #include "G4RunManager.hh"
32 #include "G4MTRunManager.hh"
33 #include "G4UIdirectory.hh"
35 #include "G4UIcmdWithAString.hh"
36 #include "G4UIcmdWithAnInteger.hh"
37 #include "G4UIcmdWithABool.hh"
38 #include "G4UIcommand.hh"
39 #include "G4UIparameter.hh"
40 #include "G4UImanager.hh"
41 #include "G4ProductionCutsTable.hh"
42 #include "G4ios.hh"
43 #include "G4MaterialScanner.hh"
44 #include "G4Tokenizer.hh"
45 #include "Randomize.hh"
46 #include <sstream>
47 
49 :runManager(runMgr)
50 {
51  runDirectory = new G4UIdirectory("/run/");
52  runDirectory->SetGuidance("Run control commands.");
53 
54  initCmd = new G4UIcmdWithoutParameter("/run/initialize",this);
55  initCmd->SetGuidance("Initialize G4 kernel.");
57 
58  beamOnCmd = new G4UIcommand("/run/beamOn",this);
59  beamOnCmd->SetGuidance("Start a Run.");
60  beamOnCmd->SetGuidance("If G4 kernel is not initialized, it will be initialized.");
61  beamOnCmd->SetGuidance("Default number of events to be processed is 1.");
62  beamOnCmd->SetGuidance("The second and third arguments can be used for");
63  beamOnCmd->SetGuidance("executing a macro file at the end of each event.");
64  beamOnCmd->SetGuidance("If the second argument, i.e. name of the macro");
65  beamOnCmd->SetGuidance("file, is given but the third argument is not,");
66  beamOnCmd->SetGuidance("the macro file will be executed for all of the");
67  beamOnCmd->SetGuidance("event.");
68  beamOnCmd->SetGuidance("If the third argument (nSelect) is given, the");
69  beamOnCmd->SetGuidance("macro file will be executed only for the first");
70  beamOnCmd->SetGuidance("nSelect events.");
73  G4UIparameter* p1 = new G4UIparameter("numberOfEvent",'i',true);
74  p1->SetDefaultValue(1);
75  p1->SetParameterRange("numberOfEvent >= 0");
77  G4UIparameter* p2 = new G4UIparameter("macroFile",'s',true);
78  p2->SetDefaultValue("***NULL***");
80  G4UIparameter* p3 = new G4UIparameter("nSelect",'i',true);
81  p3->SetDefaultValue(-1);
82  p3->SetParameterRange("nSelect>=-1");
84  //beamOnCmd->SetToBeBroadcasted(false);
85 
86  verboseCmd = new G4UIcmdWithAnInteger("/run/verbose",this);
87  verboseCmd->SetGuidance("Set the Verbose level of G4RunManager.");
88  verboseCmd->SetGuidance(" 0 : Silent (default)");
89  verboseCmd->SetGuidance(" 1 : Display main topics");
90  verboseCmd->SetGuidance(" 2 : Display main topics and run summary");
91  verboseCmd->SetParameterName("level",true);
93  verboseCmd->SetRange("level >=0 && level <=2");
94 
95  printProgCmd = new G4UIcmdWithAnInteger("/run/printProgress",this);
96  printProgCmd->SetGuidance("Display begin_of_event information at given frequency.");
97  printProgCmd->SetGuidance("If it is set to zero, only the begin_of_run is shown.");
98  printProgCmd->SetGuidance("If it is set to -1, no print-out is shown.");
99  printProgCmd->SetParameterName("mod",true);
101  printProgCmd->SetRange("mod>=-1");
102 
103  nThreadsCmd = new G4UIcmdWithAnInteger("/run/numberOfThreads",this);
104  nThreadsCmd->SetGuidance("Set the number of threads to be used.");
105  nThreadsCmd->SetGuidance("This command is valid only for multi-threaded mode.");
106  nThreadsCmd->SetGuidance("This command works only in PreInit state.");
107  nThreadsCmd->SetGuidance("The command is ignored if it is issued in sequential mode.");
108  nThreadsCmd->SetParameterName("nThreads",true);
110  nThreadsCmd->SetRange("nThreads >0");
113 
114  evModCmd = new G4UIcmdWithAnInteger("/run/eventModulo",this);
115  evModCmd->SetGuidance("Set the event modulo for dispatching events to worker threads");
116  evModCmd->SetGuidance("i.e. each worker thread is ordered to simulate N events and then");
117  evModCmd->SetGuidance("comes back to G4MTRunManager for next set.");
118  evModCmd->SetGuidance("If it is set to zero (default value), N is roughly given by this.");
119  evModCmd->SetGuidance(" N = int( sqrt( number_of_events / number_of_threads ) )");
120  evModCmd->SetGuidance("The value N may affect on the computing performance in particular");
121  evModCmd->SetGuidance("if N is too small compared to the total number of events.");
122  evModCmd->SetGuidance("This command is valid only for multi-threaded mode.");
123  evModCmd->SetGuidance("This command is ignored if it is issued in sequential mode.");
124  evModCmd->SetParameterName("nev",true);
126  evModCmd->SetRange("nev>=0");
129 
130  dumpRegCmd = new G4UIcmdWithAString("/run/dumpRegion",this);
131  dumpRegCmd->SetGuidance("Dump region information.");
132  dumpRegCmd->SetGuidance("In case name of a region is not given, all regions will be displayed.");
133  dumpRegCmd->SetParameterName("regionName", true);
134  dumpRegCmd->SetDefaultValue("**ALL**");
136 
137  dumpCoupleCmd = new G4UIcmdWithoutParameter("/run/dumpCouples",this);
138  dumpCoupleCmd->SetGuidance("Dump material-cuts-couple information.");
139  dumpCoupleCmd->SetGuidance("Note that material-cuts-couple information is updated");
140  dumpCoupleCmd->SetGuidance("after BeamOn has started.");
142 
143  optCmd = new G4UIcmdWithABool("/run/optimizeGeometry",this);
144  optCmd->SetGuidance("Set the optimization flag for geometry.");
145  optCmd->SetGuidance("If it is set to TRUE, G4GeometryManager will optimize");
146  optCmd->SetGuidance("the geometry definitions.");
147  optCmd->SetGuidance("GEANT4 is initialized with this flag as TRUE.");
148  optCmd->SetParameterName("optimizeFlag",true);
149  optCmd->SetDefaultValue(true);
151 
152  brkBoECmd = new G4UIcmdWithABool("/run/breakAtBeginOfEvent",this);
153  brkBoECmd->SetGuidance("Set a break point at the begining of every event.");
154  brkBoECmd->SetParameterName("flag",true);
155  brkBoECmd->SetDefaultValue(true);
156 
157  brkEoECmd = new G4UIcmdWithABool("/run/breakAtEndOfEvent",this);
158  brkEoECmd->SetGuidance("Set a break point at the end of every event.");
159  brkEoECmd->SetParameterName("flag",true);
160  brkEoECmd->SetDefaultValue(true);
161 
162  abortCmd = new G4UIcmdWithABool("/run/abort",this);
163  abortCmd->SetGuidance("Abort current run processing.");
164  abortCmd->SetGuidance("If softAbort is false (default), currently processing event will be immediately aborted,");
165  abortCmd->SetGuidance("while softAbort is true, abortion occurs after processing the current event.");
167  abortCmd->SetParameterName("softAbort",true);
168  abortCmd->SetDefaultValue(false);
169 
170  abortEventCmd = new G4UIcmdWithoutParameter("/run/abortCurrentEvent",this);
171  abortEventCmd->SetGuidance("Abort currently processing event.");
173 
174  geomCmd = new G4UIcmdWithoutParameter("/run/geometryModified",this);
175  geomCmd->SetGuidance("Force geometry to be closed (re-voxellized) again.");
176  geomCmd->SetGuidance("This command must be applied if geometry has been modified");
177  geomCmd->SetGuidance(" after the first initialization (or BeamOn).");
179 
180  geomRebCmd = new G4UIcmdWithABool("/run/reinitializeGeometry",this);
181  geomRebCmd->SetGuidance("Force geometry to be rebuilt once again.");
182  geomRebCmd->SetGuidance("This command must be applied if the user needs his/her");
183  geomRebCmd->SetGuidance(" detector construction to be reinvoked.");
184  geomRebCmd->SetGuidance("/run/geometryModified is automatically issued with this command.");
185  geomRebCmd->SetParameterName("destroyFirst",true);
186  geomRebCmd->SetDefaultValue(false);
188 
189  physCmd = new G4UIcmdWithoutParameter("/run/physicsModified",this);
190  physCmd->SetGuidance("Force all physics tables recalculated again.");
191  physCmd->SetGuidance("This command must be applied");
192  physCmd->SetGuidance(" if physics process has been modified after the");
193  physCmd->SetGuidance(" first initialization (or BeamOn).");
195 
196  constScoreCmd = new G4UIcmdWithoutParameter("/run/constructScoringWorlds",this);
197  constScoreCmd->SetGuidance("Constrct scoring parallel world(s) if defined.");
198  constScoreCmd->SetGuidance("This command is not mandatory, but automatically called when a run starts.");
199  constScoreCmd->SetGuidance("But the user may use this to visualize the scoring world(s) before a run to start.");
201 
203 
204  randomDirectory = new G4UIdirectory("/random/");
205  randomDirectory->SetGuidance("Random number status control commands.");
206 
207  seedCmd = new G4UIcmdWithAString("/random/setSeeds",this);
208  seedCmd->SetGuidance("Initialize the random number generator with integer seed stream.");
209  seedCmd->SetGuidance("Number of integers should be more than 1.");
210  seedCmd->SetGuidance("Actual number of integers to be used depends on the individual random number engine.");
211 #ifdef G4MULTITHREADED
212  seedCmd->SetGuidance("This command sets the seeds for the master thread.");
213 #endif
214  seedCmd->SetParameterName("IntArray",false);
216  seedCmd->SetToBeBroadcasted(false);
217 
218  randDirCmd = new G4UIcmdWithAString("/random/setDirectoryName",this);
219  randDirCmd->SetGuidance("Define the directory name of the rndm status files.");
220  randDirCmd->SetGuidance("Directory will be created if it does not exist.");
221  randDirCmd->SetParameterName("fileName",true);
224 
225  savingFlagCmd = new G4UIcmdWithABool("/random/setSavingFlag",this);
226  savingFlagCmd->SetGuidance("The randomNumberStatus will be saved at :");
227  savingFlagCmd->SetGuidance("begining of run (currentRun.rndm) and "
228  "begining of event (currentEvent.rndm) ");
229  savingFlagCmd->SetParameterName("flag",true);
231 
232  saveThisRunCmd = new G4UIcmdWithoutParameter("/random/saveThisRun",this);
233  saveThisRunCmd->SetGuidance("copy currentRun.rndm to runXXX.rndm");
235 
236  saveThisEventCmd = new G4UIcmdWithoutParameter("/random/saveThisEvent",this);
237  saveThisEventCmd->SetGuidance("copy currentEvent.rndm to runXXXevtYYY.rndm");
239 
240  restoreRandCmd = new G4UIcmdWithAString("/random/resetEngineFrom",this);
241  restoreRandCmd->SetGuidance("Reset the status of the rndm engine from a file.");
242  restoreRandCmd->SetGuidance("See CLHEP manual for detail.");
243  restoreRandCmd->SetGuidance("The engine status must be stored beforehand.");
244  restoreRandCmd->SetGuidance("Directory of the status file should be set by"
245  " /random/setDirectoryName.");
246  restoreRandCmd->SetParameterName("fileName",true);
247  restoreRandCmd->SetDefaultValue("currentRun.rndm");
250 
251  saveEachEventCmd = new G4UIcmdWithABool("/random/saveEachEventFlag",this);
252  saveEachEventCmd->SetGuidance("Save random number status at beginning of each event.");
253  saveEachEventCmd->SetGuidance("File name contains run and event numbers: runXXXevtYYY.rndm");
254  saveEachEventCmd->SetParameterName("flag",true);
256 
257  randEvtCmd = new G4UIcmdWithAnInteger("/run/storeRndmStatToEvent",this);
258  randEvtCmd->SetGuidance("Flag to store rndm status to G4Event object.");
259  randEvtCmd->SetGuidance(" flag = 0 : not store (default)");
260  randEvtCmd->SetGuidance(" flag = 1 : status before primary particle generation is stored");
261  randEvtCmd->SetGuidance(" flag = 2 : status before event processing (after primary particle generation) is stored");
262  randEvtCmd->SetGuidance(" flag = 3 : both are stored");
263  randEvtCmd->SetGuidance("Note: Some performance overhead may be seen by storing rndm status, in particular");
264  randEvtCmd->SetGuidance("for the case of simplest geometry and small number of tracks per event.");
265  randEvtCmd->SetParameterName("flag",true);
267  randEvtCmd->SetRange("flag>=0 && flag<3");
269 
270 }
271 
273 {
274  delete materialScanner;
275  delete beamOnCmd;
276  delete verboseCmd;
277  delete printProgCmd;
278  delete nThreadsCmd;
279  delete evModCmd;
280  delete optCmd;
281  delete dumpRegCmd;
282  delete dumpCoupleCmd;
283  delete brkBoECmd;
284  delete brkEoECmd;
285  delete abortCmd;
286  delete abortEventCmd;
287  delete initCmd;
288  delete geomCmd;
289  delete geomRebCmd;
290  delete physCmd;
291  delete randEvtCmd;
292  delete constScoreCmd;
293 
294  delete seedCmd;
295  delete savingFlagCmd;
296  delete saveThisRunCmd;
297  delete saveThisEventCmd;
298  delete restoreRandCmd;
299  delete randomDirectory;
300  delete saveEachEventCmd;
301 
302  delete randDirCmd;
303  delete runDirectory;
304 }
305 
307 {
308  if( command==beamOnCmd )
309  {
310  G4int nev;
311  G4int nst;
312  const char* nv = (const char*)newValue;
313  std::istringstream is(nv);
314  is >> nev >> macroFileName >> nst;
315  if(macroFileName=="***NULL***")
316  { runManager->BeamOn(nev); }
317  else
318  { runManager->BeamOn(nev,macroFileName,nst); }
319  }
320  else if( command==verboseCmd )
322  else if( command == printProgCmd )
324  else if( command==nThreadsCmd )
325  {
327  if( rmType==G4RunManager::masterRM )
328  {
329  static_cast<G4MTRunManager*>(runManager)->SetNumberOfThreads(
330  nThreadsCmd->GetNewIntValue(newValue));
331  }
332  else if ( rmType==G4RunManager::sequentialRM )
333  {
334  G4cout<<"*** /run/numberOfThreads command is issued in sequential mode."
335  <<"\nCommand is ignored."<<G4endl;
336  }
337  else
338  {
339  G4Exception("G4RunMessenger::ApplyNewCommand","Run0901",FatalException,
340  "/run/numberOfThreads command is issued to local thread.");
341  }
342  }
343  else if( command==evModCmd)
344  {
346  if( rmType==G4RunManager::masterRM )
347  {
348  static_cast<G4MTRunManager*>(runManager)->SetEventModulo(evModCmd->GetNewIntValue(newValue));
349  }
350  else if ( rmType==G4RunManager::sequentialRM )
351  {
352  G4cout<<"*** /run/eventModulo command is issued in sequential mode."
353  <<"\nCommand is ignored."<<G4endl;
354  }
355  else
356  {
357  G4Exception("G4RunMessenger::ApplyNewCommand","Run0902",FatalException,
358  "/run/eventModulo command is issued to local thread.");
359  }
360  }
361  else if( command==dumpRegCmd )
362  {
363  if(newValue=="**ALL**")
364  { runManager->DumpRegion(); }
365  else
366  { runManager->DumpRegion(newValue); }
367  }
368  else if( command==dumpCoupleCmd)
369  {
371  }
372  else if( command==optCmd )
374  else if( command==brkBoECmd )
376  else if( command==brkEoECmd )
378  else if( command==abortCmd )
379  { runManager->AbortRun(abortCmd->GetNewBoolValue(newValue)); }
380  else if( command==abortEventCmd )
381  { runManager->AbortEvent(); }
382  else if( command==initCmd )
383  { runManager->Initialize(); }
384  else if( command==geomCmd )
386  else if( command==geomRebCmd )
388  else if( command==physCmd )
390  else if( command==seedCmd )
391  {
392  G4Tokenizer next(newValue);
393  G4int idx=0;
394  long seeds[100];
395  G4String vl;
396  while(!(vl=next()).isNull())
397  { seeds[idx] = (long)(StoI(vl)); idx++; }
398  if(idx<2)
399  { G4cerr << "/random/setSeeds should have at least two integers. Command ignored." << G4endl; }
400  else
401  {
402  seeds[idx] = 0;
403  G4Random::setTheSeeds(seeds);
404  }
405  }
406  else if( command==randDirCmd )
407  { runManager->SetRandomNumberStoreDir(newValue); }
408  else if( command==savingFlagCmd )
410  else if( command==saveThisRunCmd )
412  else if( command==saveThisEventCmd )
414  else if( command==restoreRandCmd )
415  { runManager->RestoreRandomNumberStatus(newValue); }
416  else if( command==randEvtCmd )
418  else if( command==saveEachEventCmd)
420  else if( command==constScoreCmd )
422 
423 }
424 
426 {
427  G4String cv;
428 
429  if( command==verboseCmd )
431  else if( command == printProgCmd )
433  else if( command==randDirCmd )
435  else if( command==randEvtCmd )
437  else if( command==nThreadsCmd )
438  {
440  if( rmType==G4RunManager::masterRM )
441  {
443  static_cast<G4MTRunManager*>(runManager)->GetNumberOfThreads());
444  }
445  else if ( rmType==G4RunManager::sequentialRM )
446  {
447  cv = "0";
448  }
449  }
450 
451  return cv;
452 }
453 
G4UIcmdWithoutParameter * saveThisRunCmd
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void GeometryHasBeenModified(G4bool prop=true)
G4UIcmdWithABool * optCmd
G4int GetVerboseLevel() const
virtual void AbortRun(G4bool softAbort=false)
G4UIcmdWithAString * randDirCmd
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
G4int GetPrintProgress()
G4RunMessenger(G4RunManager *runMgr)
G4UIcmdWithoutParameter * initCmd
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4UIdirectory * runDirectory
const G4String & GetRandomNumberStoreDir() const
void SetVerboseLevel(G4int vl)
G4UIcmdWithAString * restoreRandCmd
static G4int GetNewIntValue(const char *paramString)
void SetParameterRange(const char *theRange)
G4UIcmdWithAnInteger * nThreadsCmd
G4UIcmdWithAnInteger * evModCmd
G4UIdirectory * randomDirectory
void SetPrintProgress(G4int i)
G4UIcmdWithAnInteger * printProgCmd
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:184
void SetGeometryToBeOptimized(G4bool vl)
void SetDefaultValue(const char *theDefaultValue)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:357
void SetRandomNumberStorePerEvent(G4bool flag)
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
G4UIcmdWithoutParameter * constScoreCmd
G4UIcmdWithABool * savingFlagCmd
void SetRandomNumberStore(G4bool flag)
G4int GetFlagRandomNumberStatusToG4Event() const
G4String GetCurrentValue(G4UIcommand *command)
int G4int
Definition: G4Types.hh:78
G4UIcmdWithoutParameter * geomCmd
static G4bool GetNewBoolValue(const char *paramString)
void SetDefaultValue(G4bool defVal)
G4MaterialScanner * materialScanner
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
virtual void RestoreRandomNumberStatus(const G4String &fileN)
G4UIcmdWithoutParameter * dumpCoupleCmd
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
virtual void rndmSaveThisRun()
G4GLOB_DLL std::ostream G4cout
void StoreRandomNumberStatusToG4Event(G4int vl)
void PhysicsHasBeenModified()
RMType GetRunManagerType() const
G4UIcmdWithABool * geomRebCmd
virtual void ConstructScoringWorlds()
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
virtual void rndmSaveThisEvent()
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
G4String macroFileName
G4UIcmdWithAString * seedCmd
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
G4int StoI(G4String s)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4UIcmdWithoutParameter * physCmd
void SetNewValue(G4UIcommand *command, G4String newValues)
static G4ProductionCutsTable * GetProductionCutsTable()
G4UIcmdWithABool * brkEoECmd
G4RunManager * runManager
G4UIcmdWithoutParameter * abortEventCmd
void SetDefaultValue(const char *defVal)
G4UIcmdWithABool * saveEachEventCmd
void SetPauseAtEndOfEvent(G4bool vl)
Definition: G4UImanager.hh:196
G4UIcmdWithAString * dumpRegCmd
G4UIcommand * beamOnCmd
G4UIcmdWithABool * brkBoECmd
G4UIcmdWithAnInteger * randEvtCmd
void SetPauseAtBeginOfEvent(G4bool vl)
Definition: G4UImanager.hh:192
virtual void Initialize()
#define G4endl
Definition: G4ios.hh:61
G4UIcmdWithoutParameter * saveThisEventCmd
virtual void AbortEvent()
void SetDefaultValue(G4int defVal)
void SetRandomNumberStoreDir(const G4String &dir)
G4UIcmdWithABool * abortCmd
void DumpRegion(const G4String &rname) const
G4UIcmdWithAnInteger * verboseCmd
G4GLOB_DLL std::ostream G4cerr