Geant4  10.00.p02
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 77650 2013-11-27 08:40:42Z 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  seedCmd->SetParameterName("IntArray",false);
213 
214  randDirCmd = new G4UIcmdWithAString("/random/setDirectoryName",this);
215  randDirCmd->SetGuidance("Define the directory name of the rndm status files.");
216  randDirCmd->SetGuidance("Directory will be created if it does not exist.");
217  randDirCmd->SetParameterName("fileName",true);
220 
221  savingFlagCmd = new G4UIcmdWithABool("/random/setSavingFlag",this);
222  savingFlagCmd->SetGuidance("The randomNumberStatus will be saved at :");
223  savingFlagCmd->SetGuidance("begining of run (currentRun.rndm) and "
224  "begining of event (currentEvent.rndm) ");
225  savingFlagCmd->SetParameterName("flag",true);
227 
228  saveThisRunCmd = new G4UIcmdWithoutParameter("/random/saveThisRun",this);
229  saveThisRunCmd->SetGuidance("copy currentRun.rndm to runXXX.rndm");
231 
232  saveThisEventCmd = new G4UIcmdWithoutParameter("/random/saveThisEvent",this);
233  saveThisEventCmd->SetGuidance("copy currentEvent.rndm to runXXXevtYYY.rndm");
235 
236  restoreRandCmd = new G4UIcmdWithAString("/random/resetEngineFrom",this);
237  restoreRandCmd->SetGuidance("Reset the status of the rndm engine from a file.");
238  restoreRandCmd->SetGuidance("See CLHEP manual for detail.");
239  restoreRandCmd->SetGuidance("The engine status must be stored beforehand.");
240  restoreRandCmd->SetGuidance("Directory of the status file should be set by"
241  " /random/setDirectoryName.");
242  restoreRandCmd->SetParameterName("fileName",true);
243  restoreRandCmd->SetDefaultValue("currentRun.rndm");
246 
247  saveEachEventCmd = new G4UIcmdWithABool("/random/saveEachEventFlag",this);
248  saveEachEventCmd->SetGuidance("Save random number status at beginning of each event.");
249  saveEachEventCmd->SetGuidance("File name contains run and event numbers: runXXXevtYYY.rndm");
250  saveEachEventCmd->SetParameterName("flag",true);
252 
253  randEvtCmd = new G4UIcmdWithAnInteger("/run/storeRndmStatToEvent",this);
254  randEvtCmd->SetGuidance("Flag to store rndm status to G4Event object.");
255  randEvtCmd->SetGuidance(" flag = 0 : not store (default)");
256  randEvtCmd->SetGuidance(" flag = 1 : status before primary particle generation is stored");
257  randEvtCmd->SetGuidance(" flag = 2 : status before event processing (after primary particle generation) is stored");
258  randEvtCmd->SetGuidance(" flag = 3 : both are stored");
259  randEvtCmd->SetGuidance("Note: Some performance overhead may be seen by storing rndm status, in particular");
260  randEvtCmd->SetGuidance("for the case of simplest geometry and small number of tracks per event.");
261  randEvtCmd->SetParameterName("flag",true);
263  randEvtCmd->SetRange("flag>=0 && flag<3");
265 
266 }
267 
269 {
270  delete materialScanner;
271  delete beamOnCmd;
272  delete verboseCmd;
273  delete printProgCmd;
274  delete nThreadsCmd;
275  delete evModCmd;
276  delete optCmd;
277  delete dumpRegCmd;
278  delete dumpCoupleCmd;
279  delete brkBoECmd;
280  delete brkEoECmd;
281  delete abortCmd;
282  delete abortEventCmd;
283  delete initCmd;
284  delete geomCmd;
285  delete geomRebCmd;
286  delete physCmd;
287  delete randEvtCmd;
288  delete constScoreCmd;
289 
290  delete seedCmd;
291  delete savingFlagCmd;
292  delete saveThisRunCmd;
293  delete saveThisEventCmd;
294  delete restoreRandCmd;
295  delete randomDirectory;
296  delete saveEachEventCmd;
297 
298  delete randDirCmd;
299  delete runDirectory;
300 }
301 
303 {
304  if( command==beamOnCmd )
305  {
306  G4int nev;
307  G4int nst;
308  const char* nv = (const char*)newValue;
309  std::istringstream is(nv);
310  is >> nev >> macroFileName >> nst;
311  if(macroFileName=="***NULL***")
312  { runManager->BeamOn(nev); }
313  else
314  { runManager->BeamOn(nev,macroFileName,nst); }
315  }
316  else if( command==verboseCmd )
318  else if( command == printProgCmd )
320  else if( command==nThreadsCmd )
321  {
323  if( rmType==G4RunManager::masterRM )
324  {
325  static_cast<G4MTRunManager*>(runManager)->SetNumberOfThreads(
326  nThreadsCmd->GetNewIntValue(newValue));
327  }
328  else if ( rmType==G4RunManager::sequentialRM )
329  {
330  G4cout<<"*** /run/numberOfThreads command is issued in sequential mode."
331  <<"\nCommand is ignored."<<G4endl;
332  }
333  else
334  {
335  G4Exception("G4RunMessenger::ApplyNewCommand","Run0901",FatalException,
336  "/run/numberOfThreads command is issued to local thread.");
337  }
338  }
339  else if( command==evModCmd)
340  {
342  if( rmType==G4RunManager::masterRM )
343  {
344  static_cast<G4MTRunManager*>(runManager)->SetEventModulo(evModCmd->GetNewIntValue(newValue));
345  }
346  else if ( rmType==G4RunManager::sequentialRM )
347  {
348  G4cout<<"*** /run/eventModulo command is issued in sequential mode."
349  <<"\nCommand is ignored."<<G4endl;
350  }
351  else
352  {
353  G4Exception("G4RunMessenger::ApplyNewCommand","Run0902",FatalException,
354  "/run/eventModulo command is issued to local thread.");
355  }
356  }
357  else if( command==dumpRegCmd )
358  {
359  if(newValue=="**ALL**")
360  { runManager->DumpRegion(); }
361  else
362  { runManager->DumpRegion(newValue); }
363  }
364  else if( command==dumpCoupleCmd)
365  {
367  }
368  else if( command==optCmd )
370  else if( command==brkBoECmd )
372  else if( command==brkEoECmd )
374  else if( command==abortCmd )
375  { runManager->AbortRun(abortCmd->GetNewBoolValue(newValue)); }
376  else if( command==abortEventCmd )
377  { runManager->AbortEvent(); }
378  else if( command==initCmd )
379  { runManager->Initialize(); }
380  else if( command==geomCmd )
382  else if( command==geomRebCmd )
384  else if( command==physCmd )
386  else if( command==seedCmd )
387  {
388  G4Tokenizer next(newValue);
389  G4int idx=0;
390  long seeds[100];
391  G4String vl;
392  while(!(vl=next()).isNull())
393  { seeds[idx] = (long)(StoI(vl)); idx++; }
394  if(idx<2)
395  { G4cerr << "/random/setSeeds should have at least two integers. Command ignored." << G4endl; }
396  else
397  {
398  seeds[idx] = 0;
399  CLHEP::HepRandom::setTheSeeds(seeds);
400  }
401  }
402  else if( command==randDirCmd )
403  { runManager->SetRandomNumberStoreDir(newValue); }
404  else if( command==savingFlagCmd )
406  else if( command==saveThisRunCmd )
408  else if( command==saveThisEventCmd )
410  else if( command==restoreRandCmd )
411  { runManager->RestoreRandomNumberStatus(newValue); }
412  else if( command==randEvtCmd )
414  else if( command==saveEachEventCmd)
416  else if( command==constScoreCmd )
418 
419 }
420 
422 {
423  G4String cv;
424 
425  if( command==verboseCmd )
427  else if( command == printProgCmd )
429  else if( command==randDirCmd )
431  else if( command==randEvtCmd )
433  else if( command==nThreadsCmd )
434  {
436  if( rmType==G4RunManager::masterRM )
437  {
439  static_cast<G4MTRunManager*>(runManager)->GetNumberOfThreads());
440  }
441  else if ( rmType==G4RunManager::sequentialRM )
442  {
443  cv = "0";
444  }
445  }
446 
447  return cv;
448 }
449 
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