Geant4-11
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes
G4ZMQServer Class Reference

#include <G4ZMQServer.hh>

Inheritance diagram for G4ZMQServer:
G4VBasicShell G4UIsession G4coutDestination

Public Types

using Transformer = std::function< G4bool(G4String &)>
 

Public Member Functions

void AddCerrTransformer (const Transformer &t)
 
void AddCerrTransformer (Transformer &&t)
 
void AddCoutTransformer (const Transformer &t)
 
void AddCoutTransformer (Transformer &&t)
 
 G4ZMQServer ()
 
G4String GetEndpoint () const
 
G4int GetLastReturnCode () const
 
virtual void PauseSessionStart (const G4String &message)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 
G4int ReceiveG4cerr_ (const G4String &msg)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
G4int ReceiveG4cout_ (const G4String &msg)
 
virtual void ResetTransformers ()
 
virtual G4UIsessionSessionStart ()
 
void SetDebug (G4bool flag)
 
void SetEndpoint (const G4String &endpoint)
 
 ~G4ZMQServer ()
 

Static Public Member Functions

static G4int InSession ()
 

Protected Member Functions

void ApplyShellCommand (const G4String &, G4bool &, G4bool &)
 
G4bool ChangeDirectory (const char *newDir)
 
void ChangeDirectoryCommand (const G4String &)
 
G4String Complete (const G4String &)
 
G4UIcommandFindCommand (const char *commandName) const
 
G4UIcommandTreeFindDirectory (const char *dirName) const
 
G4String FindMatchingPath (G4UIcommandTree *, const G4String &)
 
G4String GetCurrentWorkingDirectory () const
 
void ListDirectory (const G4String &) const
 
G4String ModifyToFullPathCommand (const char *aCommandLine) const
 
void ShowCurrent (const G4String &) const
 
void TerminalHelp (const G4String &)
 

Protected Attributes

G4int ifBatch = 0
 
G4int lastRC = 0
 
std::vector< TransformertransformersCerr
 
std::vector< TransformertransformersCout
 

Static Protected Attributes

static G4ICOMS_DLL G4int inSession = 0
 
static G4MTGLOB_DLL G4coutDestinationmasterG4coutDestination = nullptr
 

Private Member Functions

virtual void ExecuteCommand (const G4String &command)
 
virtual void ExitHelp () const
 
G4String GetCommand (const G4String &input)
 
virtual G4bool GetHelpChoice (G4int &)
 
G4String ModifyPath (const G4String &tempPath) const
 

Private Attributes

G4String currentDirectory
 
G4String endpoint_
 
G4bool qdebug_
 
G4UItcshshell_
 

Detailed Description

Definition at line 36 of file G4ZMQServer.hh.

Member Typedef Documentation

◆ Transformer

Definition at line 61 of file G4coutDestination.hh.

Constructor & Destructor Documentation

◆ G4ZMQServer()

G4ZMQServer::G4ZMQServer ( )

Definition at line 74 of file G4ZMQServer.cc.

75{
76 endpoint_ = "tcp://127.0.0.1:5555";
77 qdebug_ = false;
78 shell_= new G4UItcsh();
79 shell_-> SetLsColor(BLUE, RED);
80
82 ::ui_manager-> SetSession(this);
83 ::ui_manager-> SetCoutDestination(this);
84
85 ::qexit = false;
86}
@ BLUE
Definition: G4VUIshell.hh:54
@ RED
Definition: G4VUIshell.hh:53
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
G4String endpoint_
Definition: G4ZMQServer.hh:54
G4UItcsh * shell_
Definition: G4ZMQServer.hh:55
G4bool qdebug_
Definition: G4ZMQServer.hh:53

References BLUE, endpoint_, G4UImanager::GetUIpointer(), qdebug_, anonymous_namespace{G4ZMQServer.cc}::qexit, RED, shell_, and anonymous_namespace{G4ZMQServer.cc}::ui_manager.

◆ ~G4ZMQServer()

G4ZMQServer::~G4ZMQServer ( )

Definition at line 89 of file G4ZMQServer.cc.

90{
91 delete shell_;
92}

References shell_.

Member Function Documentation

◆ AddCerrTransformer() [1/2]

void G4coutDestination::AddCerrTransformer ( const Transformer t)
inlineinherited

Definition at line 67 of file G4coutDestination.hh.

68 {
69 transformersCerr.push_back(t);
70 }
std::vector< Transformer > transformersCerr

References G4coutDestination::transformersCerr.

Referenced by G4MTcoutDestination::HandleFileCerr().

◆ AddCerrTransformer() [2/2]

void G4coutDestination::AddCerrTransformer ( Transformer &&  t)
inlineinherited

Definition at line 71 of file G4coutDestination.hh.

71{ transformersCerr.push_back(t); }

References G4coutDestination::transformersCerr.

◆ AddCoutTransformer() [1/2]

void G4coutDestination::AddCoutTransformer ( const Transformer t)
inlineinherited

