52G4bool G4UImanager::doublePrecisionStr =
false;
53G4int G4UImanager::igThreadID = -1;
63G4bool& G4UImanager::fUImanagerHasBeenKilled()
79 if (fUImanager() ==
nullptr) {
80 if (!fUImanagerHasBeenKilled()) {
82 fUImanager()->CreateMessenger();
91 return fMasterUImanager();
100 commandStack =
new std::vector<G4String>;
104void G4UImanager::CreateMessenger()
115 if (bridges !=
nullptr) {
116 for (
auto bridge : *bridges) {
126 delete CoutMessenger;
127 delete ProfileMessenger;
128 delete UnitsMessenger;
132 fUImanagerHasBeenKilled() =
true;
133 fUImanager() =
nullptr;
134 if (commandStack !=
nullptr) {
135 commandStack->clear();
148 doublePrecisionStr = val;
154 return doublePrecisionStr;
161 savedCommand = treeTop->
FindPath(theCommand);
162 if (savedCommand ==
nullptr) {
173 if (reGet || savedCommand ==
nullptr) {
178 for (
G4int i_thParameter = 0; i_thParameter < parameterNumber; ++i_thParameter) {
179 token = savedToken();
183 if (token[(
size_t)0] ==
'"') {
185 token.append(savedToken(
"\""));
195 if (reGet || savedCommand ==
nullptr) {
212 const char* t = targetParameter;
213 std::istringstream is(t);
223 const char* t = targetParameter;
224 std::istringstream is(t);
235 const char* t = targetParameter;
236 std::istringstream is(t);
247 const char* t = targetParameter;
248 std::istringstream is(t);
258 fMasterUImanager()->AddWorkerCommand(newCommand);
263void G4UImanager::AddWorkerCommand(
G4UIcommand* newCommand)
273 fMasterUImanager()->RemoveWorkerCommand(aCommand);
278void G4UImanager::RemoveWorkerCommand(
G4UIcommand* aCommand)
290 lastRC =
session->GetLastReturnCode();
304 c1 += parameterToken();
306 c1 += parameterToken();
308 std::istringstream is(t1);
312 is >> d1 >> d2 >> d3;
313 Loop(mf, vn, d1, d2, d3);
322 for (
G4double d = initialValue; d <= finalValue; d += stepSize) {
323 std::ostringstream os;
330 for (
G4double d = initialValue; d >= finalValue; d += stepSize) {
331 std::ostringstream os;
337 Foreach(macroFile, variableName, cd);
349 while (!((ca = parameterToken()).empty())) {
355 if (aliasValue[0] ==
'"') {
357 if (aliasValue.back() ==
'"') {
358 strippedValue = aliasValue.substr(1, aliasValue.length() - 2);
361 strippedValue = aliasValue.substr(1, aliasValue.length() - 1);
363 aliasValue = strippedValue;
373 G4String candidatesString = candidates;
376 while (!((cd = parameterToken()).empty())) {
384 ed <<
"Loop aborted due to a command execution error - "
385 <<
"error code " << lastRC;
396 std::size_t ia = aCommand.find(
'{');
397 std::size_t iz = aCommand.find(
'#');
398 while ((ia != std::string::npos) && ((iz == std::string::npos) || (ia < iz))) {
401 std::size_t ib = aCommand.find(
'}');
402 if (ib == std::string::npos) {
404 for (std::size_t i = 0; i < ia; ++i) {
408 G4cerr <<
"Unmatched alias parenthesis -- command ignored" <<
G4endl;
412 G4String ps = aCommand.substr(ia + 1, aCommand.length() - (ia + 1));
413 std::size_t ic = ps.find(
'{');
414 std::size_t
id = ps.find(
'}');
415 if (ic != std::string::npos && ic <
id) {
426 subs = aCommand.substr(0, ia);
428 G4String alis = aCommand.substr(ia + 1, ibx - ia - 1);
429 G4String rems = aCommand.substr(ibx + 1, aCommand.length() - ibx);
431 if (alVal ==
nullptr) {
432 G4cerr <<
"Alias <" << alis <<
"> not found -- command ignored" <<
G4endl;
436 aCommand = subs + (*alVal) + rems;
437 ia = aCommand.find(
'{');
452 if (aCommand.empty()) {
455 if (verboseLevel != 0) {
457 fLastCommandOutputTreated =
false;
464 std::size_t i = aCommand.find(
' ');
465 if (i != std::string::npos) {
466 commandString = aCommand.substr(0, i);
467 commandParameter = aCommand.substr(i + 1, aCommand.length() - (i + 1));
470 commandString = aCommand;
474 std::size_t len = commandString.length();
478 while (ll < len - 1) {
479 if (commandString.substr(ll, 2) ==
"//") {
482 commandString.erase(ll, 1);
485 a1 = commandString.substr(0, ll);
486 a2 = commandString.substr(ll + 1, len - ll - 1);
487 commandString = a1 + a2;
496 if (isMaster && bridges !=
nullptr) {
497 for (
auto bridge : *bridges) {
498 G4int leng = bridge->DirLength();
499 if (commandString.substr(0, leng) == bridge->DirName()) {
500 return bridge->LocalUI()->ApplyCommand(commandString +
" " + commandParameter);
506 if (targetCommand ==
nullptr) {
507 if (ignoreCmdNotFound) {
508 if (stackCommandsForBroadcast) {
509 commandStack->push_back(commandString +
" " + commandParameter);
518 commandStack->push_back(commandString +
" " + commandParameter);
526 historyFile << aCommand <<
G4endl;
528 if (
G4int(histVec.size()) >= maxHistSize) {
529 histVec.erase(histVec.begin());
531 histVec.push_back(aCommand);
534 G4int commandFailureCode = targetCommand->
DoIt(commandParameter);
535 if (commandFailureCode == 0) {
537 if (additionalFailureCode > 0) {
540 <<
"Error code : " << additionalFailureCode;
542 commandFailureCode += additionalFailureCode;
545 return commandFailureCode;
558 if (aCommand.empty()) {
564 std::size_t i = aCommand.find(
' ');
565 if (i != std::string::npos) {
566 commandString = aCommand.substr(0, i);
569 commandString = aCommand;
572 return treeTop->
FindPath(commandString);
588 historyFile.open((
char*)fileName);
595 saveHistory = historySwitch;
599void G4UImanager::PauseSession(
const char* msg)
602 session->PauseSessionStart(msg);
610 if (comTree !=
nullptr) {
622 G4String targetDir = G4StrUtil::strip_copy(aDirName);
623 if (targetDir.back() !=
'/') {
627 if (targetDir ==
"/") {
631 while (idx < targetDir.length() - 1) {
632 std::size_t i = targetDir.find(
'/', idx);
633 G4String targetDirString = targetDir.substr(0, i + 1);
634 comTree = comTree->
GetTree(targetDirString);
635 if (comTree ==
nullptr) {
646 if (pauseAtBeginOfEvent) {
650 PauseSession(
"BeginOfEvent");
653 if (pauseAtEndOfEvent) {
657 PauseSession(
"EndOfEvent");
673 std::size_t i = aLine.find(
' ');
674 G4String aliasName = aLine.substr(0, i);
675 G4String aliasValue = aLine.substr(i + 1, aLine.length() - (i + 1));
676 if (aliasValue[0] ==
'"') {
678 if (aliasValue.back() ==
'"') {
679 strippedValue = aliasValue.substr(1, aliasValue.length() - 2);
682 strippedValue = aliasValue.substr(1, aliasValue.length() - 1);
684 aliasValue = strippedValue;
694 G4String targetAlias = G4StrUtil::strip_copy(aL);
712 G4cerr <<
"Directory <" << dir <<
"> is not found." <<
G4endl;
721 std::size_t idxfirst = 0;
722 std::size_t idxend = 0;
724 while ((idxend = searchPath.find(
':', idxfirst)) != G4String::npos) {
725 pathstring = searchPath.substr(idxfirst, idxend - idxfirst);
726 if (!pathstring.empty()) {
727 searchDirs.push_back(pathstring);
729 idxfirst = idxend + 1;
732 pathstring = searchPath.substr(idxfirst, searchPath.size() - idxfirst);
733 if (!pathstring.empty()) {
734 searchDirs.push_back(pathstring);
743 fs.open(fname.c_str(), std::ios::in);
756 for (
const auto& searchDir : searchDirs) {
757 G4String fullpath = searchDir +
"/" + fname;
758 if (FileFound(fullpath)) {
759 macrofile = fullpath;
769 std::vector<G4String>* returnValue = commandStack;
770 commandStack =
new std::vector<G4String>;
779 "G4UIBridge cannot bridge between same object.");
782 bridges->push_back(brg);
814 if (fileN ==
"**Screen**") {
818 std::stringstream fn;
819 fn <<
"G4W_" << threadID <<
"_" << fileN;
832 if (fileN ==
"**Screen**") {
836 std::stringstream fn;
837 fn <<
"G4W_" << threadID <<
"_" << fileN;
889 while (
auto aBatchSession =
dynamic_cast<G4UIbatch*
>(baseSession)) {
890 auto previousSession = aBatchSession->GetPreviousSession();
891 if (previousSession ==
nullptr) {
893 baseSession = aBatchSession;
898 baseSession = previousSession;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
@ fIllegalApplicationState
G4GLOB_DLL std::ostream G4cerr
void G4iosSetDestination(G4coutDestination *sink)
G4GLOB_DLL std::ostream G4cout
void G4iosInitialization()
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()
void ChangeAlias(const char *aliasName, const char *aliasValue)
void RemoveAlias(const char *aliasName)
const G4String * FindAlias(const char *aliasName) const
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)
G4UIsession * GetBaseSession() const
void SetThreadUseBuffer(G4bool flg=true)
const G4String & GetParameterName() const
void G4SetThreadId(G4int aNewValue)
#define G4ThreadLocalStatic