Geant4  10.02.p03
G4MPIsession Class Reference

#include <G4MPIsession.hh>

Inheritance diagram for G4MPIsession:
Collaboration diagram for G4MPIsession:

Public Member Functions

 G4MPIsession (G4VUIshell *ashell=0)
 
 ~G4MPIsession ()
 
void SetPrompt (const G4String &prompt)
 
void SetShell (G4VUIshell *ashell)
 
virtual G4UIsessionSessionStart ()
 
- Public Member Functions inherited from G4VMPIsession
 G4VMPIsession ()
 
 ~G4VMPIsession ()
 
virtual void PauseSessionStart (const G4String &msg)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 
- Public Member Functions inherited from G4VBasicShell
 G4VBasicShell ()
 
virtual ~G4VBasicShell ()
 
- Public Member Functions inherited from G4UIsession
 G4UIsession ()
 
virtual ~G4UIsession ()
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()
 
virtual ~G4coutDestination ()
 

Private Member Functions

G4String GetCommand (const char *msg=0)
 
G4bool TryForcedTerminate ()
 

Private Attributes

G4VUIshellshell_
 

Additional Inherited Members

- Protected Member Functions inherited from G4VMPIsession
G4int ExecCommand (const G4String &acommand)
 
G4String TruncateCommand (const G4String &command) const
 
G4String BypassCommand (const G4String &command) const
 
virtual G4bool GetHelpChoice (G4int &aval)
 
virtual void ExitHelp () const
 
- Protected Member Functions inherited from G4VBasicShell
G4String ModifyToFullPathCommand (const char *aCommandLine) const
 
G4String GetCurrentWorkingDirectory () const
 
G4bool ChangeDirectory (const char *newDir)
 
G4UIcommandTreeFindDirectory (const char *dirName) const
 
G4UIcommandFindCommand (const char *commandName) const
 
G4String Complete (const G4String &)
 
G4String FindMatchingPath (G4UIcommandTree *, const G4String &)
 
virtual void ExecuteCommand (const G4String &)
 
void ApplyShellCommand (const G4String &, G4bool &, G4bool &)
 
void ShowCurrent (const G4String &) const
 
void ChangeDirectoryCommand (const G4String &)
 
void ListDirectory (const G4String &) const
 
void TerminalHelp (const G4String &)
 
- Protected Attributes inherited from G4VMPIsession
G4MPImanagerg4mpi_
 
G4bool is_master_
 
G4bool is_slave_
 
G4int rank_
 
- Static Protected Attributes inherited from G4coutDestination
static G4coutDestinationmasterG4coutDestination = 0
 

Detailed Description

Definition at line 33 of file G4MPIsession.hh.

Constructor & Destructor Documentation

◆ G4MPIsession()

G4MPIsession::G4MPIsession ( G4VUIshell ashell = 0)

Definition at line 52 of file G4MPIsession.cc.

53  : G4VMPIsession()
54 {
55  ::UI-> SetSession(this);
56  ::UI-> SetCoutDestination(this);
57 
58  // shell
59  if( is_master_ ) {
60  if( ashell ) {
61  shell_ = ashell;
62  } else {
63  if ( g4mpi_-> GetSize() == 1 && ::tcsh_build ) shell_ = new G4UItcsh;
64  else shell_ = new G4UIcsh;
65  }
66  } else {
67  shell_ = new G4UImpish;
68  }
69 }
G4MPImanager * g4mpi_
static const G4bool tcsh_build
G4VUIshell * shell_
Definition: G4MPIsession.hh:44

◆ ~G4MPIsession()

G4MPIsession::~G4MPIsession ( )

Definition at line 72 of file G4MPIsession.cc.

73 {
74  delete shell_;
75 
77  ::UI-> SetSession(0);
78  ::UI-> SetCoutDestination(0);
79 }
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4VUIshell * shell_
Definition: G4MPIsession.hh:44
Here is the call graph for this function:

Member Function Documentation

◆ GetCommand()

G4String G4MPIsession::GetCommand ( const char *  msg = 0)
private

Definition at line 95 of file G4MPIsession.cc.

