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