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

#include <G4MPIbatch.hh>

Inheritance diagram for G4MPIbatch:
G4VMPIsession G4VBasicShell G4UIsession G4coutDestination

Public Member Functions

 G4MPIbatch (const G4String &fname="", G4bool qbatch=false)
 
 ~G4MPIbatch ()
 
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 ()
 

Protected Member Functions

G4String ReadCommand ()
 
- 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

std::ifstream batch_stream_
 
G4bool is_opened_
 
G4bool is_batch_mode_
 
- Protected Attributes inherited from G4VMPIsession
G4MPImanagerg4mpi_
 
G4bool is_master_
 
G4bool is_slave_
 
G4int rank_
 

Detailed Description

Definition at line 34 of file G4MPIbatch.hh.

Constructor & Destructor Documentation

G4MPIbatch::G4MPIbatch ( const G4String fname = "",
G4bool  qbatch = false 
)

Definition at line 64 of file G4MPIbatch.cc.

References batch_stream_, G4cerr, G4endl, G4VMPIsession::is_master_, and is_opened_.

65  : G4VMPIsession(), is_opened_(false), is_batch_mode_(qbatch)
66 {
67  if( is_master_ ) {
68  batch_stream_.open(fname, std::ios::in);
69  if(batch_stream_.fail()) {
70  G4cerr << "cannot open a macro file(" << fname << ")."
71  << G4endl;
72  } else {
73  is_opened_ = true;
74  }
75  }
76 }
G4bool is_batch_mode_
Definition: G4MPIbatch.hh:44
std::ifstream batch_stream_
Definition: G4MPIbatch.hh:42
#define G4endl
Definition: G4ios.hh:61
G4bool is_opened_
Definition: G4MPIbatch.hh:43
G4GLOB_DLL std::ostream G4cerr
G4MPIbatch::~G4MPIbatch ( )

Definition at line 79 of file G4MPIbatch.cc.

References batch_stream_, and is_opened_.

80 {
81  if( is_opened_ ) batch_stream_.close();
82 }
std::ifstream batch_stream_
Definition: G4MPIbatch.hh:42
G4bool is_opened_
Definition: G4MPIbatch.hh:43

Member Function Documentation

G4String G4MPIbatch::ReadCommand ( )
protected

Definition at line 85 of file G4MPIbatch.cc.

References batch_stream_, G4String::both, BUFSIZE, G4VMPIsession::BypassCommand(), G4Exception(), JustWarning, G4String::replace(), and G4String::strip().

Referenced by SessionStart().

86 {
87  enum { BUFSIZE = 4096 };
88  static char linebuf[BUFSIZE];
89 
90  G4String cmdtotal = "";
91  G4bool qcontinued = false;
92  while( batch_stream_.good() ) {
93  batch_stream_.getline(linebuf, BUFSIZE);
94 
95  G4String cmdline(linebuf);
96 
97  // TAB-> ' ' conversion
98  str_size nb = 0;
99  while ((nb= cmdline.find('\t',nb)) != G4String::npos) {
100  cmdline.replace(nb, 1, " ");
101  }
102 
103  // strip
104  cmdline = cmdline.strip(G4String::both);
105 
106  // skip null line if single line
107  if( !qcontinued && cmdline.size() == 0 ) continue;
108 
109  // '#' is treated as echoing something
110  if( cmdline(0) == '#' ) return cmdline;
111 
112  // tokenize...
113  std::vector<G4String> tokens;
114  Tokenize(cmdline, tokens);
115  qcontinued = false;
116  for( G4int i = 0; i < G4int(tokens.size()); i++ ) {
117  // string after '#" is ignored
118  if( tokens[i](0) == '#' ) break;
119  // '\' or '_' is treated as continued line.
120  if( tokens[i] == '\\' || tokens[i] == '_' ) {
121  qcontinued = true;
122  // check nothing after line continuation character
123  if( i != G4int(tokens.size())-1 ) {
124  G4Exception("G4MPIbatch::ReadCommand", "MPI004", JustWarning,
125  "unexpected character after line continuation character");
126  }
127  break; // stop parsing
128  }
129  cmdtotal += tokens[i];
130  cmdtotal += " ";
131  }
132 
133  if( qcontinued ) continue; // read the next line
134 
135  if( cmdtotal.size() != 0 ) break;
136  if( batch_stream_.eof() ) break;
137  }
138 
139  // strip again
140  cmdtotal = cmdtotal.strip(G4String::both);
141 
142  // bypass some commands
143  cmdtotal = BypassCommand(cmdtotal);
144 
145  // finally,
146  if( batch_stream_.eof() && cmdtotal.size()==0 ) {
147  return "exit";
148  }
149 
150  return cmdtotal;
151 }
G4String strip(G4int strip_Type=trailing, char c=' ')
std::string::size_type str_size
int G4int
Definition: G4Types.hh:78
G4String BypassCommand(const G4String &command) const
bool G4bool
Definition: G4Types.hh:79
std::ifstream batch_stream_
Definition: G4MPIbatch.hh:42
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define BUFSIZE
Definition: liblist.c:41
G4UIsession * G4MPIbatch::SessionStart ( )
virtual

Implements G4VBasicShell.

Definition at line 154 of file G4MPIbatch.cc.

References G4VMPIsession::ExecCommand(), fCommandSucceeded, G4cerr, G4cout, G4endl, G4VMPIsession::g4mpi_, G4UImanager::GetUIpointer(), G4VMPIsession::is_master_, is_opened_, and ReadCommand().

155 {
156  if( is_master_ && !is_opened_ ) { // macro file is not found
157  g4mpi_-> BcastCommand("exit");
158  return NULL;
159  }
160 
161  G4String newCommand = "", scommand; // newCommand is always "" in slaves
162 
163  while(1) {
164  if( is_master_ ) newCommand = ReadCommand();
165  // broadcast a new G4 command
166  scommand = g4mpi_-> BcastCommand(newCommand);
167  if( scommand == "exit" ) {
168  g4mpi_-> WaitBeamOn();
169  return 0;
170  }
171 
172  // just echo something
173  if( scommand(0) == '#' ) {
174  if( G4UImanager::GetUIpointer()-> GetVerboseLevel() == 2 ) {
175  G4cout << scommand << G4endl;
176  }
177  continue;
178  }
179 
180  G4int rc = ExecCommand(scommand);
181  if ( rc != fCommandSucceeded ) {
182  G4cerr << G4endl << "***** Batch is interupted!! *****" << G4endl;
183  break;
184  }
185  }
186 
187  return NULL;
188 }
G4MPImanager * g4mpi_
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4String ReadCommand()
Definition: G4MPIbatch.cc:85
G4bool is_opened_
Definition: G4MPIbatch.hh:43
G4int ExecCommand(const G4String &acommand)
G4GLOB_DLL std::ostream G4cerr

Field Documentation

std::ifstream G4MPIbatch::batch_stream_
protected

Definition at line 42 of file G4MPIbatch.hh.

Referenced by G4MPIbatch(), ReadCommand(), and ~G4MPIbatch().

G4bool G4MPIbatch::is_batch_mode_
protected

Definition at line 44 of file G4MPIbatch.hh.

G4bool G4MPIbatch::is_opened_
protected

Definition at line 43 of file G4MPIbatch.hh.

Referenced by G4MPIbatch(), SessionStart(), and ~G4MPIbatch().


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