96 {
97  G4String newCommand;
98  const G4String nullString = "";
99 
100  // get command from shell...
101  newCommand = shell_-> GetCommandLineString(msg);
102 
103  G4String nC= newCommand.strip(G4String::leading);
104  if( nC.length() == 0 ) {
105  newCommand = nullString;
106 
107  } else if( nC(0) == '#' ) {
108  G4cout << nC << G4endl;
109  newCommand = nullString;
110 
111  } else if( nC == "ls" || nC(0,3) == "ls " ) { // list commands
112  ListDirectory(nC);
113  newCommand = nullString;
114 
115  } else if( nC == "lc" || nC(0,3) == "lc " ) { // ... by shell
116  shell_-> ListCommand(nC.remove(0,2));
117  newCommand = nullString;
118 
119  } else if( nC == "pwd" ) { // show current directory
120  G4cout << "Current Command Directory : "
122  newCommand = nullString;
123 
124  } else if( nC == "cwd" ) { // ... by shell
125  shell_-> ShowCurrentDirectory();
126  newCommand = nullString;
127 
128  } else if(nC == "cd" || nC(0,3) == "cd " ) { // "cd"
130  shell_-> SetCurrentDirectory(GetCurrentWorkingDirectory());
131  newCommand = nullString;
132 
133  } else if( nC == "help" || nC(0,5) == "help " ) { // "help"
134  TerminalHelp(nC);
135  newCommand = nullString;
136 
137  } else if( nC(0) == '?' ) { // "show current value of a parameter"
138  ShowCurrent(nC);
139  newCommand = nullString;
140 
141  } else if( nC == "hist" || nC == "history" ) { // "hist/history"
142  G4int nh= ::UI-> GetNumberOfHistory();
143  for( G4int i = 0; i<nh; i++ ) {
144  G4cout << i << ": " << ::UI-> GetPreviousCommand(i) << G4endl;
145  }
146  newCommand = nullString;
147 
148  } else if( nC(0) == '!' ) { // "!"
149  G4String ss = nC(1, nC.length()-1);
150  G4int vl;
151  const char* tt = ss;
152  std::istringstream is(tt);
153  is >> vl;
154  G4int nh = ::UI-> GetNumberOfHistory();
155  if( vl>=0 && vl<nh ) {
156  newCommand = ::UI-> GetPreviousCommand(vl);
157  G4cout << newCommand << G4endl;
158  } else {
159  G4cerr << "history " << vl << " is not found." << G4endl;
160  newCommand = nullString;
161  }
162 
163  } else if( nC.empty() ) { // NULL command
164  newCommand = nullString;
165 
166  } else if( nC == "exit" ) { // "exit"
167  return "exit";
168 
169  } else { // ...
170 
171  }
172 
173  newCommand = TruncateCommand(newCommand);
174  return ModifyToFullPathCommand(newCommand);
175 }
G4String TruncateCommand(const G4String &command) const
void ChangeDirectoryCommand(const G4String &)
void TerminalHelp(const G4String &)
G4String & remove(str_size)
G4String strip(G4int strip_Type=trailing, char c=' ')
void ShowCurrent(const G4String &) const
int G4int
Definition: G4Types.hh:78
G4String GetCurrentWorkingDirectory() const
G4GLOB_DLL std::ostream G4cout
G4String ModifyToFullPathCommand(const char *aCommandLine) const
#define G4endl
Definition: G4ios.hh:61
G4VUIshell * shell_
Definition: G4MPIsession.hh:44
void ListDirectory(const G4String &) const
G4GLOB_DLL std::ostream G4cerr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SessionStart()

G4UIsession * G4MPIsession::SessionStart ( )
virtual

Implements G4VBasicShell.

Definition at line 178 of file G4MPIsession.cc.

179 {
180  // execute init macro
181  if( g4mpi_-> IsInitMacro() ) {
182  g4mpi_-> ExecuteMacroFile(g4mpi_->GetInitFileName());
183  }
184 
185  // batch mode
186  if( g4mpi_-> IsBatchMode() ) {
187  g4mpi_-> ExecuteMacroFile(g4mpi_->GetMacroFileName(), true);
188  return NULL;
189  }
190 
191  // interactive session
192  G4String newCommand = "", scommand; // newCommand is always "" in slaves
193 
194  while(1) {
195  if( is_master_ ) newCommand = GetCommand();
196  // broadcast a new G4 command
197  scommand = g4mpi_-> BcastCommand(newCommand);
198  if( scommand == "exit" ) {
199  G4bool qexit = TryForcedTerminate();
200  if( qexit ) break;
201  else scommand = "";
202  }
203  ExecCommand(scommand);
204  }
205 
206  return NULL;
207 }
G4MPImanager * g4mpi_
G4bool TryForcedTerminate()
bool G4bool
Definition: G4Types.hh:79
const G4String & GetMacroFileName() const
const G4String & GetInitFileName() const
G4int ExecCommand(const G4String &acommand)
G4String GetCommand(const char *msg=0)
Definition: G4MPIsession.cc:95
Here is the call graph for this function:

◆ SetPrompt()

void G4MPIsession::SetPrompt ( const G4String prompt)

Definition at line 82 of file G4MPIsession.cc.

83 {
84  shell_-> SetPrompt(prompt);
85 }
void SetPrompt(const G4String &prompt)
Definition: G4MPIsession.cc:82
G4VUIshell * shell_
Definition: G4MPIsession.hh:44

◆ SetShell()

void G4MPIsession::SetShell ( G4VUIshell ashell)

Definition at line 88 of file G4MPIsession.cc.

89 {
90  delete shell_;
91  shell_ = ashell;
92 }
G4VUIshell * shell_
Definition: G4MPIsession.hh:44

◆ TryForcedTerminate()

G4bool G4MPIsession::TryForcedTerminate ( )
private

Definition at line 210 of file G4MPIsession.cc.

211 {
212  if(! g4mpi_-> CheckThreadStatus()) {
213  return true;
214  }
215 
216  G4String xmessage;
217 
218  // beamOn is still running
219  if( is_master_ ) {
220  char c[1024];
221  while(1) {
222  G4cout << "Run is still running. Do you abort a run? [y/N]:"
223  << std::flush;
224  G4cin.getline(c,1024);
225  G4String yesno= c;
226  if(yesno == "y" || yesno == "Y" ||
227  yesno == "n" || yesno == "N" || yesno == "") {
228  break;
229  }
230  }
231  if(c[0] == 'y' || c[0] == 'Y') {
232  G4cout << "Aborting a run..." << G4endl;
233  xmessage = g4mpi_-> BcastCommand("kill me");
234  } else {
235  xmessage = g4mpi_-> BcastCommand("alive");
236  }
237  } else {
238  xmessage = g4mpi_-> BcastCommand("");
239  }
240 
241  if(xmessage == "kill me") {
243  runManager-> AbortRun(true); // soft abort
244  }
245 
246  return false;
247 }
G4MPImanager * g4mpi_
#define G4cin
Definition: G4ios.hh:60
G4GLOB_DLL std::ostream G4cout
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ shell_

G4VUIshell* G4MPIsession::shell_
private

Definition at line 44 of file G4MPIsession.hh.


The documentation for this class was generated from the following files: