Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UImanager.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4UImanager
27//
28// Author: Makoto Asai, 1997
29// --------------------------------------------------------------------
30
31#include "G4UImanager.hh"
32
36#include "G4StateManager.hh"
37#include "G4Threading.hh"
38#include "G4Tokenizer.hh"
39#include "G4UIaliasList.hh"
40#include "G4UIbatch.hh"
41#include "G4UIbridge.hh"
42#include "G4UIcommand.hh"
43#include "G4UIcommandTree.hh"
45#include "G4UIsession.hh"
46#include "G4UnitsMessenger.hh"
47#include "G4ios.hh"
48
49#include <fstream>
50#include <sstream>
51
52G4bool G4UImanager::doublePrecisionStr = false;
53G4int G4UImanager::igThreadID = -1;
54
55// --------------------------------------------------------------------
56G4UImanager*& G4UImanager::fUImanager()
57{
58 G4ThreadLocalStatic G4UImanager* _instance = nullptr;
59 return _instance;
60}
61
62// --------------------------------------------------------------------
63G4bool& G4UImanager::fUImanagerHasBeenKilled()
64{
65 G4ThreadLocalStatic G4bool _instance = false;
66 return _instance;
67}
68
69// --------------------------------------------------------------------
70G4UImanager*& G4UImanager::fMasterUImanager()
71{
72 static G4UImanager* _instance = nullptr;
73 return _instance;
74}
75
76// --------------------------------------------------------------------
78{
79 if (fUImanager() == nullptr) {
80 if (!fUImanagerHasBeenKilled()) {
81 fUImanager() = new G4UImanager;
82 fUImanager()->CreateMessenger();
83 }
84 }
85 return fUImanager();
86}
87
88// --------------------------------------------------------------------
90{
91 return fMasterUImanager();
92}
93
94// --------------------------------------------------------------------
96{
97 treeTop = new G4UIcommandTree("/");
98 aliasList = new G4UIaliasList;
100 commandStack = new std::vector<G4String>;
101}
102
103// --------------------------------------------------------------------
104void G4UImanager::CreateMessenger()
105{
106 UImessenger = new G4UIcontrolMessenger;
107 UnitsMessenger = new G4UnitsMessenger;
108 CoutMessenger = new G4LocalThreadCoutMessenger;
109 ProfileMessenger = new G4ProfilerMessenger;
110}
111
112// --------------------------------------------------------------------
114{
115 if (bridges != nullptr) {
116 for (auto bridge : *bridges) {
117 delete bridge;
118 }
119 delete bridges;
120 }
121 SetCoutDestination(nullptr);
122 histVec.clear();
123 if (saveHistory) {
124 historyFile.close();
125 }
126 delete CoutMessenger;
127 delete ProfileMessenger;
128 delete UnitsMessenger;
129 delete UImessenger;
130 delete treeTop;
131 delete aliasList;
132 fUImanagerHasBeenKilled() = true;
133 fUImanager() = nullptr;
134 if (commandStack != nullptr) {
135 commandStack->clear();
136 delete commandStack;
137 }
138 if (threadID >= 0) {
139 delete threadCout;
141 threadID = -1;
142 }
143}
144
145// --------------------------------------------------------------------
147{
148 doublePrecisionStr = val;
149}
150
151// --------------------------------------------------------------------
153{
154 return doublePrecisionStr;
155}
156
157// --------------------------------------------------------------------
159{
160 G4String theCommand = aCommand;
161 savedCommand = treeTop->FindPath(theCommand);
162 if (savedCommand == nullptr) {
163 G4cerr << "command not found" << G4endl;
164 return G4String();
165 }
166 return savedCommand->GetCurrentValue();
167}
168
169// --------------------------------------------------------------------
170G4String G4UImanager::GetCurrentStringValue(const char* aCommand, G4int parameterNumber,
171 G4bool reGet)
172{
173 if (reGet || savedCommand == nullptr) {
174 savedParameters = GetCurrentValues(aCommand);
175 }
176 G4Tokenizer savedToken(savedParameters);
177 G4String token;
178 for (G4int i_thParameter = 0; i_thParameter < parameterNumber; ++i_thParameter) {
179 token = savedToken();
180 if (token.empty()) {
181 return G4String();
182 }
183 if (token[(size_t)0] == '"') {
184 token.append(" ");
185 token.append(savedToken("\""));
186 }
187 }
188 return token;
189}
190
191// --------------------------------------------------------------------
192G4String G4UImanager::GetCurrentStringValue(const char* aCommand, const char* aParameterName,
193 G4bool reGet)
194{
195 if (reGet || savedCommand == nullptr) {
196 G4String parameterValues = GetCurrentValues(aCommand);
197 }
198 for (G4int i = 0; i < (G4int)savedCommand->GetParameterEntries(); ++i) {
199 if (aParameterName == savedCommand->GetParameter(i)->GetParameterName()) {
200 return GetCurrentStringValue(aCommand, i + 1, false);
201 }
202 }
203 return G4String();
204}
205
206// --------------------------------------------------------------------
207G4int G4UImanager::GetCurrentIntValue(const char* aCommand, const char* aParameterName,
208 G4bool reGet)
209{
210 G4String targetParameter = GetCurrentStringValue(aCommand, aParameterName, reGet);
211 G4int value;
212 const char* t = targetParameter;
213 std::istringstream is(t);
214 is >> value;
215 return value;
216}
217
218// --------------------------------------------------------------------
219G4int G4UImanager::GetCurrentIntValue(const char* aCommand, G4int parameterNumber, G4bool reGet)
220{
221 G4String targetParameter = GetCurrentStringValue(aCommand, parameterNumber, reGet);
222 G4int value;
223 const char* t = targetParameter;
224 std::istringstream is(t);
225 is >> value;
226 return value;
227}
228
229// --------------------------------------------------------------------
230G4double G4UImanager::GetCurrentDoubleValue(const char* aCommand, const char* aParameterName,
231 G4bool reGet)
232{
233 G4String targetParameter = GetCurrentStringValue(aCommand, aParameterName, reGet);
234 G4double value;
235 const char* t = targetParameter;
236 std::istringstream is(t);
237 is >> value;
238 return value;
239}
240
241// --------------------------------------------------------------------
242G4double G4UImanager::GetCurrentDoubleValue(const char* aCommand, G4int parameterNumber,
243 G4bool reGet)
244{
245 G4String targetParameter = GetCurrentStringValue(aCommand, parameterNumber, reGet);
246 G4double value;
247 const char* t = targetParameter;
248 std::istringstream is(t);
249 is >> value;
250 return value;
251}
252
253// --------------------------------------------------------------------
255{
256 treeTop->AddNewCommand(newCommand);
257 if (fMasterUImanager() != nullptr && G4Threading::G4GetThreadId() == 0) {
258 fMasterUImanager()->AddWorkerCommand(newCommand);
259 }
260}
261
262// --------------------------------------------------------------------
263void G4UImanager::AddWorkerCommand(G4UIcommand* newCommand)
264{
265 treeTop->AddNewCommand(newCommand, true);
266}
267
268// --------------------------------------------------------------------
270{
271 treeTop->RemoveCommand(aCommand);
272 if (fMasterUImanager() != nullptr && G4Threading::G4GetThreadId() == 0) {
273 fMasterUImanager()->RemoveWorkerCommand(aCommand);
274 }
275}
276
277// --------------------------------------------------------------------
278void G4UImanager::RemoveWorkerCommand(G4UIcommand* aCommand)
279{
280 treeTop->RemoveCommand(aCommand, true);
281}
282
283// --------------------------------------------------------------------
284void G4UImanager::ExecuteMacroFile(const char* fileName)
285{
286 G4UIsession* batchSession = new G4UIbatch(fileName, session);
287 session = batchSession;
288 lastRC = 0;
289 G4UIsession* previousSession = session->SessionStart();
290 lastRC = session->GetLastReturnCode();
291 delete session;
292 session = previousSession;
293}
294
295// --------------------------------------------------------------------
296void G4UImanager::LoopS(const char* valueList)
297{
298 G4String vl = valueList;
299 G4Tokenizer parameterToken(vl);
300 G4String mf = parameterToken();
301 G4String vn = parameterToken();
302 G4String c1 = parameterToken();
303 c1 += " ";
304 c1 += parameterToken();
305 c1 += " ";
306 c1 += parameterToken();
307 const char* t1 = c1;
308 std::istringstream is(t1);
309 G4double d1;
310 G4double d2;
311 G4double d3;
312 is >> d1 >> d2 >> d3;
313 Loop(mf, vn, d1, d2, d3);
314}
315
316// --------------------------------------------------------------------
317void G4UImanager::Loop(const char* macroFile, const char* variableName, G4double initialValue,
318 G4double finalValue, G4double stepSize)
319{
320 G4String cd;
321 if (stepSize > 0) {
322 for (G4double d = initialValue; d <= finalValue; d += stepSize) {
323 std::ostringstream os;
324 os << d;
325 cd += os.str();
326 cd += " ";
327 }
328 }
329 else {
330 for (G4double d = initialValue; d >= finalValue; d += stepSize) {
331 std::ostringstream os;
332 os << d;
333 cd += os.str();
334 cd += " ";
335 }
336 }
337 Foreach(macroFile, variableName, cd);
338}
339
340// --------------------------------------------------------------------
341void G4UImanager::ForeachS(const char* valueList)
342{
343 G4String vl = valueList;
344 G4Tokenizer parameterToken(vl);
345 G4String mf = parameterToken();
346 G4String vn = parameterToken();
347 G4String c1 = parameterToken();
348 G4String ca;
349 while (!((ca = parameterToken()).empty())) {
350 c1 += " ";
351 c1 += ca;
352 }
353
354 G4String aliasValue = c1;
355 if (aliasValue[0] == '"') {
356 G4String strippedValue;
357 if (aliasValue.back() == '"') {
358 strippedValue = aliasValue.substr(1, aliasValue.length() - 2);
359 }
360 else {
361 strippedValue = aliasValue.substr(1, aliasValue.length() - 1);
362 }
363 aliasValue = strippedValue;
364 }
365
366 // Foreach(mf,vn,c1);
367 Foreach(mf, vn, aliasValue);
368}
369
370// --------------------------------------------------------------------
371void G4UImanager::Foreach(const char* macroFile, const char* variableName, const char* candidates)
372{
373 G4String candidatesString = candidates;
374 G4Tokenizer parameterToken(candidatesString);
375 G4String cd;
376 while (!((cd = parameterToken()).empty())) {
377 G4String vl = variableName;
378 vl += " ";
379 vl += cd;
380 SetAlias(vl);
382 if (lastRC != 0) {
384 ed << "Loop aborted due to a command execution error - "
385 << "error code " << lastRC;
386 G4Exception("G4UImanager::Foreach", "UIMAN0201", JustWarning, ed);
387 break;
388 }
389 }
390}
391
392// --------------------------------------------------------------------
394{
395 G4String aCommand = aCmd;
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))) {
399 G4int ibx = -1;
400 while (ibx < 0) {
401 std::size_t ib = aCommand.find('}');
402 if (ib == std::string::npos) {
403 G4cerr << aCommand << G4endl;
404 for (std::size_t i = 0; i < ia; ++i) {
405 G4cerr << " ";
406 }
407 G4cerr << "^" << G4endl;
408 G4cerr << "Unmatched alias parenthesis -- command ignored" << G4endl;
409 G4String nullStr;
410 return nullStr;
411 }
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) {
416 ia += ic + 1;
417 }
418 else {
419 ibx = (G4int)ib;
420 }
421 }
422 //--- Here ia represents the position of innermost "{"
423 //--- and ibx represents corresponding "}"
424 G4String subs;
425 if (ia > 0) {
426 subs = aCommand.substr(0, ia);
427 }
428 G4String alis = aCommand.substr(ia + 1, ibx - ia - 1);
429 G4String rems = aCommand.substr(ibx + 1, aCommand.length() - ibx);
430 const G4String* alVal = aliasList->FindAlias(alis);
431 if (alVal == nullptr) {
432 G4cerr << "Alias <" << alis << "> not found -- command ignored" << G4endl;
433 G4String nullStr;
434 return nullStr;
435 }
436 aCommand = subs + (*alVal) + rems;
437 ia = aCommand.find('{');
438 }
439 return aCommand;
440}
441
442// --------------------------------------------------------------------
444{
445 return ApplyCommand(aCmd.data());
446}
447
448// --------------------------------------------------------------------
450{
451 G4String aCommand = SolveAlias(aCmd);
452 if (aCommand.empty()) {
453 return fAliasNotFound;
454 }
455 if (verboseLevel != 0) {
456 if (isMaster) {
457 fLastCommandOutputTreated = false;
458 }
459 G4cout << aCommand << G4endl;
460 }
461 G4String commandString;
462 G4String commandParameter;
463
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));
468 }
469 else {
470 commandString = aCommand;
471 }
472
473 // remove doubled slash
474 std::size_t len = commandString.length();
475 std::size_t ll = 0;
476 G4String a1;
477 G4String a2;
478 while (ll < len - 1) {
479 if (commandString.substr(ll, 2) == "//") {
480 if (ll == 0) {
481 // Safe because index argument always 0
482 commandString.erase(ll, 1);
483 }
484 else {
485 a1 = commandString.substr(0, ll);
486 a2 = commandString.substr(ll + 1, len - ll - 1);
487 commandString = a1 + a2;
488 }
489 --len;
490 }
491 else {
492 ++ll;
493 }
494 }
495
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);
501 }
502 }
503 }
504
505 G4UIcommand* targetCommand = treeTop->FindPath(commandString);
506 if (targetCommand == nullptr) {
507 if (ignoreCmdNotFound) {
508 if (stackCommandsForBroadcast) {
509 commandStack->push_back(commandString + " " + commandParameter);
510 }
511 return fCommandSucceeded;
512 }
513
514 return fCommandNotFound;
515 }
516
517 if (stackCommandsForBroadcast && targetCommand->ToBeBroadcasted()) {
518 commandStack->push_back(commandString + " " + commandParameter);
519 }
520
521 if (!(targetCommand->IsAvailable())) {
523 }
524
525 if (saveHistory) {
526 historyFile << aCommand << G4endl;
527 }
528 if (G4int(histVec.size()) >= maxHistSize) {
529 histVec.erase(histVec.begin());
530 }
531 histVec.push_back(aCommand);
532
533 targetCommand->ResetFailure();
534 G4int commandFailureCode = targetCommand->DoIt(commandParameter);
535 if (commandFailureCode == 0) {
536 G4int additionalFailureCode = targetCommand->IfCommandFailed();
537 if (additionalFailureCode > 0) {
539 msg << targetCommand->GetFailureDescription() << "\n"
540 << "Error code : " << additionalFailureCode;
541 G4Exception("G4UImanager::ApplyCommand", "UIMAN0123", JustWarning, msg);
542 commandFailureCode += additionalFailureCode;
543 }
544 }
545 return commandFailureCode;
546}
547
548// --------------------------------------------------------------------
550{
551 return FindCommand(aCmd.data());
552}
553
554// --------------------------------------------------------------------
556{
557 G4String aCommand = SolveAlias(aCmd);
558 if (aCommand.empty()) {
559 return nullptr;
560 }
561
562 G4String commandString;
563
564 std::size_t i = aCommand.find(' ');
565 if (i != std::string::npos) {
566 commandString = aCommand.substr(0, i);
567 }
568 else {
569 commandString = aCommand;
570 }
571
572 return treeTop->FindPath(commandString);
573}
574
575// --------------------------------------------------------------------
576void G4UImanager::StoreHistory(const char* fileName)
577{
578 StoreHistory(true, fileName);
579}
580
581// --------------------------------------------------------------------
582void G4UImanager::StoreHistory(G4bool historySwitch, const char* fileName)
583{
584 if (historySwitch) {
585 if (saveHistory) {
586 historyFile.close();
587 }
588 historyFile.open((char*)fileName);
589 saveHistory = true;
590 }
591 else {
592 historyFile.close();
593 saveHistory = false;
594 }
595 saveHistory = historySwitch;
596}
597
598// --------------------------------------------------------------------
599void G4UImanager::PauseSession(const char* msg)
600{
601 if (session != nullptr) {
602 session->PauseSessionStart(msg);
603 }
604}
605
606// --------------------------------------------------------------------
607void G4UImanager::ListCommands(const char* direct)
608{
609 G4UIcommandTree* comTree = FindDirectory(direct);
610 if (comTree != nullptr) {
611 comTree->List();
612 }
613 else {
614 G4cout << direct << " is not found." << G4endl;
615 }
616}
617
618// --------------------------------------------------------------------
619G4UIcommandTree* G4UImanager::FindDirectory(const char* dirName)
620{
621 G4String aDirName = dirName;
622 G4String targetDir = G4StrUtil::strip_copy(aDirName);
623 if (targetDir.back() != '/') {
624 targetDir += "/";
625 }
626 G4UIcommandTree* comTree = treeTop;
627 if (targetDir == "/") {
628 return comTree;
629 }
630 std::size_t idx = 1;
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) {
636 return nullptr;
637 }
638 idx = i + 1;
639 }
640 return comTree;
641}
642
643// --------------------------------------------------------------------
645{
646 if (pauseAtBeginOfEvent) {
647 if (requestedState == G4State_EventProc
648 && G4StateManager::GetStateManager()->GetPreviousState() == G4State_GeomClosed)
649 {
650 PauseSession("BeginOfEvent");
651 }
652 }
653 if (pauseAtEndOfEvent) {
654 if (requestedState == G4State_GeomClosed
655 && G4StateManager::GetStateManager()->GetPreviousState() == G4State_EventProc)
656 {
657 PauseSession("EndOfEvent");
658 }
659 }
660 return true;
661}
662
663// --------------------------------------------------------------------
665{
666 G4iosSetDestination(value);
667}
668
669// --------------------------------------------------------------------
670void G4UImanager::SetAlias(const char* aliasLine)
671{
672 G4String aLine = aliasLine;
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] == '"') {
677 G4String strippedValue;
678 if (aliasValue.back() == '"') {
679 strippedValue = aliasValue.substr(1, aliasValue.length() - 2);
680 }
681 else {
682 strippedValue = aliasValue.substr(1, aliasValue.length() - 1);
683 }
684 aliasValue = strippedValue;
685 }
686
687 aliasList->ChangeAlias(aliasName, aliasValue);
688}
689
690// --------------------------------------------------------------------
691void G4UImanager::RemoveAlias(const char* aliasName)
692{
693 G4String aL = aliasName;
694 G4String targetAlias = G4StrUtil::strip_copy(aL);
695 aliasList->RemoveAlias(targetAlias);
696}
697
698// --------------------------------------------------------------------
700{
701 aliasList->List();
702}
703
704// --------------------------------------------------------------------
705void G4UImanager::CreateHTML(const char* dir)
706{
707 G4UIcommandTree* tr = FindDirectory(dir);
708 if (tr != nullptr) {
709 tr->CreateHTML();
710 }
711 else {
712 G4cerr << "Directory <" << dir << "> is not found." << G4endl;
713 }
714}
715
716// --------------------------------------------------------------------
718{
719 searchDirs.clear();
720
721 std::size_t idxfirst = 0;
722 std::size_t idxend = 0;
723 G4String pathstring = "";
724 while ((idxend = searchPath.find(':', idxfirst)) != G4String::npos) {
725 pathstring = searchPath.substr(idxfirst, idxend - idxfirst);
726 if (!pathstring.empty()) {
727 searchDirs.push_back(pathstring);
728 }
729 idxfirst = idxend + 1;
730 }
731
732 pathstring = searchPath.substr(idxfirst, searchPath.size() - idxfirst);
733 if (!pathstring.empty()) {
734 searchDirs.push_back(pathstring);
735 }
736}
737
738// --------------------------------------------------------------------
739static G4bool FileFound(const G4String& fname)
740{
741 G4bool qopen = false;
742 std::ifstream fs;
743 fs.open(fname.c_str(), std::ios::in);
744 if (fs.good()) {
745 fs.close();
746 qopen = true;
747 }
748 return qopen;
749}
750
751// --------------------------------------------------------------------
753{
754 G4String macrofile = fname;
755
756 for (const auto& searchDir : searchDirs) {
757 G4String fullpath = searchDir + "/" + fname;
758 if (FileFound(fullpath)) {
759 macrofile = fullpath;
760 break;
761 }
762 }
763 return macrofile;
764}
765
766// --------------------------------------------------------------------
767std::vector<G4String>* G4UImanager::GetCommandStack()
768{
769 std::vector<G4String>* returnValue = commandStack;
770 commandStack = new std::vector<G4String>;
771 return returnValue;
772}
773
774// --------------------------------------------------------------------
776{
777 if (brg->LocalUI() == this) {
778 G4Exception("G4UImanager::RegisterBridge()", "UI7002", FatalException,
779 "G4UIBridge cannot bridge between same object.");
780 }
781 else {
782 bridges->push_back(brg);
783 }
784}
785
786// --------------------------------------------------------------------
788{
789 threadID = tId;
791 threadCout = new G4MTcoutDestination(threadID);
792 threadCout->SetIgnoreCout(igThreadID);
793}
794
795// --------------------------------------------------------------------
797{
801 threadCout = new G4MTcoutDestination(threadID);
802 threadCout->SetPrefixString(pref);
803 threadCout->SetIgnoreCout(igThreadID);
804}
805
806// --------------------------------------------------------------------
807void G4UImanager::SetCoutFileName(const G4String& fileN, G4bool ifAppend)
808{
809 // for sequential mode, ignore this method.
810 if (threadID < 0) {
811 return;
812 }
813
814 if (fileN == "**Screen**") {
815 threadCout->SetCoutFileName(fileN, ifAppend);
816 }
817 else {
818 std::stringstream fn;
819 fn << "G4W_" << threadID << "_" << fileN;
820 threadCout->SetCoutFileName(fn.str(), ifAppend);
821 }
822}
823
824// --------------------------------------------------------------------
825void G4UImanager::SetCerrFileName(const G4String& fileN, G4bool ifAppend)
826{
827 // for sequential mode, ignore this method.
828 if (threadID < 0) {
829 return;
830 }
831
832 if (fileN == "**Screen**") {
833 threadCout->SetCerrFileName(fileN, ifAppend);
834 }
835 else {
836 std::stringstream fn;
837 fn << "G4W_" << threadID << "_" << fileN;
838 threadCout->SetCerrFileName(fn.str(), ifAppend);
839 }
840}
841
842// --------------------------------------------------------------------
844{
845 // for sequential mode, ignore this method.
846 if (threadID < 0) {
847 return;
848 }
849 threadCout->SetPrefixString(s);
850}
851
852// --------------------------------------------------------------------
854{
855 // for sequential mode, ignore this method.
856 if (threadID < 0) {
857 return;
858 }
859 threadCout->EnableBuffering(flg);
860}
861
862// --------------------------------------------------------------------
864{
865 // for sequential mode, ignore this method.
866 if (threadID < 0) {
867 igThreadID = tid;
868 return;
869 }
870 threadCout->SetIgnoreCout(tid);
871}
872
873// --------------------------------------------------------------------
875{
876 // for sequential mode, ignore this method.
877 if (threadID < 0) {
878 return;
879 }
880 threadCout->SetIgnoreInit(flg);
881}
882
884{
885 // There may be no session - pure batch mode (session == nullptr)
886 // If there is a session, it may be a batch session used for processing macros.
887 // Find base session of this hierarchy of batch sessions.
888 G4UIsession* baseSession = session;
889 while (auto aBatchSession = dynamic_cast<G4UIbatch*>(baseSession)) {
890 auto previousSession = aBatchSession->GetPreviousSession();
891 if (previousSession == nullptr) {
892 // No previouse session - aBatchSession is the desired base session
893 baseSession = aBatchSession;
894 break;
895 }
896 // There is a previous session, which may or may not be a batch.
897 // If not, it will be our desired base - so record and test again.
898 baseSession = previousSession;
899 }
900 return baseSession;
901}
G4ApplicationState
@ G4State_EventProc
@ G4State_GeomClosed
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
@ fCommandNotFound
@ fAliasNotFound
@ fIllegalApplicationState
@ fCommandSucceeded
void G4iosFinalization()
Definition G4ios.cc:266
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
void G4iosSetDestination(G4coutDestination *sink)
Definition G4ios.cc:270
G4GLOB_DLL std::ostream G4cout
void G4iosInitialization()
Definition G4ios.cc:265
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 List() const
void ChangeAlias(const char *aliasName, const char *aliasValue)
void RemoveAlias(const char *aliasName)
const G4String * FindAlias(const char *aliasName) const
G4UImanager * LocalUI() const
Definition G4UIbridge.hh:54
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
G4int IfCommandFailed()
virtual G4int DoIt(G4String parameterList)
void ResetFailure()
G4bool IsAvailable()
const G4String & GetFailureDescription()
G4String GetCurrentValue()
~G4UImanager() override
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 ListAlias()
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
G4int G4GetThreadId()
void G4SetThreadId(G4int aNewValue)
#define G4ThreadLocalStatic
Definition tls.hh:76