Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4MPIbatch Class Reference

#include <G4MPIbatch.hh>

Inheritance diagram for G4MPIbatch:
Collaboration diagram for G4MPIbatch:

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 ()
 
 G4UIsession (G4int iBatch)
 
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_
 
- Protected Attributes inherited from G4UIsession
G4int ifBatch
 

Additional Inherited Members

- Static Public Member Functions inherited from G4UIsession
static G4int InSession ()
 
- Static Protected Attributes inherited from G4UIsession
static G4int inSession = 0
 
- Static Protected Attributes inherited from G4coutDestination
static G4coutDestinationmasterG4coutDestination = 0
 

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.

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.

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.

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=' ')
static void Tokenize(const G4String &str, std::vector< G4String > &tokens)
Definition: G4UIbatch.cc:38
std::string::size_type str_size
Definition: G4String.hh:57
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

Here is the call graph for this function:

Here is the caller graph for this function:

G4UIsession * G4MPIbatch::SessionStart ( )
virtual

Implements G4VBasicShell.

Definition at line 154 of file G4MPIbatch.cc.

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:59
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

Here is the call graph for this function:

Member Data Documentation

std::ifstream G4MPIbatch::batch_stream_
protected

Definition at line 42 of file G4MPIbatch.hh.

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.


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