◆ AddCoutTransformer() [2/2]

void G4coutDestination::AddCoutTransformer ( Transformer &&  t)
inlineinherited

Definition at line 66 of file G4coutDestination.hh.

66{ transformersCout.push_back(t); }

References G4coutDestination::transformersCout.

◆ ApplyShellCommand()

void G4VBasicShell::ApplyShellCommand ( const G4String a_string,
G4bool exitSession,
G4bool exitPause 
)
protectedinherited

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Definition at line 232 of file G4VBasicShell.cc.

237{
239 if(UI==NULL) return;
240
241 G4String command = G4StrUtil::lstrip_copy(a_string);
242
243 if( command[0] == '#' ) {
244
245 G4cout << command << G4endl;
246
247 } else if( command == "ls" || command.substr(0,3) == "ls " ) {
248
249 ListDirectory( command );
250
251 } else if( command == "pwd" ) {
252
253 G4cout << "Current Working Directory : "
255
256 } else if( command == "cd" || command.substr(0,3) == "cd ") {
257
258 ChangeDirectoryCommand ( command );
259
260 } else if( command == "help" || command.substr(0,5) == "help ") {
261
262 TerminalHelp( command );
263
264 } else if( command[0] == '?' ) {
265
266 ShowCurrent( command );
267
268 } else if( command == "hist" || command == "history") {
269
270 G4int nh = UI->GetNumberOfHistory();
271 for(G4int i=0;i<nh;i++) {
272 G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl;
273 }
274
275 } else if( command[0] == '!' ) {
276
277 G4String ss = command.substr(1,command.length()-1);
278 G4int vl;
279 const char* tt = ss;
280 std::istringstream is(tt);
281 is >> vl;
282 G4int nh = UI->GetNumberOfHistory();
283 if(vl>=0 && vl<nh) {
284 G4String prev = UI->GetPreviousCommand(vl);
285 G4cout << prev << G4endl;
287 } else {
288 G4cerr << "history " << vl << " is not found." << G4endl;
289 }
290
291 } else if( command == "exit" ) {
292
293 if( exitPause == false) { //In a secondary loop.
294 G4cout << "You are now processing RUN." << G4endl;
295 G4cout << "Please abort it using \"/run/abort\" command first" << G4endl;
296 G4cout << " and use \"continue\" command until the application" << G4endl;
297 G4cout << " becomes to Idle." << G4endl;
298 } else {
299 exitSession = true;
300 }
301
302 } else if( command == "cont" || command == "continue"){
303
304 exitPause = true;
305
306 } else {
307
309
310 }
311}
int G4int
Definition: G4Types.hh:85
static G4bool exitSession
Definition: G4UIQt.cc:92
static G4bool exitPause
Definition: G4UIQt.cc:93
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:201
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:202
G4String ModifyToFullPathCommand(const char *aCommandLine) const
void ShowCurrent(const G4String &) const
void TerminalHelp(const G4String &)
virtual void ExecuteCommand(const G4String &)
void ListDirectory(const G4String &) const
G4String GetCurrentWorkingDirectory() const
void ChangeDirectoryCommand(const G4String &)
G4String lstrip_copy(G4String str, char c=' ')
Return copy of string with leading characters removed.

References G4VBasicShell::ChangeDirectoryCommand(), G4VBasicShell::ExecuteCommand(), exitPause, exitSession, G4cerr, G4cout, G4endl, G4VBasicShell::GetCurrentWorkingDirectory(), G4UImanager::GetNumberOfHistory(), G4UImanager::GetPreviousCommand(), G4UImanager::GetUIpointer(), G4VBasicShell::ListDirectory(), G4StrUtil::lstrip_copy(), G4VBasicShell::ModifyToFullPathCommand(), G4VBasicShell::ShowCurrent(), and G4VBasicShell::TerminalHelp().

Referenced by G4UIQt::ButtonCallback(), G4UIXm::ButtonCallback(), G4UIQt::CommandEnteredCallback(), G4UIXm::CommandEnteredCallback(), G4UIWin32::DoOpenMacro(), G4UIWin32::DoSaveViewer(), G4UIWin32::ProcessDefaultCommands(), and G4UIWin32::ProcessEnterKey().

◆ ChangeDirectory()

G4bool G4VBasicShell::ChangeDirectory ( const char *  newDir)
protectedinherited

Definition at line 74 of file G4VBasicShell.cc.

75{
76 G4String newPrefix = G4StrUtil::strip_copy(newDir);
77
78 G4String newDirectory = ModifyPath( newPrefix );
79 if( newDirectory.back() != '/' )
80 { newDirectory += "/"; }
81 if( FindDirectory( newDirectory.c_str() ) == NULL )
82 { return false; }
83 currentDirectory = newDirectory;
84 return true;
85}
G4String ModifyPath(const G4String &tempPath) const
G4String currentDirectory
G4UIcommandTree * FindDirectory(const char *dirName) const
G4String strip_copy(G4String str, char c=' ')
Return copy of string with leading and trailing characters removed.

