52G4bool G4UImanager::doublePrecisionStr =
false;
53G4int G4UImanager::igThreadID = -1;
63G4bool& G4UImanager::fUImanagerHasBeenKilled()
79 if(fUImanager() ==
nullptr)
81 if(!fUImanagerHasBeenKilled())
84 fUImanager()->CreateMessenger();
93 return fMasterUImanager();
103 commandStack =
new std::vector<G4String>;
107void G4UImanager::CreateMessenger()
118 if(bridges !=
nullptr)
120 for(
auto itr = bridges->cbegin(); itr != bridges->cend(); ++itr)
130 delete CoutMessenger;
131 delete ProfileMessenger;
132 delete UnitsMessenger;
136 fUImanagerHasBeenKilled() =
true;
137 fUImanager() =
nullptr;
138 if(commandStack !=
nullptr)
140 commandStack->clear();
154 doublePrecisionStr = val;
160 return doublePrecisionStr;
167 savedCommand = treeTop->
FindPath(theCommand);
168 if(savedCommand ==
nullptr)
180 if(reGet || savedCommand ==
nullptr)
186 for(
G4int i_thParameter = 0; i_thParameter < parameterNumber; ++i_thParameter)
188 token = savedToken();
191 if(token[(
size_t) 0] ==
'"')
194 token.
append(savedToken(
"\""));
202 const char* aParameterName,
205 if(reGet || savedCommand ==
nullptr)
219 const char* aParameterName,
G4bool reGet)
224 const char* t = targetParameter;
225 std::istringstream is(t);
237 const char* t = targetParameter;
238 std::istringstream is(t);
245 const char* aParameterName,
251 const char* t = targetParameter;
252 std::istringstream is(t);
264 const char* t = targetParameter;
265 std::istringstream is(t);
276 fMasterUImanager()->AddWorkerCommand(newCommand);
281void G4UImanager::AddWorkerCommand(
G4UIcommand* newCommand)
292 fMasterUImanager()->RemoveWorkerCommand(aCommand);
297void G4UImanager::RemoveWorkerCommand(
G4UIcommand* aCommand)
306 session = batchSession;
311 session = previousSession;
323 c1 += parameterToken();
325 c1 += parameterToken();
327 std::istringstream is(t1);
331 is >> d1 >> d2 >> d3;
332 Loop(mf, vn, d1, d2, d3);
343 for(
G4double d = initialValue; d <= finalValue; d += stepSize)
345 std::ostringstream os;
353 for(
G4double d = initialValue; d >= finalValue; d += stepSize)
355 std::ostringstream os;
361 Foreach(macroFile, variableName, cd);
373 while(!((ca = parameterToken()).isNull()))
380 if(aliasValue(0) ==
'"')
383 if(aliasValue(aliasValue.length() - 1) ==
'"')
385 strippedValue = aliasValue(1, aliasValue.length() - 2);
389 strippedValue = aliasValue(1, aliasValue.length() - 1);
391 aliasValue = strippedValue;
400 const char* candidates)
402 G4String candidatesString = candidates;
405 while(!((cd = parameterToken()).isNull()))
415 ed <<
"Loop aborted due to a command execution error - "
416 <<
"error code " << lastRC;
429 while((ia !=
G4int(std::string::npos)) &&
430 ((iz ==
G4int(std::string::npos)) || (ia < iz)))
436 if(ib ==
G4int(std::string::npos))
439 for(
G4int i = 0; i < ia; ++i)
442 G4cerr <<
"Unmatched alias parenthesis -- command ignored" <<
G4endl;
446 G4String ps = aCommand(ia + 1, aCommand.length() - (ia + 1));
449 if(ic !=
G4int(std::string::npos) && ic <
id)
462 subs = aCommand(0, ia);
463 G4String alis = aCommand(ia + 1, ibx - ia - 1);
464 G4String rems = aCommand(ibx + 1, aCommand.length() - ibx);
468 G4cerr <<
"Alias <" << alis <<
"> not found -- command ignored" <<
G4endl;
472 aCommand = subs + (*alVal) + rems;
473 ia = aCommand.
index(
"{");
495 std::size_t i = aCommand.
index(
" ");
496 if(i != std::string::npos)
498 commandString = aCommand(0, i);
499 commandParameter = aCommand(i + 1, aCommand.length() - (i + 1));
503 commandString = aCommand;
507 G4int len = commandString.length();
513 if(commandString(ll, 2) ==
"//")
517 commandString.
remove(ll, 1);
521 a1 = commandString(0, ll);
522 a2 = commandString(ll + 1, len - ll - 1);
523 commandString = a1 + a2;
533 if(isMaster && bridges !=
nullptr)
535 for(
auto itr = bridges->cbegin(); itr != bridges->cend(); ++itr)
537 G4int leng = (*itr)->DirLength();
538 if(commandString(0, leng) == (*itr)->DirName())
540 return (*itr)->LocalUI()->ApplyCommand(commandString +
" " +
547 if(targetCommand ==
nullptr)
549 if(ignoreCmdNotFound)
551 if(stackCommandsForBroadcast)
553 commandStack->push_back(commandString +
" " + commandParameter);
565 commandStack->push_back(commandString +
" " + commandParameter);
574 historyFile << aCommand <<
G4endl;
575 if(
G4int(histVec.size()) >= maxHistSize)
577 histVec.erase(histVec.begin());
579 histVec.push_back(aCommand);
582 G4int commandFailureCode = targetCommand->
DoIt(commandParameter);
583 if(commandFailureCode == 0)
586 if(additionalFailureCode > 0)
590 <<
"Error code : " << additionalFailureCode;
592 commandFailureCode += additionalFailureCode;
595 return commandFailureCode;
613 historyFile.open((
char*) fileName);
621 saveHistory = historySwitch;
625void G4UImanager::PauseSession(
const char* msg)
635 if(comTree !=
nullptr)
650 if(targetDir(targetDir.length() - 1) !=
'/')
660 while(idx <
G4int(targetDir.length()) - 1)
663 G4String targetDirString = targetDir(0, i + 1);
664 comTree = comTree->
GetTree(targetDirString);
665 if(comTree ==
nullptr)
677 if(pauseAtBeginOfEvent)
683 PauseSession(
"BeginOfEvent");
686 if(pauseAtEndOfEvent)
692 PauseSession(
"EndOfEvent");
711 G4String aliasValue = aLine(i + 1, aLine.length() - (i + 1));
712 if(aliasValue(0) ==
'"')
715 if(aliasValue(aliasValue.length() - 1) ==
'"')
717 strippedValue = aliasValue(1, aliasValue.length() - 2);
721 strippedValue = aliasValue(1, aliasValue.length() - 1);
723 aliasValue = strippedValue;
753 G4cerr <<
"Directory <" << dir <<
"> is not found." <<
G4endl;
762 std::size_t idxfirst = 0;
763 std::size_t idxend = 0;
765 while((idxend = searchPath.
index(
':', idxfirst)) != G4String::npos)
767 pathstring = searchPath.substr(idxfirst, idxend - idxfirst);
768 if(pathstring.size() != 0)
769 searchDirs.push_back(pathstring);
770 idxfirst = idxend + 1;
773 pathstring = searchPath.substr(idxfirst, searchPath.size() - idxfirst);
774 if(pathstring.size() != 0)
775 searchDirs.push_back(pathstring);
783 fs.open(fname.c_str(), std::ios::in);
797 for(std::size_t i = 0; i < searchDirs.size(); ++i)
799 G4String fullpath = searchDirs[i] +
"/" + fname;
800 if(FileFound(fullpath))
802 macrofile = fullpath;
812 std::vector<G4String>* returnValue = commandStack;
813 commandStack =
new std::vector<G4String>;
823 "G4UIBridge cannot bridge between same object.");
827 bridges->push_back(brg);
858 if(fileN ==
"**Screen**")
864 std::stringstream fn;
865 fn <<
"G4W_" << threadID <<
"_" << fileN;
877 if(fileN ==
"**Screen**")
883 std::stringstream fn;
884 fn <<
"G4W_" << threadID <<
"_" << fileN;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
@ fIllegalApplicationState
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
void G4iosInitialization()
G4GLOB_DLL G4strstreambuf G4coutbuf
G4GLOB_DLL G4strstreambuf G4cerrbuf
void SetPrefixString(const G4String &wd="G4WT")
void EnableBuffering(G4bool flag=true)
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
void SetIgnoreInit(G4bool val=true)
void SetIgnoreCout(G4int tid=0)
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
static G4StateManager * GetStateManager()
G4String & remove(str_size)
G4String & append(const G4String &)
str_size index(const char *, G4int pos=0) const
G4String strip(G4int strip_Type=trailing, char c=' ')
const char * data() const
G4String * FindAlias(const char *aliasName)
void ChangeAlias(const char *aliasName, const char *aliasValue)
void RemoveAlias(const char *aliasName)
G4UImanager * LocalUI() const
G4UIcommandTree * GetTree(G4int i)
void AddNewCommand(G4UIcommand *newCommand, G4bool workerThreadOnly=false)
G4UIcommand * FindPath(const char *commandPath) const
void RemoveCommand(G4UIcommand *aCommand, G4bool workerThreadOnly=false)
std::size_t GetParameterEntries() const
G4UIparameter * GetParameter(G4int i) const
G4bool ToBeBroadcasted() const
virtual G4int DoIt(G4String parameterList)
const G4String & GetFailureDescription()
G4String GetCurrentValue()
static G4bool DoublePrecisionStr()
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
void SetCoutDestination(G4UIsession *const value)
static void UseDoublePrecisionStr(G4bool val)
void ForeachS(const char *valueList)
void SetUpForAThread(G4int tId)
std::vector< G4String > * GetCommandStack()
void Foreach(const char *macroFile, const char *variableName, const char *candidates)
G4int ApplyCommand(const char *aCommand)
void SetThreadIgnoreInit(G4bool flg=true)
void CreateHTML(const char *dir="/")
void Loop(const char *macroFile, const char *variableName, G4double initialValue, G4double finalValue, G4double stepSize=1.0)
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
void LoopS(const char *valueList)
void StoreHistory(const char *fileName="G4history.macro")
void ListCommands(const char *direc)
G4double GetCurrentDoubleValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
void ExecuteMacroFile(const char *fileName)
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
static G4UImanager * GetMasterUIpointer()
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
void SetUpForSpecialThread(G4String aPrefix)
void AddNewCommand(G4UIcommand *newCommand)
G4String GetCurrentValues(const char *aCommand)
virtual G4bool Notify(G4ApplicationState requestedState)
void SetThreadIgnore(G4int tid=0)
void SetAlias(const char *aliasLine)
void SetThreadPrefixString(const G4String &s="W")
G4String FindMacroPath(const G4String &fname) const
void RemoveAlias(const char *aliasName)
G4String SolveAlias(const char *aCmd)
void RemoveCommand(G4UIcommand *aCommand)
void ParseMacroSearchPath()
static G4UImanager * GetUIpointer()
void RegisterBridge(G4UIbridge *brg)
void SetThreadUseBuffer(G4bool flg=true)
const G4String & GetParameterName() const
virtual void PauseSessionStart(const G4String &Prompt)
virtual G4UIsession * SessionStart()
G4int GetLastReturnCode() const
void SetDestination(G4coutDestination *dest)
void G4SetThreadId(G4int aNewValue)
#define G4ThreadLocalStatic