Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 95634 2016-02-17 08:05:21Z 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.");
72  beamOnCmd->SetToBeBroadcasted(false);
73  G4UIparameter* p1 = new G4UIparameter("numberOfEvent",'i',true);
74  p1->SetDefaultValue(1);
75  p1->SetParameterRange("numberOfEvent >= 0");
76  beamOnCmd->SetParameter(p1);
77  G4UIparameter* p2 = new G4UIparameter("macroFile",'s',true);
78  p2->SetDefaultValue("***NULL***");
79  beamOnCmd->SetParameter(p2);
80  G4UIparameter* p3 = new G4UIparameter("nSelect",'i',true);
81  p3->SetDefaultValue(-1);
82  p3->SetParameterRange("nSelect>=-1");
83  beamOnCmd->SetParameter(p3);
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);
92  verboseCmd->SetDefaultValue(0);
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);
100  printProgCmd->SetDefaultValue(-1);
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 works only in PreInit state.");
106  nThreadsCmd->SetGuidance("This command is valid only for multi-threaded mode.");
107  nThreadsCmd->SetGuidance("The command is ignored if it is issued in sequential mode.");
108  nThreadsCmd->SetParameterName("nThreads",true);
109  nThreadsCmd->SetDefaultValue(2);
110  nThreadsCmd->SetRange("nThreads >0");
111  nThreadsCmd->SetToBeBroadcasted(false);
112  nThreadsCmd->AvailableForStates(G4State_PreInit);
113 
114  maxThreadsCmd = new G4UIcmdWithoutParameter("/run/useMaximumLogicalCores",this);
115  maxThreadsCmd->SetGuidance("Set the number of threads to be the number of available logical cores.");
116  maxThreadsCmd->SetGuidance("This command works only in PreInit state.");
117  maxThreadsCmd->SetGuidance("This command is valid only for multi-threaded mode.");
118  maxThreadsCmd->SetGuidance("The command is ignored if it is issued in sequential mode.");
119  maxThreadsCmd->SetToBeBroadcasted(false);
120  maxThreadsCmd->AvailableForStates(G4State_PreInit);
121 
122  pinAffinityCmd = new G4UIcmdWithAnInteger("/run/pinAffinity",this);
123  pinAffinityCmd->SetGuidance("Locks each thread to a specific logical core. Workers are locked in round robin to logical cores.");
124  pinAffinityCmd->SetGuidance("This command is valid only for multi-threaded mode.");
125  pinAffinityCmd->SetGuidance("This command works only in PreInit state.");
126  pinAffinityCmd->SetGuidance("This command is ignored if it is issued in sequential mode.");
127  pinAffinityCmd->SetGuidance("If a value n>0 is provided it starts setting affinity from the n-th CPU (note: counting from 1).");
128  pinAffinityCmd->SetGuidance("E.g. /run/pinAffinity 3 locks first thread on third logical CPU (number 2).");
129  pinAffinityCmd->SetGuidance("If a value n<0 is provided never locks on n-th CPU.");
130  pinAffinityCmd->SetParameterName("pinAffinity",true);
131  pinAffinityCmd->SetDefaultValue(1);
132  pinAffinityCmd->SetToBeBroadcasted(false);
133  pinAffinityCmd->SetRange("pinAffinity > 0 || pinAffinity < 0");
134  pinAffinityCmd->AvailableForStates(G4State_PreInit);
135 
136  evModCmd = new G4UIcommand("/run/eventModulo",this);
137  evModCmd->SetGuidance("Set the event modulo for dispatching events to worker threads");
138  evModCmd->SetGuidance("i.e. each worker thread is ordered to simulate N events and then");
139  evModCmd->SetGuidance("comes back to G4MTRunManager for next set.");
140  evModCmd->SetGuidance("If it is set to zero (default value), N is roughly given by this.");
141  evModCmd->SetGuidance(" N = int( sqrt( number_of_events / number_of_threads ) )");
142  evModCmd->SetGuidance("The value N may affect on the computing performance in particular");
143  evModCmd->SetGuidance("if N is too small compared to the total number of events.");
144  evModCmd->SetGuidance("The second parameter seedOnce specifies how frequently each worker");
145  evModCmd->SetGuidance("thread is seeded by the random number sequence contrally managed");
146  evModCmd->SetGuidance("by the master G4MTRunManager.");
147  evModCmd->SetGuidance(" - If seedOnce is set to 0 (default), seeds that are centrally managed");
148  evModCmd->SetGuidance(" by G4MTRunManager are set for every event of every worker thread.");
149  evModCmd->SetGuidance(" This option guarantees event reproducability regardless of number");
150  evModCmd->SetGuidance(" of threads.");
151  evModCmd->SetGuidance(" - If seedOnce is set to 1, seeds are set only once for the first");
152  evModCmd->SetGuidance(" event of each run of each worker thread. Event reproducability is");
153  evModCmd->SetGuidance(" guaranteed only if the same number of worker threads are used.");
154  evModCmd->SetGuidance(" On the other hand, this option offers better computing performance");
155  evModCmd->SetGuidance(" in particular for applications with relatively small primary");
156  evModCmd->SetGuidance(" particle energy and large number of events.");
157  evModCmd->SetGuidance(" - If seedOnce is set to 2, seeds are set only for the first event of");
158  evModCmd->SetGuidance(" group of N events. This option is reserved for the future use when");
159  evModCmd->SetGuidance(" Geant4 allows number of threads to be dynatically changed during an");
160  evModCmd->SetGuidance(" event loop.");
161  evModCmd->SetGuidance("This command is valid only for multi-threaded mode.");
162  evModCmd->SetGuidance("This command is ignored if it is issued in sequential mode.");
163  G4UIparameter* emp1 = new G4UIparameter("N",'i',true);
164  emp1->SetDefaultValue(0);
165  emp1->SetParameterRange("N >= 0");
166  evModCmd->SetParameter(emp1);
167  G4UIparameter* emp2 = new G4UIparameter("seedOnce",'i',true);
168  emp2->SetDefaultValue(0);
169  emp2->SetParameterRange("seedOnce >= 0 && seedOnce <=2");
170  evModCmd->SetParameter(emp2);
171  evModCmd->SetToBeBroadcasted(false);
173 
174  dumpRegCmd = new G4UIcmdWithAString("/run/dumpRegion",this);
175  dumpRegCmd->SetGuidance("Dump region information.");
176  dumpRegCmd->SetGuidance("In case name of a region is not given, all regions will be displayed.");
177  dumpRegCmd->SetParameterName("regionName", true);
178  dumpRegCmd->SetDefaultValue("**ALL**");
179  dumpRegCmd->AvailableForStates(G4State_Idle);
180 
181  dumpCoupleCmd = new G4UIcmdWithoutParameter("/run/dumpCouples",this);
182  dumpCoupleCmd->SetGuidance("Dump material-cuts-couple information.");
183  dumpCoupleCmd->SetGuidance("Note that material-cuts-couple information is updated");
184  dumpCoupleCmd->SetGuidance("after BeamOn has started.");
185  dumpCoupleCmd->AvailableForStates(G4State_Idle);
186 
187  optCmd = new G4UIcmdWithABool("/run/optimizeGeometry",this);
188  optCmd->SetGuidance("Set the optimization flag for geometry.");
189  optCmd->SetGuidance("If it is set to TRUE, G4GeometryManager will optimize");
190  optCmd->SetGuidance("the geometry definitions.");
191  optCmd->SetGuidance("GEANT4 is initialized with this flag as TRUE.");
192  optCmd->SetParameterName("optimizeFlag",true);
193  optCmd->SetDefaultValue(true);
195 
196  brkBoECmd = new G4UIcmdWithABool("/run/breakAtBeginOfEvent",this);
197  brkBoECmd->SetGuidance("Set a break point at the begining of every event.");
198  brkBoECmd->SetParameterName("flag",true);
199  brkBoECmd->SetDefaultValue(true);
200 
201  brkEoECmd = new G4UIcmdWithABool("/run/breakAtEndOfEvent",this);
202  brkEoECmd->SetGuidance("Set a break point at the end of every event.");
203  brkEoECmd->SetParameterName("flag",true);
204  brkEoECmd->SetDefaultValue(true);
205 
206  abortCmd = new G4UIcmdWithABool("/run/abort",this);
207  abortCmd->SetGuidance("Abort current run processing.");
208  abortCmd->SetGuidance("If softAbort is false (default), currently processing event will be immediately aborted,");
209  abortCmd->SetGuidance("while softAbort is true, abortion occurs after processing the current event.");
211  abortCmd->SetParameterName("softAbort",true);
212  abortCmd->SetDefaultValue(false);
213 
214  abortEventCmd = new G4UIcmdWithoutParameter("/run/abortCurrentEvent",this);
215  abortEventCmd->SetGuidance("Abort currently processing event.");
216  abortEventCmd->AvailableForStates(G4State_EventProc);
217 
218  geomCmd = new G4UIcmdWithoutParameter("/run/geometryModified",this);
219  geomCmd->SetGuidance("Force geometry to be closed (re-voxellized) again.");
220  geomCmd->SetGuidance("This command must be applied if geometry has been modified");
221  geomCmd->SetGuidance(" after the first initialization (or BeamOn).");
223 
224  geomRebCmd = new G4UIcmdWithABool("/run/reinitializeGeometry",this);
225  geomRebCmd->SetGuidance("Force geometry to be rebuilt once again.");
226  geomRebCmd->SetGuidance("This command must be applied if the user needs his/her");
227  geomRebCmd->SetGuidance(" detector construction to be reinvoked.");
228  geomRebCmd->SetGuidance("/run/geometryModified is automatically issued with this command.");
229  geomRebCmd->SetParameterName("destroyFirst",true);
230  geomRebCmd->SetDefaultValue(false);
232 
233  physCmd = new G4UIcmdWithoutParameter("/run/physicsModified",this);
234  physCmd->SetGuidance("Force all physics tables recalculated again.");
235  physCmd->SetGuidance("This command must be applied");
236  physCmd->SetGuidance(" if physics process has been modified after the");
237  physCmd->SetGuidance(" first initialization (or BeamOn).");
239 
240  constScoreCmd = new G4UIcmdWithoutParameter("/run/constructScoringWorlds",this);
241  constScoreCmd->SetGuidance("Constrct scoring parallel world(s) if defined.");
242  constScoreCmd->SetGuidance("This command is not mandatory, but automatically called when a run starts.");
243  constScoreCmd->SetGuidance("But the user may use this to visualize the scoring world(s) before a run to start.");
244  constScoreCmd->AvailableForStates(G4State_Idle);
245 
246  materialScanner = new G4MaterialScanner();
247 
248  randomDirectory = new G4UIdirectory("/random/");
249  randomDirectory->SetGuidance("Random number status control commands.");
250 
251  seedCmd = new G4UIcmdWithAString("/random/setSeeds",this);
252  seedCmd->SetGuidance("Initialize the random number generator with integer seed stream.");
253  seedCmd->SetGuidance("Number of integers should be more than 1.");
254  seedCmd->SetGuidance("Actual number of integers to be used depends on the individual random number engine.");
255 #ifdef G4MULTITHREADED
256  seedCmd->SetGuidance("This command sets the seeds for the master thread.");
257 #endif
258  seedCmd->SetParameterName("IntArray",false);
260  seedCmd->SetToBeBroadcasted(false);
261 
262  randDirCmd = new G4UIcmdWithAString("/random/setDirectoryName",this);
263  randDirCmd->SetGuidance("Define the directory name of the rndm status files.");
264  randDirCmd->SetGuidance("Directory will be created if it does not exist.");
265  randDirCmd->SetParameterName("fileName",true);
266  randDirCmd->SetDefaultValue("./");
268 
269  savingFlagCmd = new G4UIcmdWithABool("/random/setSavingFlag",this);
270  savingFlagCmd->SetGuidance("The randomNumberStatus will be saved at :");
271  savingFlagCmd->SetGuidance("begining of run (currentRun.rndm) and "
272  "begining of event (currentEvent.rndm) ");
273  savingFlagCmd->SetParameterName("flag",true);
274  savingFlagCmd->SetDefaultValue(true);
275 
276  saveThisRunCmd = new G4UIcmdWithoutParameter("/random/saveThisRun",this);
277  saveThisRunCmd->SetGuidance("copy currentRun.rndm to runXXX.rndm");
279 
280  saveThisEventCmd = new G4UIcmdWithoutParameter("/random/saveThisEvent",this);
281  saveThisEventCmd->SetGuidance("copy currentEvent.rndm to runXXXevtYYY.rndm");
282  saveThisEventCmd->AvailableForStates(G4State_EventProc);
283 
284  restoreRandCmd = new G4UIcmdWithAString("/random/resetEngineFrom",this);
285  restoreRandCmd->SetGuidance("Reset the status of the rndm engine from a file.");
286  restoreRandCmd->SetGuidance("See CLHEP manual for detail.");
287  restoreRandCmd->SetGuidance("The engine status must be stored beforehand.");
288  restoreRandCmd->SetGuidance("Directory of the status file should be set by"
289  " /random/setDirectoryName.");
290  restoreRandCmd->SetParameterName("fileName",true);
291  restoreRandCmd->SetDefaultValue("currentRun.rndm");
293  restoreRandCmd->SetToBeBroadcasted(false);
294 
295  restoreRandCmdMT = new G4UIcmdWithABool("/random/resetEngineFromEachEvent",this);
296  restoreRandCmdMT->SetGuidance("Reset the status of the rndm engine from a file at each event.");
297  restoreRandCmdMT->SetGuidance("Note that the file must follow the following naming convention:");
298  restoreRandCmdMT->SetGuidance("run{#1}evt{#2}.rndm ; where #1 is the run number and #2 is the event number.");
299  restoreRandCmdMT->SetGuidance("For example to re-seed the first event of the first run the file should be called run0evt0.rndm.");
300  restoreRandCmdMT->SetGuidance("If for a specific run/event the file is not found, the standard re-seeding strategy is used.");
301  restoreRandCmdMT->SetGuidance("This command has meaning only in MT mode for strong reproducibility studies.");
302  restoreRandCmdMT->SetGuidance("Directory of the status file should be set by"
303  " /random/setDirectoryName.");
304  restoreRandCmdMT->SetDefaultValue(false);
306 
307 
308  saveEachEventCmd = new G4UIcmdWithABool("/random/saveEachEventFlag",this);
309  saveEachEventCmd->SetGuidance("Save random number status at beginning of each event.");
310  saveEachEventCmd->SetGuidance("File name contains run and event numbers: runXXXevtYYY.rndm");
311  saveEachEventCmd->SetParameterName("flag",true);
312  saveEachEventCmd->SetDefaultValue(true);
313 
314  randEvtCmd = new G4UIcmdWithAnInteger("/run/storeRndmStatToEvent",this);
315  randEvtCmd->SetGuidance("Flag to store rndm status to G4Event object.");
316  randEvtCmd->SetGuidance(" flag = 0 : not store (default)");
317  randEvtCmd->SetGuidance(" flag = 1 : status before primary particle generation is stored");
318  randEvtCmd->SetGuidance(" flag = 2 : status before event processing (after primary particle generation) is stored");
319  randEvtCmd->SetGuidance(" flag = 3 : both are stored");
320  randEvtCmd->SetGuidance("Note: Some performance overhead may be seen by storing rndm status, in particular");
321  randEvtCmd->SetGuidance("for the case of simplest geometry and small number of tracks per event.");
322  randEvtCmd->SetParameterName("flag",true);
323  randEvtCmd->SetDefaultValue(0);
324  randEvtCmd->SetRange("flag>=0 && flag<3");
326 
327  procUICmds = new G4UIcmdWithoutParameter("/run/workersProcessCmds",this);
328  procUICmds->SetToBeBroadcasted(false);
329  procUICmds->SetGuidance("Force workers to process current stack of UI commands.");
330  procUICmds->SetGuidance("This commands is meaningful only in MT mode.");
332 
333 }
334 
336 {
337  delete materialScanner;
338  delete beamOnCmd;
339  delete verboseCmd;
340  delete printProgCmd;
341  delete nThreadsCmd;
342  delete maxThreadsCmd;
343  delete pinAffinityCmd;
344  delete evModCmd;
345  delete optCmd;
346  delete dumpRegCmd;
347  delete dumpCoupleCmd;
348  delete brkBoECmd;
349  delete brkEoECmd;
350  delete abortCmd;
351  delete abortEventCmd;
352  delete initCmd;
353  delete geomCmd;
354  delete geomRebCmd;
355  delete physCmd;
356  delete randEvtCmd;
357  delete constScoreCmd;
358  delete procUICmds;
359 
360  delete seedCmd;
361  delete savingFlagCmd;
362  delete saveThisRunCmd;
363  delete saveThisEventCmd;
364  delete restoreRandCmd;
365  delete randomDirectory;
366  delete saveEachEventCmd;
367 
368  delete randDirCmd;
369  delete runDirectory;
370 
371  delete restoreRandCmdMT;
372 }
373 
375 {
376  if( command==beamOnCmd )
377  {
378  G4int nev;
379  G4int nst;
380  const char* nv = (const char*)newValue;
381  std::istringstream is(nv);
382  is >> nev >> macroFileName >> nst;
383  if(macroFileName=="***NULL***")
384  { runManager->BeamOn(nev); }
385  else
386  { runManager->BeamOn(nev,macroFileName,nst); }
387  }
388  else if( command==verboseCmd )
389  { runManager->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue)); }
390  else if( command == printProgCmd )
391  { runManager->SetPrintProgress(printProgCmd->GetNewIntValue(newValue)); }
392  else if( command==nThreadsCmd )
393  {
394  G4RunManager::RMType rmType = runManager->GetRunManagerType();
395  if( rmType==G4RunManager::masterRM )
396  {
397  static_cast<G4MTRunManager*>(runManager)->SetNumberOfThreads(
398  nThreadsCmd->GetNewIntValue(newValue));
399  }
400  else if ( rmType==G4RunManager::sequentialRM )
401  {
402  G4cout<<"*** /run/numberOfThreads command is issued in sequential mode."
403  <<"\nCommand is ignored."<<G4endl;
404  }
405  else
406  {
407  G4Exception("G4RunMessenger::ApplyNewCommand","Run0901",FatalException,
408  "/run/numberOfThreads command is issued to local thread.");
409  }
410  }
411  else if( command==maxThreadsCmd)
412  {
413  G4RunManager::RMType rmType = runManager->GetRunManagerType();
414  if( rmType==G4RunManager::masterRM )
415  {
416  static_cast<G4MTRunManager*>(runManager)->SetNumberOfThreads(
418  }
419  else if ( rmType==G4RunManager::sequentialRM )
420  {
421  G4cout<<"*** /run/useMaximumLogicalCores command is issued in sequential mode."
422  <<"\nCommand is ignored."<<G4endl;
423  }
424  else
425  {
426  G4Exception("G4RunMessenger::ApplyNewCommand","Run0901",FatalException,
427  "/run/useMaximumLogicalCores command is issued to local thread.");
428  }
429  }
430  else if ( command == pinAffinityCmd )
431  {
432  G4RunManager::RMType rmType = runManager->GetRunManagerType();
433  if( rmType==G4RunManager::masterRM )
434  {
435  static_cast<G4MTRunManager*>(runManager)->SetPinAffinity(
436  pinAffinityCmd->GetNewIntValue(newValue) );
437  }
438  else if ( rmType==G4RunManager::sequentialRM )
439  {
440  G4cout<<"*** /run/pinAffinity command is issued in sequential mode."
441  <<"\nCommand is ignored."<<G4endl;
442  }
443  else
444  {
445  G4Exception("G4RunMessenger::ApplyNewCommand","Run0901",FatalException,
446  "/run/pinAffinity command is issued to local thread.");
447  }
448 
449  }
450  else if( command==evModCmd)
451  {
452  G4RunManager::RMType rmType = runManager->GetRunManagerType();
453  if( rmType==G4RunManager::masterRM )
454  {
455  G4int nevMod = 0;
456  G4int sOnce = 0;
457  const char* nv = (const char*)newValue;
458  std::istringstream is(nv);
459  is >> nevMod >> sOnce;
460  static_cast<G4MTRunManager*>(runManager)->SetEventModulo(nevMod);
462  }
463  else if ( rmType==G4RunManager::sequentialRM )
464  {
465  G4cout<<"*** /run/eventModulo command is issued in sequential mode."
466  <<"\nCommand is ignored."<<G4endl;
467  }
468  else
469  {
470  G4Exception("G4RunMessenger::ApplyNewCommand","Run0902",FatalException,
471  "/run/eventModulo command is issued to local thread.");
472  }
473  }
474  else if( command==dumpRegCmd )
475  {
476  if(newValue=="**ALL**")
477  { runManager->DumpRegion(); }
478  else
479  { runManager->DumpRegion(newValue); }
480  }
481  else if( command==dumpCoupleCmd)
482  {
484  }
485  else if( command==optCmd )
486  { runManager->SetGeometryToBeOptimized(optCmd->GetNewBoolValue(newValue)); }
487  else if( command==brkBoECmd )
489  else if( command==brkEoECmd )
491  else if( command==abortCmd )
492  { runManager->AbortRun(abortCmd->GetNewBoolValue(newValue)); }
493  else if( command==abortEventCmd )
494  { runManager->AbortEvent(); }
495  else if( command==initCmd )
496  { runManager->Initialize(); }
497  else if( command==geomCmd )
498  { runManager->GeometryHasBeenModified(false); }
499  else if( command==geomRebCmd )
500  { runManager->ReinitializeGeometry(geomRebCmd->GetNewBoolValue(newValue),false); }
501  else if( command==physCmd )
502  { runManager->PhysicsHasBeenModified(); }
503  else if( command==seedCmd )
504  {
505  G4Tokenizer next(newValue);
506  G4int idx=0;
507  long seeds[100];
508  G4String vl;
509  while(!(vl=next()).isNull())
510  { seeds[idx] = (long)(StoI(vl)); idx++; }
511  if(idx<2)
512  { G4cerr << "/random/setSeeds should have at least two integers. Command ignored." << G4endl; }
513  else
514  {
515  seeds[idx] = 0;
516  G4Random::setTheSeeds(seeds);
517  }
518  }
519  else if( command==randDirCmd )
520  { runManager->SetRandomNumberStoreDir(newValue); }
521  else if( command==savingFlagCmd )
522  { runManager->SetRandomNumberStore(savingFlagCmd->GetNewBoolValue(newValue)); }
523  else if( command==saveThisRunCmd )
524  { runManager->rndmSaveThisRun(); }
525  else if( command==saveThisEventCmd )
526  { runManager->rndmSaveThisEvent(); }
527  else if( command==restoreRandCmd )
528  { runManager->RestoreRandomNumberStatus(newValue); }
529  else if( command==randEvtCmd )
530  { runManager->StoreRandomNumberStatusToG4Event(randEvtCmd->GetNewIntValue(newValue)); }
531  else if( command==saveEachEventCmd)
532  { runManager->SetRandomNumberStorePerEvent(saveEachEventCmd->GetNewBoolValue(newValue)); }
533  else if( command==constScoreCmd )
534  { runManager->ConstructScoringWorlds(); }
535  else if( command==restoreRandCmdMT)
536  { runManager->RestoreRndmEachEvent(restoreRandCmdMT->GetNewBoolValue(newValue)); }
537  else if ( command==procUICmds)
538  {
539  G4RunManager::RMType rmType = runManager->GetRunManagerType();
540  if( rmType==G4RunManager::masterRM ) {
541  auto rm = dynamic_cast<G4MTRunManager*>(runManager);
542  if ( rm != nullptr ) {
544  }
545  else { G4Exception("G4RunManager::ApplyNewCommand","Run0128",FatalException,"/run/workersProcessCmds command issued on a non-G4MTRunManager class instance."); }
546  } else if ( rmType==G4RunManager::sequentialRM ) {
547  G4cout<<"*** /run/workersProcessCmds command is issued in sequential mode."
548  <<"\nCommand is ignored."<<G4endl;
549  } else {
550  G4Exception("G4RunMessenger::ApplyNewCommand","Run0129",FatalException,
551  "/run/workersProcessCmds command is issued to local thread.");
552  }
553  }
554 
555 }
556 
558 {
559  G4String cv;
560 
561  if( command==verboseCmd )
562  { cv = verboseCmd->ConvertToString(runManager->GetVerboseLevel()); }
563  else if( command == printProgCmd )
564  { cv = printProgCmd->ConvertToString(runManager->GetPrintProgress()); }
565  else if( command==randDirCmd )
566  { cv = runManager->GetRandomNumberStoreDir(); }
567  else if( command==randEvtCmd )
568  { cv = randEvtCmd->ConvertToString(runManager->GetFlagRandomNumberStatusToG4Event()); }
569  else if( command==nThreadsCmd )
570  {
571  G4RunManager::RMType rmType = runManager->GetRunManagerType();
572  if( rmType==G4RunManager::masterRM )
573  {
574  cv = nThreadsCmd->ConvertToString(
575  static_cast<G4MTRunManager*>(runManager)->GetNumberOfThreads());
576  }
577  else if ( rmType==G4RunManager::sequentialRM )
578  {
579  cv = "0";
580  }
581  }
582  else if( command==evModCmd)
583  {
584  G4RunManager::RMType rmType = runManager->GetRunManagerType();
585  if( rmType==G4RunManager::masterRM )
586  {
587  cv = evModCmd->ConvertToString(
588  static_cast<G4MTRunManager*>(runManager)->GetEventModulo() )
590  }
591  else if ( rmType==G4RunManager::sequentialRM )
592  { G4cout<<"*** /run/eventModulo command is valid only in MT mode."<<G4endl; }
593  }
594 
595  return cv;
596 }
597 
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void GeometryHasBeenModified(G4bool prop=true)
G4int GetVerboseLevel() const
virtual void AbortRun(G4bool softAbort=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
G4int GetPrintProgress()
G4RunMessenger(G4RunManager *runMgr)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
const G4String & GetRandomNumberStoreDir() const
void SetVerboseLevel(G4int vl)
static G4int GetNewIntValue(const char *paramString)
void SetParameterRange(const char *theRange)
void SetPrintProgress(G4int i)
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:372
void SetRandomNumberStorePerEvent(G4bool flag)
virtual void BeamOn(G4int n_event, const char *macroFile=0, G4int n_select=-1)
void SetRandomNumberStore(G4bool flag)
G4int GetFlagRandomNumberStatusToG4Event() const
G4String GetCurrentValue(G4UIcommand *command)
int G4int
Definition: G4Types.hh:78
static G4bool GetNewBoolValue(const char *paramString)
void SetDefaultValue(G4bool defVal)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
virtual void RestoreRandomNumberStatus(const G4String &fileN)
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
virtual void ConstructScoringWorlds()
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:143
virtual void rndmSaveThisEvent()
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:240
virtual void RequestWorkersProcessCommandsStack()
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
void SetNewValue(G4UIcommand *command, G4String newValues)
static G4ProductionCutsTable * GetProductionCutsTable()
void SetDefaultValue(const char *defVal)
void SetPauseAtEndOfEvent(G4bool vl)
Definition: G4UImanager.hh:196
virtual void RestoreRndmEachEvent(G4bool)
static G4int SeedOncePerCommunication()
void SetPauseAtBeginOfEvent(G4bool vl)
Definition: G4UImanager.hh:192
virtual void Initialize()
#define G4endl
Definition: G4ios.hh:61
virtual void AbortEvent()
void SetDefaultValue(G4int defVal)
void SetRandomNumberStoreDir(const G4String &dir)
static void SetSeedOncePerCommunication(G4int val)
void DumpRegion(const G4String &rname) const
G4GLOB_DLL std::ostream G4cerr