References G4VBasicShell::currentDirectory, G4VBasicShell::FindDirectory(), G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by G4VBasicShell::ChangeDirectoryCommand().

◆ ChangeDirectoryCommand()

void G4VBasicShell::ChangeDirectoryCommand ( const G4String newCommand)
protectedinherited

Definition at line 325 of file G4VBasicShell.cc.

326{
328 if( newCommand.length() <= 3 ) {
329 prefix = "/";
330 } else {
331 G4String aNewPrefix = newCommand.substr(3, newCommand.length()-3);
332 prefix = G4StrUtil::strip_copy(aNewPrefix);
333 }
334 if(!ChangeDirectory(prefix)) {
335 G4cout << "directory <" << prefix << "> not found." << G4endl;
336 }
337}
G4bool ChangeDirectory(const char *newDir)

References G4VBasicShell::ChangeDirectory(), G4cout, G4endl, and G4StrUtil::strip_copy().

Referenced by G4VBasicShell::ApplyShellCommand(), G4UIterminal::GetCommand(), and GetCommand().

◆ Complete()

G4String G4VBasicShell::Complete ( const G4String commandName)
protectedinherited

Definition at line 180 of file G4VBasicShell.cc.

181{
182 G4String rawCommandLine = commandName;
183 G4String commandLine = G4StrUtil::strip_copy(rawCommandLine);
184
185 size_t i = commandLine.find(" ");
186 if( i != std::string::npos ) return rawCommandLine; // Already entering parameters,
187 // assume command path is correct.
188 G4String commandString = commandLine;
189 G4String targetCom = ModifyPath(commandString);
191 G4String value = FindMatchingPath(tree,targetCom);
192 if(value=="") return rawCommandLine;
193 return value;
194}
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:186
G4String FindMatchingPath(G4UIcommandTree *, const G4String &)

References G4VBasicShell::FindMatchingPath(), G4UImanager::GetTree(), G4UImanager::GetUIpointer(), G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by G4UIQt::eventFilter(), G4UIXm::keyHandler(), and G4UIWin32::ProcessTabKey().

◆ ExecuteCommand()

void G4ZMQServer::ExecuteCommand ( const G4String aCommand)
privatevirtual

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Reimplemented from G4VBasicShell.

Definition at line 263 of file G4ZMQServer.cc.

264{
265 auto rc = ::ui_manager-> ApplyCommand(command);
266 auto pcode = rc % 100;
267 auto status = rc - pcode;
268
269 G4UIcommand* cmd = nullptr;
270 if( status != fCommandSucceeded ) cmd = FindCommand(command);
271
272 switch ( status ) {
274 break;
275 case fCommandNotFound:
276 G4cerr << "command <" << ::ui_manager-> SolveAlias(command)
277 << "> not found" << G4endl;
278 break;
280 G4cerr << "illegal application state -- command refused" << G4endl;
281 break;
283 G4cerr << "Parameter is out of range" << G4endl;
284 break;
286 G4cerr << "Parameter is out of candidate list (index "
287 << pcode << ")" << G4endl;
288 G4cerr << "Candidates : "
289 << cmd-> GetParameter(pcode)-> GetParameterCandidates()
290 << G4endl;
291 break;
293 G4cerr << "Parameter is wrong type and/or is not omittable (index "
294 << pcode << ")" << G4endl;
295 break;
296 case fAliasNotFound:
297 break;
298 default:
299 G4cerr << "command refused (" << status << ")" << G4endl;
300 break;
301 }
302}
@ fParameterOutOfCandidates
@ fCommandNotFound
@ fAliasNotFound
@ fIllegalApplicationState
@ fParameterUnreadable
@ fCommandSucceeded
@ fParameterOutOfRange
G4UIcommand * FindCommand(const char *commandName) const

References fAliasNotFound, fCommandNotFound, fCommandSucceeded, fIllegalApplicationState, G4VBasicShell::FindCommand(), fParameterOutOfCandidates, fParameterOutOfRange, fParameterUnreadable, G4cerr, G4endl, and anonymous_namespace{G4ZMQServer.cc}::ui_manager.

Referenced by SessionStart().

◆ ExitHelp()

void G4ZMQServer::ExitHelp ( ) const
privatevirtual

Implements G4VBasicShell.

Definition at line 311 of file G4ZMQServer.cc.

312{
313}

◆ FindCommand()

G4UIcommand * G4VBasicShell::FindCommand ( const char *  commandName) const
protectedinherited

Definition at line 109 of file G4VBasicShell.cc.

110{
111 G4String commandLine = G4StrUtil::strip_copy(commandName);
112
113 G4String commandString;
114 size_t i = commandLine.find(" ");
115 if( i != std::string::npos )
116 { commandString = commandLine.substr(0,i); }
117 else
118 { commandString = commandLine; }
119
120 G4String targetCom = ModifyPath(commandString);
121 return G4UImanager::GetUIpointer()->GetTree()->FindPath(targetCom);
122}
G4UIcommand * FindPath(const char *commandPath) const

