Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/intercoms/src/G4UImanager.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /intercoms/src/G4UImanager.cc (Version 11.3.0) and /intercoms/src/G4UImanager.cc (Version 10.0.p2)


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