Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes
G4VMPIsession Class Reference

#include <G4VMPIsession.hh>

Inheritance diagram for G4VMPIsession:
G4VBasicShell G4UIsession G4coutDestination G4MPIbatch G4MPIsession

Public Member Functions

 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 ()
 
virtual G4UIsessionSessionStart ()=0
 
- Public Member Functions inherited from G4UIsession
 G4UIsession ()
 
virtual ~G4UIsession ()
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()
 
virtual ~G4coutDestination ()
 

Protected Member Functions

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

G4MPImanagerg4mpi_
 
G4bool is_master_
 
G4bool is_slave_
 
G4int rank_
 

Detailed Description

Definition at line 38 of file G4VMPIsession.hh.

Constructor & Destructor Documentation

G4VMPIsession::G4VMPIsession ( )

Definition at line 35 of file G4VMPIsession.cc.

References g4mpi_, G4MPImanager::GetManager(), is_master_, is_slave_, and rank_.

36  : G4VBasicShell()
37 {
39 
40  is_master_ = g4mpi_-> IsMaster();
41  is_slave_ = g4mpi_-> IsSlave();
42  rank_ = g4mpi_-> GetRank();
43 }
G4MPImanager * g4mpi_
static G4MPImanager * GetManager()
G4VMPIsession::~G4VMPIsession ( )

Definition at line 46 of file G4VMPIsession.cc.

47 {
48 }

Member Function Documentation

G4String G4VMPIsession::BypassCommand ( const G4String command) const
protected

Definition at line 172 of file G4VMPIsession.cc.

References G4cout, G4endl, g4mpi_, is_master_, and G4String::replace().

Referenced by ExecCommand(), and G4MPIbatch::ReadCommand().

173 {
174  // bypass some commands
175  // * /mpi/beamOn
176  // -> /mpi/.beamOn (batch session)
177  // -> /mpi/.beamOn (MT mode)
178  //
179  // * /run/beamOn
180  // -> /mpi/.beamOn (batch session)
181  // -> /mpi/beamOn (interactive session)
182  // -> /mpi/.beamOn (MT mode)
183  //
184  // * /control/execute -> /mpi/execute
185 
186  G4String acommand = command;
187 
188  // /mpi/beamOn
189  if( acommand(0,11) == "/mpi/beamOn" ) {
190 #ifdef G4MULTITHREADED
191  acommand = "/mpi/.beamOn";
192  if(command.length() > 11) {
193  acommand += command.substr(11);
194  }
195 #else
196  if( g4mpi_-> IsBatchMode()) {
197  acommand = "/mpi/.beamOn";
198  if(command.length() > 11) {
199  acommand += command.substr(11);
200  }
201  }
202 #endif
203  }
204 
205  // /run/beamOn
206  if( acommand(0,11) == "/run/beamOn" ) {
207  G4String strarg = "";
208  G4bool qget = false;
209  G4bool qdone = false;
210 
211  for ( str_size idx = 10; idx < command.size(); idx++ ) {
212  if( command[idx] == ' ' || command[idx] == '\011' ) {
213  qget = true;
214  if(qdone) break;
215  continue;
216  }
217  if( qget ) {
218  strarg += command[idx];
219  qdone = true;
220  }
221  }
222 
223  if( g4mpi_-> IsBatchMode() ) { // batch session
224  acommand = "/mpi/.beamOn ";
225  if( command.length() > 11 ) acommand += strarg;
226  } else { // interactive session
227 #ifdef G4MULTITHREADED
228  if( g4mpi_-> GetVerbose()>0 && is_master_ ) {
229  G4cout << "/run/beamOn is overridden by /mpi/.beamOn" << G4endl;
230  }
231  acommand = "/mpi/.beamOn ";
232  if( command.length() > 11 ) acommand += strarg;
233 #else
234  if( g4mpi_-> GetVerbose()>0 && is_master_ ) {
235  G4cout << "/run/beamOn is overridden by /mpi/beamOn" << G4endl;
236  }
237  acommand = "/mpi/beamOn ";
238  if( command.length() > 11 ) acommand += strarg;
239 #endif
240  }
241  }
242 
243  // /control/execute
244  if( acommand(0,16) == "/control/execute" ) {
245  if( g4mpi_-> GetVerbose()>0 && is_master_ ) {
246  G4cout << "/control/execute is overridden by /mpi/execute"
247  << G4endl;
248  }
249  acommand.replace(0, 16, "/mpi/execute ");
250  }
251 
252  return acommand;
253 }
std::string::size_type str_size
G4MPImanager * g4mpi_
G4String & replace(unsigned int, unsigned int, const char *, unsigned int)
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
#define G4endl
Definition: G4ios.hh:61
G4int G4VMPIsession::ExecCommand ( const G4String acommand)
protected

Definition at line 75 of file G4VMPIsession.cc.

References BypassCommand(), cmd, fAliasNotFound, fCommandNotFound, fCommandSucceeded, fIllegalApplicationState, G4VBasicShell::FindCommand(), fParameterOutOfCandidates, fParameterOutOfRange, fParameterUnreadable, G4cerr, G4cout, G4endl, g4mpi_, G4UIcommand::GetParameter(), G4UImanager::GetUIpointer(), and is_master_.

Referenced by G4MPIbatch::SessionStart(), and G4MPIsession::SessionStart().