References G4UIcommandTree::FindPath(), G4UImanager::GetTree(), G4UImanager::GetUIpointer(), G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by G4UIterminal::ExecuteCommand(), and ExecuteCommand().

◆ FindDirectory()

G4UIcommandTree * G4VBasicShell::FindDirectory ( const char *  dirName) const
protectedinherited

Definition at line 87 of file G4VBasicShell.cc.

88{
89 G4String theDir = G4StrUtil::strip_copy(dirName);
90
91 G4String targetDir = ModifyPath( theDir );
92 if( targetDir.back() != '/' )
93 { targetDir += "/"; }
95 if( targetDir == "/" )
96 { return comTree; }
97 size_t idx = 1;
98 while( idx < targetDir.length()-1 )
99 {
100 size_t i = targetDir.find("/",idx);
101 comTree = comTree->GetTree(targetDir.substr(0,i+1).c_str());
102 if( comTree == NULL )
103 { return NULL; }
104 idx = i+1;
105 }
106 return comTree;
107}
G4UIcommandTree * GetTree(G4int i)

References G4UImanager::GetTree(), G4UIcommandTree::GetTree(), G4UImanager::GetUIpointer(), G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by G4VBasicShell::ChangeDirectory(), G4VBasicShell::ListDirectory(), and SessionStart().

◆ FindMatchingPath()

G4String G4VBasicShell::FindMatchingPath ( G4UIcommandTree aTree,
const G4String aCommandPath 
)
protectedinherited

Definition at line 196 of file G4VBasicShell.cc.

198{
199 return aTree-> CompleteCommandPath(aCommandPath);
200}

Referenced by G4VBasicShell::Complete().

◆ GetCommand()

G4String G4ZMQServer::GetCommand ( const G4String input)
private

Definition at line 203 of file G4ZMQServer.cc.

204{
205 const std::string nullstr = "";
206 G4String cmdstr = input;
207
209 if ( cstr.length() == 0 ) {
210 cmdstr = nullstr;
211
212 // define built-in shell commands...
213 } else if ( cstr[0] == '#' ) {
214 G4cout << cstr << G4endl;
215 cmdstr = nullstr;
216
217 } else if ( cstr == "ls" || cstr.substr(0,3) == "ls " ) {
218 ListDirectory(cstr);
219 cmdstr = nullstr;
220
221 } else if ( cstr == "lc" || cstr.substr(0,3) == "lc " ) {
222 shell_-> ListCommand(cstr.erase(0,2));
223 cmdstr = nullstr;
224
225 } else if (cstr == "pwd" ) {
226 G4cout << "Current Command Directory : "
228 cmdstr = nullstr;
229
230 } else if ( cstr == "cwd" ) {
231 shell_-> ShowCurrentDirectory();
232 cmdstr = nullstr;
233
234 } else if (cstr == "cd" || cstr.substr(0,3) == "cd " ) {
236 shell_-> SetCurrentDirectory(GetCurrentWorkingDirectory());
237 cmdstr = nullstr;
238
239 } else if ( cstr == "help" || cstr.substr(0,5) == "help " ) {
240 TerminalHelp(cstr);
241 cmdstr = nullstr;
242
243 } else if ( cstr(0) == '?' ) {
244 ShowCurrent(cstr);
245 cmdstr = nullstr;
246
247 } else if ( cstr == "history" ) {
248 auto nh= ::ui_manager-> GetNumberOfHistory();
249 for (auto i = 0; i < nh; i++) {
250 G4cout << i << ": " << ::ui_manager->GetPreviousCommand(i) << G4endl;
251 }
252 cmdstr = nullstr;
253
254 } else if ( cstr == "exit" ) {
255 ::qexit = true;
256 cmdstr = nullstr;
257 }
258
260}
string cmdstr
Definition: test.py:122

References G4VBasicShell::ChangeDirectoryCommand(), test::cmdstr, G4cout, G4endl, G4VBasicShell::GetCurrentWorkingDirectory(), G4UImanager::GetPreviousCommand(), G4VBasicShell::ListDirectory(), G4StrUtil::lstrip_copy(), G4VBasicShell::ModifyToFullPathCommand(), anonymous_namespace{G4ZMQServer.cc}::qexit, shell_, G4VBasicShell::ShowCurrent(), G4VBasicShell::TerminalHelp(), and anonymous_namespace{G4ZMQServer.cc}::ui_manager.

Referenced by SessionStart().

◆ GetCurrentWorkingDirectory()

G4String G4VBasicShell::GetCurrentWorkingDirectory ( ) const
protectedinherited

◆ GetEndpoint()

G4String G4ZMQServer::GetEndpoint ( ) const
inline

