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