Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
G4MPIsession Class Reference

#include <Doxymodules_parallel.h>

Inheritance diagram for G4MPIsession:
G4VMPIsession G4VBasicShell G4UIsession G4coutDestination

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)
 

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 Attributes inherited from G4VMPIsession
G4MPImanagerg4mpi_
 
G4bool is_master_
 
G4bool is_slave_
 
G4int rank_
 

Detailed Description

Definition at line 68 of file Doxymodules_parallel.h.

Constructor & Destructor Documentation

◆ G4MPIsession()

G4MPIsession::G4MPIsession ( G4VUIshell ashell = 0)

Definition at line 52 of file G4MPIsession.cc.

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_-> GetTotalSize() == 1 && ::tcsh_build ) shell_ = new G4UItcsh;
64 else shell_ = new G4UIcsh;
65 }
66 } else {
67 shell_ = new G4UImpish;
68 }
69}
G4VUIshell * shell_
G4MPImanager * g4mpi_

◆ ~G4MPIsession()

G4MPIsession::~G4MPIsession ( )

Definition at line 72 of file G4MPIsession.cc.

73{
74 delete shell_;
75
76 ::UI = G4UImanager::GetUIpointer();
77 ::UI-> SetSession(0);
78 ::UI-> SetCoutDestination(0);
79}

Member Function Documentation

◆ 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)

◆ SetShell()

void G4MPIsession::SetShell ( G4VUIshell ashell)

Definition at line 88 of file G4MPIsession.cc.

89{
90 delete shell_;
91 shell_ = ashell;
92}

◆ SessionStart()

G4UIsession * G4MPIsession::SessionStart ( )
virtual

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}
const G4String & GetMacroFileName() const
const G4String & GetInitFileName() const
G4bool TryForcedTerminate()
G4String GetCommand(const char *msg=0)
G4int ExecCommand(const G4String &acommand)

◆ 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= G4StrUtil::lstrip_copy(newCommand);
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.substr(0,3) == "ls " ) { // list commands
112 ListDirectory(nC);
113 newCommand = nullString;
114
115 } else if( nC == "lc" || nC.substr(0,3) == "lc " ) { // ... by shell
116 shell_-> ListCommand(nC.erase(0,2));
117 newCommand = nullString;
118
119 } else if( nC == "pwd" ) { // show current directory
120 G4cout << "Current Command Directory : "
121 << GetCurrentWorkingDirectory() << G4endl;
122 newCommand = nullString;
123
124 } else if( nC == "cwd" ) { // ... by shell
125 shell_-> ShowCurrentDirectory();
126 newCommand = nullString;
127
128 } else if(nC == "cd" || nC.substr(0,3) == "cd " ) { // "cd"
129 ChangeDirectoryCommand(nC);
130 shell_-> SetCurrentDirectory(GetCurrentWorkingDirectory());
131 newCommand = nullString;
132
133 } else if( nC == "help" || nC.substr(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.substr(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
G4String lstrip_copy(G4String str, char ch=' ')

◆ 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") {
242 G4RunManager* runManager = G4RunManager::GetRunManager();
243 runManager-> AbortRun(true); // soft abort
244 }
245
246 return false;
247}

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:

Applications | User Support | Publications | Collaboration