Definition at line 71 of file G4ZMQServer.hh.

72{
73 return endpoint_;
74}

References endpoint_.

◆ GetHelpChoice()

G4bool G4ZMQServer::GetHelpChoice ( G4int )
privatevirtual

Implements G4VBasicShell.

Definition at line 305 of file G4ZMQServer.cc.

306{
307 return true;
308}

◆ GetLastReturnCode()

G4int G4UIsession::GetLastReturnCode ( ) const
inlineinherited

Definition at line 63 of file G4UIsession.hh.

63{ return lastRC; }
G4int lastRC
Definition: G4UIsession.hh:69

References G4UIsession::lastRC.

◆ InSession()

G4int G4UIsession::InSession ( )
staticinherited

Definition at line 68 of file G4UIsession.cc.

69{
70 return inSession;
71}
static G4ICOMS_DLL G4int inSession
Definition: G4UIsession.hh:67

References G4UIsession::inSession.

Referenced by G4UIcontrolMessenger::SetNewValue().

◆ ListDirectory()

void G4VBasicShell::ListDirectory ( const G4String newCommand) const
protectedinherited

Definition at line 339 of file G4VBasicShell.cc.

340{
341 G4String targetDir;
342 if( newCommand.length() <= 3 ) {
343 targetDir = GetCurrentWorkingDirectory();
344 } else {
345 G4String newPrefix = newCommand.substr(3, newCommand.length()-3);
346 targetDir = G4StrUtil::strip_copy(newPrefix);
347 }
348 G4UIcommandTree* commandTree = FindDirectory( targetDir );
349 if( commandTree == NULL ) {
350 G4cout << "Directory <" << targetDir << "> is not found." << G4endl;
351 } else {
352 commandTree->ListCurrent();
353 }
354}
void ListCurrent() const

References G4VBasicShell::FindDirectory(), G4cout, G4endl, G4VBasicShell::GetCurrentWorkingDirectory(), G4UIcommandTree::ListCurrent(), and G4StrUtil::strip_copy().

Referenced by G4VBasicShell::ApplyShellCommand(), G4UIterminal::GetCommand(), and GetCommand().

◆ ModifyPath()

G4String G4VBasicShell::ModifyPath ( const G4String tempPath) const
privateinherited

Definition at line 124 of file G4VBasicShell.cc.

125{
126 if( tempPath.length() == 0 ) return tempPath;
127
128 G4String newPath = "";
129
130 // temporal full path
131 if( tempPath[0] == '/') newPath = tempPath;
132 else newPath = currentDirectory + tempPath;
133
134 // body of path...
135 while(1){
136 size_t idx = newPath.find("/./");
137 if( idx == G4String::npos) break;
138 newPath.erase(idx,2);
139 }
140
141 while(1) {
142 size_t idx = newPath.find("/../");
143 if( idx == G4String::npos) break;
144 if( idx == 0) {
145 newPath.erase(1,3);
146 continue;
147 }
148 size_t idx2 = newPath.find_last_of('/', idx-1);
149 if(idx2 != G4String::npos) newPath.erase(idx2, idx-idx2+3);
150 }
151
152 // end of path...
153 if ( newPath.size() >= 3 ) {
154 if(newPath.substr(newPath.size()-3,3) == "/..") {
155 if( newPath.size() == 3) {
156 newPath = "/";
157 } else {
158 size_t idx = newPath.find_last_of('/', newPath.size()-4);
159 if(idx != G4String::npos) newPath.erase(idx+1);
160 }
161 }
162 }
163
164 if ( newPath.size() >= 2 ) {
165 if(newPath.substr(newPath.size()-2,2) == "/.") newPath.erase(newPath.size()-1,1);
166 }
167
168 // truncate "/////" to "/"
169 while(1) {
170 size_t idx = newPath.find("//");
171 if( idx == G4String::npos) break;
172 newPath.erase(idx,1);
173 }
174
175 return newPath;
176}

References G4VBasicShell::currentDirectory.

Referenced by G4VBasicShell::ChangeDirectory(), G4VBasicShell::Complete(), G4VBasicShell::FindCommand(), G4VBasicShell::FindDirectory(), and G4VBasicShell::ModifyToFullPathCommand().

◆ ModifyToFullPathCommand()

G4String G4VBasicShell::ModifyToFullPathCommand ( const char *  aCommandLine) const
protectedinherited

Definition at line 47 of file G4VBasicShell.cc.

48{
49 G4String rawCommandLine = aCommandLine;
50 if(rawCommandLine.empty()||rawCommandLine[0]=='\0') return rawCommandLine;
51 G4String commandLine = G4StrUtil::strip_copy(rawCommandLine);
52 G4String commandString;
53 G4String parameterString;
54 size_t i = commandLine.find(" ");
55 if( i != std::string::npos )
56 {
57 commandString = commandLine.substr(0,i);
58 parameterString = " ";
59 parameterString += commandLine.substr(i+1,commandLine.length()-(i+1));
60 }
61 else
62 { commandString = commandLine; }
63
64 G4String fullPathCommandLine
65 = ModifyPath( commandString )+parameterString;
66 return fullPathCommandLine;
67}

