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 bridge : *bridges)
132 delete CoutMessenger;
133 delete ProfileMessenger;
134 delete UnitsMessenger;
138 fUImanagerHasBeenKilled() =
true;
139 fUImanager() =
nullptr;
140 if(commandStack !=
nullptr)
142 commandStack->clear();
156 doublePrecisionStr = val;
162 return doublePrecisionStr;
169 savedCommand = treeTop->
FindPath(theCommand);
170 if(savedCommand ==
nullptr)
182 if(reGet || savedCommand ==
nullptr)
188 for(
G4int i_thParameter = 0; i_thParameter < parameterNumber; ++i_thParameter)
190 token = savedToken();
195 if(token[(
size_t) 0] ==
'"')
198 token.append(savedToken(
"\""));
206 const char* aParameterName,
209 if(reGet || savedCommand ==
nullptr)
225 const char* aParameterName,
G4bool reGet)
230 const char* t = targetParameter;
231 std::istringstream is(t);
243 const char* t = targetParameter;
244 std::istringstream is(t);
251 const char* aParameterName,
257 const char* t = targetParameter;
258 std::istringstream is(t);
270 const char* t = targetParameter;
271 std::istringstream is(t);
282 fMasterUImanager()->AddWorkerCommand(newCommand);
287void G4UImanager::AddWorkerCommand(
G4UIcommand* newCommand)
298 fMasterUImanager()->RemoveWorkerCommand(aCommand);
303void G4UImanager::RemoveWorkerCommand(
G4UIcommand* aCommand)
315 lastRC =
session->GetLastReturnCode();
329 c1 += parameterToken();
331 c1 += parameterToken();
333 std::istringstream is(t1);
337 is >> d1 >> d2 >> d3;
338 Loop(mf, vn, d1, d2, d3);
349 for(
G4double d = initialValue; d <= finalValue; d += stepSize)
351 std::ostringstream os;
359 for(
G4double d = initialValue; d >= finalValue; d += stepSize)
361 std::ostringstream os;
367 Foreach(macroFile, variableName, cd);
379 while(!((ca = parameterToken()).empty()))
386 if(aliasValue[0] ==
'"')
389 if(aliasValue.back() ==
'"')
391 strippedValue = aliasValue.substr(1, aliasValue.length() - 2);
395 strippedValue = aliasValue.substr(1, aliasValue.length() - 1);
397 aliasValue = strippedValue;
406 const char* candidates)
408 G4String candidatesString = candidates;
411 while(!((cd = parameterToken()).empty()))
421 ed <<
"Loop aborted due to a command execution error - "
422 <<
"error code " << lastRC;
433 std::size_t ia = aCommand.find(
"{");
434 std::size_t iz = aCommand.find(
"#");
435 while((ia != std::string::npos) &&
436 ((iz == std::string::npos) || (ia < iz)))
441 std::size_t ib = aCommand.find(
"}");
442 if(ib == std::string::npos)
445 for(std::size_t i = 0; i < ia; ++i)
450 G4cerr <<
"Unmatched alias parenthesis -- command ignored" <<
G4endl;
454 G4String ps = aCommand.substr(ia + 1, aCommand.length() - (ia + 1));
455 std::size_t ic = ps.find(
"{");
456 std::size_t
id = ps.find(
"}");
457 if(ic != std::string::npos && ic <
id)
471 subs = aCommand.substr(0, ia);
473 G4String alis = aCommand.substr(ia + 1, ibx - ia - 1);
474 G4String rems = aCommand.substr(ibx + 1, aCommand.length() - ibx);
478 G4cerr <<
"Alias <" << alis <<
"> not found -- command ignored" <<
G4endl;
482 aCommand = subs + (*alVal) + rems;
483 ia = aCommand.find(
"{");
502 if(verboseLevel != 0)
506 fLastCommandOutputTreated =
false;
513 std::size_t i = aCommand.find(
" ");
514 if(i != std::string::npos)
516 commandString = aCommand.substr(0, i);
517 commandParameter = aCommand.substr(i + 1, aCommand.length() - (i + 1));
521 commandString = aCommand;
525 std::size_t len = commandString.length();
531 if(commandString.substr(ll, 2) ==
"//")
536 commandString.erase(ll, 1);
540 a1 = commandString.substr(0, ll);
541 a2 = commandString.substr(ll + 1, len - ll - 1);
542 commandString = a1 + a2;
552 if(isMaster && bridges !=
nullptr)
554 for(
auto bridge : *bridges)
556 G4int leng = bridge->DirLength();
557 if(commandString.substr(0, leng) == bridge->DirName())
559 return bridge->LocalUI()->ApplyCommand(commandString +
" " +
566 if(targetCommand ==
nullptr)
568 if(ignoreCmdNotFound)
570 if(stackCommandsForBroadcast)
572 commandStack->push_back(commandString +
" " + commandParameter);
584 commandStack->push_back(commandString +
" " + commandParameter);
594 historyFile << aCommand <<
G4endl;
596 if(
G4int(histVec.size()) >= maxHistSize)
598 histVec.erase(histVec.begin());
600 histVec.push_back(aCommand);
603 G4int commandFailureCode = targetCommand->
DoIt(commandParameter);
604 if(commandFailureCode == 0)
607 if(additionalFailureCode > 0)
611 <<
"Error code : " << additionalFailureCode;
613 commandFailureCode += additionalFailureCode;
616 return commandFailureCode;
635 std::size_t i = aCommand.find(
" ");
636 if(i != std::string::npos)
637 { commandString = aCommand.substr(0, i); }
639 { commandString = aCommand; }
641 return treeTop->
FindPath(commandString);
659 historyFile.open((
char*) fileName);
667 saveHistory = historySwitch;
671void G4UImanager::PauseSession(
const char* msg)
675 session->PauseSessionStart(msg);
683 if(comTree !=
nullptr)
698 if(targetDir.back() !=
'/')
708 while(idx < targetDir.length() - 1)
710 std::size_t i = targetDir.find(
"/", idx);
711 G4String targetDirString = targetDir.substr(0, i + 1);
712 comTree = comTree->
GetTree(targetDirString);
713 if(comTree ==
nullptr)
725 if(pauseAtBeginOfEvent)
731 PauseSession(
"BeginOfEvent");
734 if(pauseAtEndOfEvent)
740 PauseSession(
"EndOfEvent");
757 std::size_t i = aLine.find(
" ");
758 G4String aliasName = aLine.substr(0, i);
759 G4String aliasValue = aLine.substr(i + 1, aLine.length() - (i + 1));
760 if(aliasValue[0] ==
'"')
763 if(aliasValue.back() ==
'"')
765 strippedValue = aliasValue.substr(1, aliasValue.length() - 2);
769 strippedValue = aliasValue.substr(1, aliasValue.length() - 1);
771 aliasValue = strippedValue;
801 G4cerr <<
"Directory <" << dir <<
"> is not found." <<
G4endl;
810 std::size_t idxfirst = 0;
811 std::size_t idxend = 0;
813 while((idxend = searchPath.find(
':', idxfirst)) != G4String::npos)
815 pathstring = searchPath.substr(idxfirst, idxend - idxfirst);
816 if(!pathstring.empty())
818 searchDirs.push_back(pathstring);
820 idxfirst = idxend + 1;
823 pathstring = searchPath.substr(idxfirst, searchPath.size() - idxfirst);
824 if(!pathstring.empty())
826 searchDirs.push_back(pathstring);
835 fs.open(fname.c_str(), std::ios::in);
849 for(
const auto& searchDir : searchDirs)
851 G4String fullpath = searchDir +
"/" + fname;
852 if(FileFound(fullpath))
854 macrofile = fullpath;
864 std::vector<G4String>* returnValue = commandStack;
865 commandStack =
new std::vector<G4String>;
875 "G4UIBridge cannot bridge between same object.");
879 bridges->push_back(brg);
912 if(fileN ==
"**Screen**")
918 std::stringstream fn;
919 fn <<
"G4W_" << threadID <<
"_" << fileN;
933 if(fileN ==
"**Screen**")
939 std::stringstream fn;
940 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 * 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)
void CreateHTML(const G4String &="")
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 SetThreadPrefixString(const G4String &prefix="W")
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(const G4String &aPrefix)
void AddNewCommand(G4UIcommand *newCommand)
G4String GetCurrentValues(const char *aCommand)
void SetThreadIgnore(G4int tid=0)
void SetAlias(const char *aliasLine)
G4String FindMacroPath(const G4String &fname) const
void RemoveAlias(const char *aliasName)
G4bool Notify(G4ApplicationState requestedState) override
G4String SolveAlias(const char *aCmd)
void RemoveCommand(G4UIcommand *aCommand)
G4UIcommand * FindCommand(const char *aCommand)
void ParseMacroSearchPath()
static G4UImanager * GetUIpointer()
void RegisterBridge(G4UIbridge *brg)
void SetThreadUseBuffer(G4bool flg=true)
const G4String & GetParameterName() const
void SetDestination(G4coutDestination *dest)
G4String strip_copy(G4String str, char ch=' ')
Return copy of string with leading and trailing characters removed.
void G4SetThreadId(G4int aNewValue)
#define G4ThreadLocalStatic