76 {
77  if( acommand.length() < 2 ) return fCommandSucceeded;
78 
80  G4int returnVal = 0;
81 
82  G4String command = BypassCommand(acommand);
83 
84  // "/mpi/beamOn is threaded out.
85  if( command(0,11) == "/mpi/beamOn" ) {
86  g4mpi_-> ExecuteBeamOnThread(command);
87  returnVal = fCommandSucceeded;
88  } else if( command(0,12) == "/mpi/.beamOn" ) { // care for beamOn
89  G4bool threadStatus = g4mpi_-> CheckThreadStatus();
90  if ( threadStatus ) { // still /run/beamOn is active
91  if( is_master_ ) {
92  G4cout << "G4MPIsession:: beamOn is still running." << G4endl;
93  }
94  returnVal = fCommandSucceeded;
95  } else {
96  returnVal = UI-> ApplyCommand(command);
97  }
98  } else { // normal command
99  returnVal = UI-> ApplyCommand(command);
100  }
101 
102  G4int paramIndex = returnVal % 100;
103  // 0 - 98 : paramIndex-th parameter is invalid
104  // 99 : convination of parameters is invalid
105  G4int commandStatus = returnVal - paramIndex;
106 
107  G4UIcommand* cmd = 0;
108  if( commandStatus != fCommandSucceeded ) {
109  cmd = FindCommand(command);
110  }
111 
112  switch( commandStatus ) {
113  case fCommandSucceeded:
114  break;
115  case fCommandNotFound:
116  G4cerr << "command <" << UI-> SolveAlias(command)
117  << "> not found" << G4endl;
118  break;
120  G4cerr << "illegal application state -- command refused" << G4endl;
121  break;
123  // ...
124  break;
126  G4cerr << "Parameter is out of candidate list (index "
127  << paramIndex << ")" << G4endl;
128  G4cerr << "Candidates : "
129  << cmd->GetParameter(paramIndex)-> GetParameterCandidates()
130  << G4endl;
131  break;
133  G4cerr << "Parameter is wrong type and/or is not omittable (index "
134  << paramIndex << ")" << G4endl;
135  break;
136  case fAliasNotFound:
137  // ...
138  break;
139  default:
140  G4cerr << "command refused (" << commandStatus << ")" << G4endl;
141  }
142 
143  return returnVal;
144 }
char cmd[1024]
Definition: tracer.cxx:25
G4MPImanager * g4mpi_
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4String BypassCommand(const G4String &command) const
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:145
#define G4endl
Definition: G4ios.hh:61
G4UIcommand * FindCommand(const char *commandName) const
G4GLOB_DLL std::ostream G4cerr
void G4VMPIsession::ExitHelp ( ) const
protectedvirtual

Implements G4VBasicShell.

Definition at line 63 of file G4VMPIsession.cc.

References G4cin.

64 {
65  char temp[100];
66  G4cin.getline(temp, 100);
67 }
#define G4cin
Definition: G4ios.hh:60
G4bool G4VMPIsession::GetHelpChoice ( G4int aval)
protectedvirtual

Implements G4VBasicShell.

Definition at line 51 of file G4VMPIsession.cc.

References G4cin.

52 {
53  G4cin >> aval;
54  if( !G4cin.good() ){
55  G4cin.clear();
56  G4cin.ignore(30,'\n');
57  return false;
58  }
59  return true;
60 }
#define G4cin
Definition: G4ios.hh:60
void G4VMPIsession::PauseSessionStart ( const G4String msg)
virtual

Implements G4VBasicShell.

Definition at line 70 of file G4VMPIsession.cc.

71 {
72 }
G4int G4VMPIsession::ReceiveG4cerr ( const G4String cerrString)
virtual

Reimplemented from G4UIsession.

Definition at line 263 of file G4VMPIsession.cc.

References g4mpi_, and pyG4Element::Print().

264 {
265  g4mpi_-> Print(cerrString);
266  return 0;
267 }
G4MPImanager * g4mpi_
void Print(G4Element &ele)
Definition: pyG4Element.cc:56
G4int G4VMPIsession::ReceiveG4cout ( const G4String coutString)
virtual

Reimplemented from G4UIsession.

Definition at line 256 of file G4VMPIsession.cc.

References g4mpi_, and pyG4Element::Print().

257 {
258  g4mpi_-> Print(coutString);
259  return 0;
260 }
G4MPImanager * g4mpi_
void Print(G4Element &ele)
Definition: pyG4Element.cc:56
G4String G4VMPIsession::TruncateCommand ( const G4String command) const
protected

Definition at line 147 of file G4VMPIsession.cc.

148 {
149  // replace "//" with "/" in G4command
150  G4String acommand = command;
151  G4String strarg;
152 
153  str_size iarg = acommand.find(' ');
154  if( iarg != G4String::npos ) {
155  strarg = acommand(iarg, acommand.size()-iarg);
156  acommand = acommand(0,iarg);
157  }
158 
159  str_size idx;
160  while( (idx = acommand.find("//")) != G4String::npos) {
161  G4String command1 = acommand(0,idx+1);
162  G4String command2 = acommand(idx+2, acommand.size()-idx-2);
163  acommand = command1 + command2;
164  }
165 
166  acommand += strarg;
167 
168  return acommand;
169 }
std::string::size_type str_size

Field Documentation

G4MPImanager* G4VMPIsession::g4mpi_
protected
G4bool G4VMPIsession::is_master_
protected
G4bool G4VMPIsession::is_slave_
protected

Definition at line 53 of file G4VMPIsession.hh.

Referenced by G4VMPIsession().

G4int G4VMPIsession::rank_
protected

Definition at line 54 of file G4VMPIsession.hh.

Referenced by G4VMPIsession().


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