References G4VBasicShell::ModifyPath(), and G4StrUtil::strip_copy().

Referenced by G4UIQt::ActivateCommand(), G4VBasicShell::ApplyShellCommand(), G4UIterminal::GetCommand(), GetCommand(), G4VBasicShell::ShowCurrent(), and G4VBasicShell::TerminalHelp().

◆ PauseSessionStart()

void G4ZMQServer::PauseSessionStart ( const G4String message)
virtual

Implements G4VBasicShell.

Definition at line 174 of file G4ZMQServer.cc.

175{
176}

◆ ReceiveG4cerr()

G4int G4ZMQServer::ReceiveG4cerr ( const G4String cerrString)
virtual

Reimplemented from G4UIsession.

Definition at line 191 of file G4ZMQServer.cc.

192{
193 if ( qdebug_ ) {
194 std::cerr << cerrString << std::flush;
195 }
196
197 ::cout_stream << cerrString << std::flush;
198
199 return 0;
200}

References anonymous_namespace{G4ZMQServer.cc}::cout_stream, and qdebug_.

◆ ReceiveG4cerr_()

G4int G4coutDestination::ReceiveG4cerr_ ( const G4String msg)
inherited

Definition at line 84 of file G4coutDestination.cc.

85{
86 if(transformersCout.size() > 0)
87 {
88 G4String m = msg;
89 std::for_each(transformersCerr.begin(), transformersCerr.end(),
90 [&m](const Transformer& t) { t(m); }
91 // Call transforming function on message
92 );
93 return ReceiveG4cerr(m);
94 }
95 else
96 {
97 return ReceiveG4cerr(msg);
98 }
99}
static constexpr double m
Definition: G4SIunits.hh:109
virtual G4int ReceiveG4cerr(const G4String &msg)
std::function< G4bool(G4String &)> Transformer

References m, G4coutDestination::ReceiveG4cerr(), G4coutDestination::transformersCerr, and G4coutDestination::transformersCout.

Referenced by G4MasterForwardcoutDestination::ReceiveG4cerr().

◆ ReceiveG4cout()

G4int G4ZMQServer::ReceiveG4cout ( const G4String coutString)
virtual

Reimplemented from G4UIsession.

Definition at line 179 of file G4ZMQServer.cc.

180{
181 if ( qdebug_ ) {
182 std::cout << coutString << std::flush;
183 }
184
185 ::cout_stream << coutString << std::flush;
186
187 return 0;
188}

References anonymous_namespace{G4ZMQServer.cc}::cout_stream, and qdebug_.

◆ ReceiveG4cout_()

G4int G4coutDestination::ReceiveG4cout_ ( const G4String msg)
inherited

Definition at line 62 of file G4coutDestination.cc.

63{
64 // Avoid copy of string if not necessary
65 if(transformersCout.size() > 0)
66 {
67 G4String m = msg;
68 G4bool result = true;
69 for(const auto& el : transformersCout)
70 {
71 result &= el(m);
72 if(!result)
73 break;
74 }
75 return (result ? ReceiveG4cout(m) : 0);
76 }
77 else
78 {
79 return ReceiveG4cout(msg);
80 }
81}
bool G4bool
Definition: G4Types.hh:86
virtual G4int ReceiveG4cout(const G4String &msg)

References m, G4coutDestination::ReceiveG4cout(), and G4coutDestination::transformersCout.

Referenced by G4MasterForwardcoutDestination::ReceiveG4cout().

◆ ResetTransformers()

void G4coutDestination::ResetTransformers ( )
virtualinherited

Definition at line 41 of file G4coutDestination.cc.

42{
43 transformersCout.clear();
44 transformersCerr.clear();
45}

References G4coutDestination::transformersCerr, and G4coutDestination::transformersCout.

◆ SessionStart()

G4UIsession * G4ZMQServer::SessionStart ( )
virtual

Implements G4VBasicShell.

Definition at line 95 of file G4ZMQServer.cc.

96{
97 zmq::context_t context(1);
98 zmq::socket_t socket( context, ZMQ_REP );
99 socket.bind(endpoint_);
100
101 enum { kBufferSize = 4096 };
102 char buffer[kBufferSize];
103
104 while ( ! ::qexit ) {
105 if ( qdebug_ ) {
106 std::cout << "@@ Waiting..." << std::endl;
107 }
108
109 // waiting command
110 zmq::message_t request;
111 G4bool qok = socket.recv(&request);
112 if ( qok == false ) ::ThrowException("G4ZMQSever: socket recv error");
113 auto end_pos = request.size();
114 if ( end_pos >= kBufferSize ) end_pos = kBufferSize - 1;
115 std::memcpy(buffer, request.data(), end_pos);
116 buffer[end_pos] = '\0';
117 std::string cmd_str = buffer;
118
119 if ( qdebug_ ) {
120 std::cout << "@@ Recv=" << cmd_str << "<<" << std::endl;
121 }
122
123 // store output & send back response
124 ::cout_stream.str("");
125
126 if ( cmd_str == "@@ping" ) {
127 G4cout << "pong" << G4endl;
128
129 } else if ( cmd_str == "@@debug") {
130 qdebug_ = true;
131 G4cout << "G4ZMQ debug activated" << G4endl;
132
133 } else if ( cmd_str == "@@nodebug") {
134 qdebug_ = false;
135 G4cout << "G4ZMQ debug deactivated" << G4endl;
136
137 } else if ( cmd_str == "@@get_command_tree" ) {
138 auto cwd_name = GetCurrentWorkingDirectory();
139 auto cwd_tree = FindDirectory(cwd_name.c_str());
140 ::command_list = "";
141 ::GetCommandTree(cwd_tree);
142 G4cout << ::command_list << std::flush;
143
144 } else if ( cmd_str == "@@get_fullcommand_tree" ) {
145 auto root = ::ui_manager-> GetTree();
146 ::command_list = "";
147 ::GetCommandTree(root);
148 G4cout << ::command_list << std::flush;
149
150 } else if ( cmd_str == "help" ) {
151 G4cout << "help <command>" << G4endl;
152
153 } else {
154 G4String new_command = GetCommand(cmd_str);
155 if ( qdebug_ ) {
156 std::cout << ::black_str << "@@ Cmd="
157 << new_command << "<<" << std::endl;
158 }
159 ExecuteCommand(new_command);
160 }
161
162 std::string reply = ::cout_stream.str();
163 size_t cout_size = reply.size();
164 zmq::message_t message(cout_size);
165 std::strncpy((char*)message.data(), reply.c_str(), cout_size);
166 qok = socket.send(message);
167 if ( qok == false ) ::ThrowException("G4ZMQServer: socket send error");
168 }
169
170 return nullptr;
171}
G4String GetCommand(const G4String &input)
Definition: G4ZMQServer.cc:203
virtual void ExecuteCommand(const G4String &command)
Definition: G4ZMQServer.cc:263
void GetCommandTree(G4UIcommandTree *ctree)
Definition: G4ZMQServer.cc:54
void ThrowException(const std::string &message)
Definition: G4ZMQServer.cc:46
socket
Definition: g4zmq.py:12
context
Definition: g4zmq.py:11
#define buffer
Definition: xmlparse.cc:628

References anonymous_namespace{G4ZMQServer.cc}::black_str, buffer, anonymous_namespace{G4ZMQServer.cc}::command_list, g4zmq::context, anonymous_namespace{G4ZMQServer.cc}::cout_stream, endpoint_, ExecuteCommand(), G4VBasicShell::FindDirectory(), G4cout, G4endl, GetCommand(), anonymous_namespace{G4ZMQServer.cc}::GetCommandTree(), G4VBasicShell::GetCurrentWorkingDirectory(), qdebug_, anonymous_namespace{G4ZMQServer.cc}::qexit, g4zmq::socket, anonymous_namespace{G4ZMQServer.cc}::ThrowException(), and anonymous_namespace{G4ZMQServer.cc}::ui_manager.

◆ SetDebug()

void G4ZMQServer::SetDebug ( G4bool  flag)
inline

Definition at line 76 of file G4ZMQServer.hh.

77{
78 qdebug_ = flag;
79}

References qdebug_.

◆ SetEndpoint()

void G4ZMQServer::SetEndpoint ( const G4String endpoint)
inline

Definition at line 66 of file G4ZMQServer.hh.

67{
68 endpoint_ = endpoint;
69}

References endpoint_.

◆ ShowCurrent()

void G4VBasicShell::ShowCurrent ( const G4String newCommand) const
protectedinherited

Definition at line 313 of file G4VBasicShell.cc.

314{
316 if(UI==NULL) return;
317 G4String comString = newCommand.substr(1,newCommand.length()-1);
318 G4String theCommand = ModifyToFullPathCommand(comString);
319 G4String curV = UI->GetCurrentValues(theCommand);
320 if( ! curV.empty() ) {
321 G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
322 }
323}
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:164

References G4cout, G4endl, G4UImanager::GetCurrentValues(), G4UImanager::GetUIpointer(), and G4VBasicShell::ModifyToFullPathCommand().

Referenced by G4VBasicShell::ApplyShellCommand(), G4UIterminal::GetCommand(), and GetCommand().

◆ TerminalHelp()

void G4VBasicShell::TerminalHelp ( const G4String newCommand)
protectedinherited

Definition at line 355 of file G4VBasicShell.cc.

356{
358 if(UI==NULL) return;
359 G4UIcommandTree * treeTop = UI->GetTree();
360 size_t i = newCommand.find(" ");
361 if( i != std::string::npos )
362 {
363 G4String newValue = newCommand.substr(i+1, newCommand.length()-(i+1));
364 G4StrUtil::strip(newValue);
365 G4String targetCom = ModifyToFullPathCommand(newValue);
366 G4UIcommand* theCommand = treeTop->FindPath(targetCom);
367 if( theCommand != NULL )
368 {
369 theCommand->List();
370 return;
371 }
372 else
373 {
374 G4cout << "Command <" << newValue << " is not found." << G4endl;
375 return;
376 }
377 }
378
379 G4UIcommandTree * floor[10];
380 floor[0] = treeTop;
381 size_t iFloor = 0;
382 size_t prefixIndex = 1;
384 while( prefixIndex < prefix.length()-1 )
385 {
386 size_t ii = prefix.find("/",prefixIndex);
387 floor[iFloor+1] =
388 floor[iFloor]->GetTree(G4String(prefix.substr(0,ii+1)));
389 prefixIndex = ii+1;
390 iFloor++;
391 }
392 floor[iFloor]->ListCurrentWithNum();
393 // 1998 Oct 2 non-number input
394 while(1){
395 //G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;
396 G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<G4endl;
397 G4int j;
398 if(!GetHelpChoice(j)){
399 G4cout << G4endl << "Not a number, once more" << G4endl;
400 continue;
401 } else if( j < 0 ){
402 if( iFloor < (size_t)-j ) iFloor = 0;
403 else iFloor += j;
404 //iFloor += j;
405 //if( iFloor < 0 ) iFloor = 0;
406 floor[iFloor]->ListCurrentWithNum();
407 continue;
408 } else if(j == 0) {
409 break;
410 } else if( j > 0 ) {
411 G4int n_tree = floor[iFloor]->GetTreeEntry();
412 if( j > n_tree )
413 {
414 if( j <= n_tree + floor[iFloor]->GetCommandEntry() )
415 {
416 floor[iFloor]->GetCommand(j-n_tree)->List();
417 }
418 }
419 else
420 {
421 floor[iFloor+1] = floor[iFloor]->GetTree(j);
422 iFloor++;
423 floor[iFloor]->ListCurrentWithNum();
424 }
425 }
426 }
427 G4cout << "Exit from HELP." << G4endl << G4endl;
428 //G4cout << G4endl;
429 ExitHelp();
430}
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
void ListCurrentWithNum() const
virtual void List()
Definition: G4UIcommand.cc:410
virtual void ExitHelp() const =0
virtual G4bool GetHelpChoice(G4int &)=0
void strip(G4String &str, char c=' ')
Remove leading and trailing characters from string.

References G4VBasicShell::ExitHelp(), G4UIcommandTree::FindPath(), G4cout, G4endl, G4UIcommandTree::GetCommand(), G4VBasicShell::GetCurrentWorkingDirectory(), G4VBasicShell::GetHelpChoice(), G4UImanager::GetTree(), G4UIcommandTree::GetTree(), G4UIcommandTree::GetTreeEntry(), G4UImanager::GetUIpointer(), G4UIcommand::List(), G4UIcommandTree::ListCurrentWithNum(), G4VBasicShell::ModifyToFullPathCommand(), and G4StrUtil::strip().

Referenced by G4VBasicShell::ApplyShellCommand(), G4UIterminal::GetCommand(), GetCommand(), and G4UIQt::ShowHelpCallback().

Field Documentation

◆ currentDirectory

G4String G4VBasicShell::currentDirectory
privateinherited

◆ endpoint_

G4String G4ZMQServer::endpoint_
private

Definition at line 54 of file G4ZMQServer.hh.

Referenced by G4ZMQServer(), GetEndpoint(), SessionStart(), and SetEndpoint().

◆ ifBatch

G4int G4UIsession::ifBatch = 0
protectedinherited

Definition at line 68 of file G4UIsession.hh.

Referenced by G4UIsession::~G4UIsession().

◆ inSession

G4int G4UIsession::inSession = 0
staticprotectedinherited

◆ lastRC

G4int G4UIsession::lastRC = 0
protectedinherited

◆ masterG4coutDestination

G4coutDestination * G4coutDestination::masterG4coutDestination = nullptr
staticprotectedinherited

◆ qdebug_

G4bool G4ZMQServer::qdebug_
private

Definition at line 53 of file G4ZMQServer.hh.

Referenced by G4ZMQServer(), ReceiveG4cerr(), ReceiveG4cout(), SessionStart(), and SetDebug().

◆ shell_

G4UItcsh* G4ZMQServer::shell_
private

Definition at line 55 of file G4ZMQServer.hh.

Referenced by G4ZMQServer(), GetCommand(), and ~G4ZMQServer().

◆ transformersCerr

std::vector<Transformer> G4coutDestination::transformersCerr
protectedinherited

◆ transformersCout

std::vector<Transformer> G4coutDestination::transformersCout
protectedinherited

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