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; 74 69 75 // ------------------------------------------- << 70 G4int G4UImanager::igThreadID = -1; 76 G4UImanager* G4UImanager::GetUIpointer() << 71 >> 72 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), lastRC(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 = nullptr; >> 103 g4UIWindow = nullptr; 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(nullptr); 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() = nullptr; 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 G4bool G4UImanager::operator==(const G4UImanager &right) const >> 180 { return (this==&right); } >> 181 G4bool 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 == nullptr ) >> 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 == nullptr) 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 == nullptr) 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(size_t 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; 315 lastRC = 0; 286 G4UIsession* previousSession = session->Sess 316 G4UIsession* previousSession = session->SessionStart(); 287 lastRC = session->GetLastReturnCode(); 317 lastRC = session->GetLastReturnCode(); 288 delete session; 318 delete session; 289 session = previousSession; 319 session = previousSession; 290 } 320 } 291 321 292 // ------------------------------------------- << 293 void G4UImanager::LoopS(const char* valueList) 322 void G4UImanager::LoopS(const char* valueList) 294 { 323 { 295 G4String vl = valueList; 324 G4String vl = valueList; 296 G4Tokenizer parameterToken(vl); 325 G4Tokenizer parameterToken(vl); 297 G4String mf = parameterToken(); 326 G4String mf = parameterToken(); 298 G4String vn = parameterToken(); 327 G4String vn = parameterToken(); 299 G4String c1 = parameterToken(); 328 G4String c1 = parameterToken(); 300 c1 += " "; 329 c1 += " "; 301 c1 += parameterToken(); 330 c1 += parameterToken(); 302 c1 += " "; 331 c1 += " "; 303 c1 += parameterToken(); 332 c1 += parameterToken(); 304 const char* t1 = c1; 333 const char* t1 = c1; 305 std::istringstream is(t1); 334 std::istringstream is(t1); 306 G4double d1; 335 G4double d1; 307 G4double d2; 336 G4double d2; 308 G4double d3; 337 G4double d3; 309 is >> d1 >> d2 >> d3; 338 is >> d1 >> d2 >> d3; 310 Loop(mf, vn, d1, d2, d3); << 339 Loop(mf,vn,d1,d2,d3); 311 } 340 } 312 341 313 // ------------------------------------------- << 342 void G4UImanager::Loop(const char * macroFile,const char * variableName, 314 void G4UImanager::Loop(const char* macroFile, << 343 G4double initialValue,G4double finalValue,G4double stepSize) 315 G4double finalValue, G4 << 316 { 344 { 317 G4String cd; 345 G4String cd; 318 if (stepSize > 0) { 346 if (stepSize > 0) { 319 for (G4double d = initialValue; d <= final << 347 for(G4double d=initialValue;d<=finalValue;d+=stepSize) 320 std::ostringstream os; << 348 { 321 os << d; << 349 std::ostringstream os; 322 cd += os.str(); << 350 os << d; 323 cd += " "; << 351 cd += os.str(); 324 } << 352 cd += " "; 325 } << 353 } 326 else { << 354 } else { 327 for (G4double d = initialValue; d >= final << 355 for(G4double d=initialValue;d>=finalValue;d+=stepSize) 328 std::ostringstream os; << 356 { 329 os << d; << 357 std::ostringstream os; 330 cd += os.str(); << 358 os << d; 331 cd += " "; << 359 cd += os.str(); 332 } << 360 cd += " "; >> 361 } 333 } 362 } 334 Foreach(macroFile, variableName, cd); << 363 Foreach(macroFile,variableName,cd); 335 } 364 } 336 365 337 // ------------------------------------------- << 338 void G4UImanager::ForeachS(const char* valueLi 366 void G4UImanager::ForeachS(const char* valueList) 339 { 367 { 340 const G4String& vl = valueList; << 368 G4String vl = valueList; 341 G4Tokenizer parameterToken(vl); 369 G4Tokenizer parameterToken(vl); 342 const G4String& mf = parameterToken(); << 370 G4String mf = parameterToken(); 343 const G4String& vn = parameterToken(); << 371 G4String vn = parameterToken(); 344 G4String c1 = parameterToken(); 372 G4String c1 = parameterToken(); 345 G4String ca; 373 G4String ca; 346 while (!((ca = parameterToken()).empty())) { << 374 while(!((ca=parameterToken()).isNull())) >> 375 { 347 c1 += " "; 376 c1 += " "; 348 c1 += ca; 377 c1 += ca; 349 } 378 } 350 379 351 G4String aliasValue = std::move(c1); << 380 G4String aliasValue = c1; 352 if (aliasValue[0] == '"') { << 381 if(aliasValue(0)=='"') >> 382 { 353 G4String strippedValue; 383 G4String strippedValue; 354 if (aliasValue.back() == '"') { << 384 if(aliasValue(aliasValue.length()-1)=='"') 355 strippedValue = aliasValue.substr(1, ali << 385 { strippedValue = aliasValue(1,aliasValue.length()-2); } 356 } << 386 else 357 else { << 387 { strippedValue = aliasValue(1,aliasValue.length()-1); } 358 strippedValue = aliasValue.substr(1, ali << 388 aliasValue = strippedValue; 359 } << 360 aliasValue = std::move(strippedValue); << 361 } 389 } 362 390 363 // Foreach(mf,vn,c1); << 391 // Foreach(mf,vn,c1); 364 Foreach(mf, vn, aliasValue); << 392 Foreach(mf,vn,aliasValue); 365 } 393 } 366 394 367 // ------------------------------------------- << 395 void G4UImanager::Foreach(const char * macroFile,const char * variableName, 368 void G4UImanager::Foreach(const char* macroFil << 396 const char * candidates) 369 { 397 { 370 G4String candidatesString = candidates; 398 G4String candidatesString = candidates; 371 G4Tokenizer parameterToken(candidatesString) << 399 G4Tokenizer parameterToken( candidatesString ); 372 G4String cd; 400 G4String cd; 373 while (!((cd = parameterToken()).empty())) { << 401 while(!((cd=parameterToken()).isNull())) >> 402 { 374 G4String vl = variableName; 403 G4String vl = variableName; 375 vl += " "; 404 vl += " "; 376 vl += cd; 405 vl += cd; 377 SetAlias(vl); 406 SetAlias(vl); 378 ExecuteMacroFile(FindMacroPath(macroFile)) 407 ExecuteMacroFile(FindMacroPath(macroFile)); 379 if (lastRC != 0) { << 408 if(lastRC!=0) >> 409 { 380 G4ExceptionDescription ed; 410 G4ExceptionDescription ed; 381 ed << "Loop aborted due to a command exe 411 ed << "Loop aborted due to a command execution error - " 382 << "error code " << lastRC; 412 << "error code " << lastRC; 383 G4Exception("G4UImanager::Foreach", "UIM << 413 G4Exception("G4UImanager::Foreach","UIMAN0201",JustWarning,ed); 384 break; 414 break; 385 } 415 } 386 } 416 } 387 } 417 } 388 418 389 // ------------------------------------------- << 419 390 G4String G4UImanager::SolveAlias(const char* a 420 G4String G4UImanager::SolveAlias(const char* aCmd) 391 { 421 { 392 G4String aCommand = aCmd; 422 G4String aCommand = aCmd; 393 std::size_t ia = aCommand.find('{'); << 423 G4int ia = aCommand.index("{"); 394 std::size_t iz = aCommand.find('#'); << 424 G4int iz = aCommand.index("#"); 395 while ((ia != std::string::npos) && ((iz == << 425 while((ia != G4int(std::string::npos))&&((iz==G4int(std::string::npos))||(ia<iz))) >> 426 { 396 G4int ibx = -1; 427 G4int ibx = -1; 397 while (ibx < 0) { << 428 while(ibx<0) 398 std::size_t ib = aCommand.find('}'); << 429 { 399 if (ib == std::string::npos) { << 430 G4int ib = aCommand.index("}"); >> 431 if( ib == G4int(std::string::npos) ) >> 432 { 400 G4cerr << aCommand << G4endl; 433 G4cerr << aCommand << G4endl; 401 for (std::size_t i = 0; i < ia; ++i) { << 434 for(G4int i=0;i<ia;i++) G4cerr << " "; 402 G4cerr << " "; << 403 } << 404 G4cerr << "^" << G4endl; 435 G4cerr << "^" << G4endl; 405 G4cerr << "Unmatched alias parenthesis 436 G4cerr << "Unmatched alias parenthesis -- command ignored" << G4endl; 406 G4String nullStr; 437 G4String nullStr; 407 return nullStr; 438 return nullStr; 408 } 439 } 409 G4String ps = aCommand.substr(ia + 1, aC << 440 G4String ps = aCommand(ia+1,aCommand.length()-(ia+1)); 410 std::size_t ic = ps.find('{'); << 441 G4int ic = ps.index("{"); 411 std::size_t id = ps.find('}'); << 442 G4int id = ps.index("}"); 412 if (ic != std::string::npos && ic < id) << 443 if(ic!=G4int(std::string::npos) && ic < id) 413 ia += ic + 1; << 444 { ia+=ic+1; } 414 } << 445 else 415 else { << 446 { ibx = ib; } 416 ibx = (G4int)ib; << 417 } << 418 } 447 } 419 //--- Here ia represents the position of i 448 //--- Here ia represents the position of innermost "{" 420 //--- and ibx represents corresponding "}" 449 //--- and ibx represents corresponding "}" 421 G4String subs; 450 G4String subs; 422 if (ia > 0) { << 451 if(ia>0) subs = aCommand(0,ia); 423 subs = aCommand.substr(0, ia); << 452 G4String alis = aCommand(ia+1,ibx-ia-1); 424 } << 453 G4String rems = aCommand(ibx+1,aCommand.length()-ibx); 425 G4String alis = aCommand.substr(ia + 1, ib << 454 // G4cout << "<" << subs << "> <" << alis << "> <" << rems << ">" << G4endl; 426 G4String rems = aCommand.substr(ibx + 1, a << 455 G4String* alVal = aliasList->FindAlias(alis); 427 const G4String* alVal = aliasList->FindAli << 456 if(!alVal) 428 if (alVal == nullptr) { << 457 { 429 G4cerr << "Alias <" << alis << "> not fo 458 G4cerr << "Alias <" << alis << "> not found -- command ignored" << G4endl; 430 G4String nullStr; 459 G4String nullStr; 431 return nullStr; 460 return nullStr; 432 } 461 } 433 aCommand = subs + (*alVal) + rems; << 462 aCommand = subs+(*alVal)+rems; 434 ia = aCommand.find('{'); << 463 ia = aCommand.index("{"); 435 } 464 } 436 return aCommand; 465 return aCommand; 437 } 466 } 438 467 439 // ------------------------------------------- << 440 G4int G4UImanager::ApplyCommand(const G4String 468 G4int G4UImanager::ApplyCommand(const G4String& aCmd) 441 { 469 { 442 return ApplyCommand(aCmd.data()); 470 return ApplyCommand(aCmd.data()); 443 } 471 } 444 472 445 // ------------------------------------------- << 473 #include "G4Threading.hh" 446 G4int G4UImanager::ApplyCommand(const char* aC << 474 >> 475 G4int G4UImanager::ApplyCommand(const char * aCmd) 447 { 476 { 448 const G4String& aCommand = SolveAlias(aCmd); << 477 G4String aCommand = SolveAlias(aCmd); 449 if (aCommand.empty()) { << 478 if(aCommand.isNull()) return fAliasNotFound; 450 return fAliasNotFound; << 479 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; 480 G4String commandString; 459 G4String commandParameter; 481 G4String commandParameter; 460 482 461 std::size_t i = aCommand.find(' '); << 483 size_t i = aCommand.index(" "); 462 if (i != std::string::npos) { << 484 if( i != std::string::npos ) 463 commandString = aCommand.substr(0, i); << 485 { 464 commandParameter = aCommand.substr(i + 1, << 486 commandString = aCommand(0,i); >> 487 commandParameter = aCommand(i+1,aCommand.length()-(i+1)); 465 } 488 } 466 else { << 489 else >> 490 { 467 commandString = aCommand; 491 commandString = aCommand; 468 } 492 } 469 493 470 // remove doubled slash 494 // remove doubled slash 471 std::size_t len = commandString.length(); << 495 G4int len = commandString.length(); 472 std::size_t ll = 0; << 496 G4int ll = 0; 473 G4String a1; 497 G4String a1; 474 G4String a2; 498 G4String a2; 475 while (ll < len - 1) { << 499 while(ll<len-1) 476 if (commandString.substr(ll, 2) == "//") { << 500 { 477 if (ll == 0) { << 501 if(commandString(ll,2)=="//") 478 // Safe because index argument always << 502 { 479 commandString.erase(ll, 1); << 503 if(ll==0) 480 } << 504 { commandString.remove(ll,1); } 481 else { << 505 else 482 a1 = commandString.substr(0, ll); << 506 { 483 a2 = commandString.substr(ll + 1, len << 507 a1 = commandString(0,ll); 484 commandString = a1 + a2; << 508 a2 = commandString(ll+1,len-ll-1); >> 509 commandString = a1+a2; 485 } 510 } 486 --len; << 511 len--; 487 } << 488 else { << 489 ++ll; << 490 } 512 } >> 513 else >> 514 { ll++; } 491 } 515 } 492 516 493 if (isMaster && bridges != nullptr) { << 517 if(isMaster&&bridges) 494 for (auto bridge : *bridges) { << 518 { 495 G4int leng = bridge->DirLength(); << 519 std::vector<G4UIbridge*>::iterator itr = bridges->begin(); 496 if (commandString.substr(0, leng) == bri << 520 for(;itr!=bridges->end();itr++) 497 return bridge->LocalUI()->ApplyCommand << 521 { 498 } << 522 G4int leng = (*itr)->DirLength(); >> 523 if(commandString(0,leng)==(*itr)->DirName()) >> 524 { return (*itr)->LocalUI()->ApplyCommand(commandString+" "+commandParameter); } 499 } 525 } 500 } 526 } 501 527 502 G4UIcommand* targetCommand = treeTop->FindPa << 528 G4UIcommand * targetCommand = treeTop->FindPath( commandString ); 503 if (targetCommand == nullptr) { << 529 if( targetCommand == nullptr ) 504 if (ignoreCmdNotFound) { << 530 { 505 if (stackCommandsForBroadcast) { << 531 if(ignoreCmdNotFound) 506 commandStack->push_back(commandString << 532 { 507 } << 533 if(stackCommandsForBroadcast) >> 534 { commandStack->push_back(commandString+" "+commandParameter); } 508 return fCommandSucceeded; 535 return fCommandSucceeded; 509 } 536 } 510 << 537 else 511 return fCommandNotFound; << 538 { return fCommandNotFound; } 512 } 539 } 513 540 514 if (stackCommandsForBroadcast && targetComma << 541 if(stackCommandsForBroadcast && targetCommand->ToBeBroadcasted()) 515 commandStack->push_back(commandString + " << 542 { commandStack->push_back(commandString+" "+commandParameter); } 516 } << 517 543 518 if (!(targetCommand->IsAvailable())) { << 544 if(!(targetCommand->IsAvailable())) 519 return fIllegalApplicationState; << 545 { return fIllegalApplicationState; } 520 } << 521 546 522 if (saveHistory) { << 547 if(saveHistory) historyFile << aCommand << G4endl; 523 historyFile << aCommand << G4endl; << 548 if( G4int(histVec.size()) >= maxHistSize ) 524 } << 549 { histVec.erase(histVec.begin()); } 525 if (G4int(histVec.size()) >= maxHistSize) { << 526 histVec.erase(histVec.begin()); << 527 } << 528 histVec.push_back(aCommand); 550 histVec.push_back(aCommand); 529 551 530 targetCommand->ResetFailure(); 552 targetCommand->ResetFailure(); 531 G4int commandFailureCode = targetCommand->Do << 553 G4int commandFailureCode = targetCommand->DoIt( commandParameter ); 532 if (commandFailureCode == 0) { << 554 if(commandFailureCode==0) >> 555 { 533 G4int additionalFailureCode = targetComman 556 G4int additionalFailureCode = targetCommand->IfCommandFailed(); 534 if (additionalFailureCode > 0) { << 557 if(additionalFailureCode > 0) >> 558 { 535 G4ExceptionDescription msg; 559 G4ExceptionDescription msg; 536 msg << targetCommand->GetFailureDescript 560 msg << targetCommand->GetFailureDescription() << "\n" 537 << "Error code : " << additionalFail 561 << "Error code : " << additionalFailureCode; 538 G4Exception("G4UImanager::ApplyCommand", << 562 G4Exception("G4UImanager::ApplyCommand","UIMAN0123", >> 563 JustWarning,msg); 539 commandFailureCode += additionalFailureC 564 commandFailureCode += additionalFailureCode; 540 } 565 } 541 } 566 } 542 return commandFailureCode; 567 return commandFailureCode; 543 } 568 } 544 569 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 570 void G4UImanager::StoreHistory(const char* fileName) 574 { << 571 { StoreHistory(true,fileName); } 575 StoreHistory(true, fileName); << 576 } << 577 572 578 // ------------------------------------------- << 573 void G4UImanager::StoreHistory(G4bool historySwitch,const char* fileName) 579 void G4UImanager::StoreHistory(G4bool historyS << 580 { 574 { 581 if (historySwitch) { << 575 if(historySwitch) 582 if (saveHistory) { << 576 { 583 historyFile.close(); << 577 if(saveHistory) 584 } << 578 { historyFile.close(); } 585 historyFile.open((char*)fileName); 579 historyFile.open((char*)fileName); 586 saveHistory = true; 580 saveHistory = true; 587 } 581 } 588 else { << 582 else >> 583 { 589 historyFile.close(); 584 historyFile.close(); 590 saveHistory = false; 585 saveHistory = false; 591 } 586 } 592 saveHistory = historySwitch; 587 saveHistory = historySwitch; 593 } 588 } 594 589 595 // ------------------------------------------- << 596 void G4UImanager::PauseSession(const char* msg 590 void G4UImanager::PauseSession(const char* msg) 597 { 591 { 598 if (session != nullptr) { << 592 if(session) session->PauseSessionStart(msg); 599 session->PauseSessionStart(msg); << 600 } << 601 } 593 } 602 594 603 // ------------------------------------------- << 604 void G4UImanager::ListCommands(const char* dir 595 void G4UImanager::ListCommands(const char* direct) 605 { 596 { 606 G4UIcommandTree* comTree = FindDirectory(dir 597 G4UIcommandTree* comTree = FindDirectory(direct); 607 if (comTree != nullptr) { << 598 if(comTree) 608 comTree->List(); << 599 { comTree->List(); } 609 } << 600 else 610 else { << 601 { G4cout << direct << " is not found." << G4endl; } 611 G4cout << direct << " is not found." << G4 << 612 } << 613 } 602 } 614 603 615 // ------------------------------------------- << 616 G4UIcommandTree* G4UImanager::FindDirectory(co 604 G4UIcommandTree* G4UImanager::FindDirectory(const char* dirName) 617 { 605 { 618 const G4String& aDirName = dirName; << 606 G4String aDirName = dirName; 619 G4String targetDir = G4StrUtil::strip_copy(a << 607 G4String targetDir = aDirName.strip(G4String::both); 620 if (targetDir.back() != '/') { << 608 if( targetDir( targetDir.length()-1 ) != '/' ) 621 targetDir += "/"; << 609 { targetDir += "/"; } 622 } << 623 G4UIcommandTree* comTree = treeTop; 610 G4UIcommandTree* comTree = treeTop; 624 if (targetDir == "/") { << 611 if( targetDir == "/" ) 625 return comTree; << 612 { return comTree; } 626 } << 613 G4int idx = 1; 627 std::size_t idx = 1; << 614 while( idx < G4int(targetDir.length())-1 ) 628 while (idx < targetDir.length() - 1) { << 615 { 629 std::size_t i = targetDir.find('/', idx); << 616 G4int i = targetDir.index("/",idx); 630 G4String targetDirString = targetDir.subst << 617 G4String targetDirString = targetDir(0,i+1); 631 comTree = comTree->GetTree(targetDirString 618 comTree = comTree->GetTree(targetDirString); 632 if (comTree == nullptr) { << 619 if( comTree == nullptr ) 633 return nullptr; << 620 { return nullptr; } 634 } << 621 idx = i+1; 635 idx = i + 1; << 636 } 622 } 637 return comTree; 623 return comTree; 638 } 624 } 639 625 640 // ------------------------------------------- << 641 G4bool G4UImanager::Notify(G4ApplicationState 626 G4bool G4UImanager::Notify(G4ApplicationState requestedState) 642 { 627 { 643 if (pauseAtBeginOfEvent) { << 628 //G4cout << G4StateManager::GetStateManager()->GetStateString(requestedState) << " <--- " << G4StateManager::GetStateManager()->GetStateString(G4StateManager::GetStateManager()->GetPreviousState()) << G4endl; 644 if (requestedState == G4State_EventProc << 629 if(pauseAtBeginOfEvent) 645 && G4StateManager::GetStateManager()-> << 630 { 646 { << 631 if(requestedState==G4State_EventProc && 647 PauseSession("BeginOfEvent"); << 632 G4StateManager::GetStateManager()->GetPreviousState()==G4State_GeomClosed) 648 } << 633 { PauseSession("BeginOfEvent"); } 649 } << 634 } 650 if (pauseAtEndOfEvent) { << 635 if(pauseAtEndOfEvent) 651 if (requestedState == G4State_GeomClosed << 636 { 652 && G4StateManager::GetStateManager()-> << 637 if(requestedState==G4State_GeomClosed && 653 { << 638 G4StateManager::GetStateManager()->GetPreviousState()==G4State_EventProc) 654 PauseSession("EndOfEvent"); << 639 { PauseSession("EndOfEvent"); } 655 } << 656 } 640 } 657 return true; 641 return true; 658 } 642 } 659 643 660 // ------------------------------------------- << 644 //void G4UImanager::Interact() 661 void G4UImanager::SetCoutDestination(G4UIsessi << 645 //{ 662 { << 646 // Interact(G4String("G4> ")); 663 G4iosSetDestination(value); << 647 //} 664 } << 648 >> 649 //void G4UImanager::Interact(const char * pC) >> 650 //{ >> 651 // G4cerr << "G4UImanager::Interact() is out of date and is not used anymore." << G4endl; >> 652 // G4cerr << "This method will be removed shortly!!!" << G4endl; >> 653 // G4cerr << "In case of main() use" << G4endl; >> 654 // G4cerr << " G4UIsession * session = new G4UIterminal;" << G4endl; >> 655 // G4cerr << " session->SessionStart();" << G4endl; >> 656 // G4cerr << "In other cases use" << G4endl; >> 657 // G4cerr << " G4StateManager::GetStateManager()->Pause();" << G4endl; >> 658 //} 665 659 666 // ------------------------------------------- << 660 667 void G4UImanager::SetAlias(const char* aliasLi << 661 668 { << 662 void G4UImanager::SetCoutDestination(G4UIsession *const value) 669 const G4String& aLine = aliasLine; << 663 { 670 std::size_t i = aLine.find(' '); << 664 G4coutbuf.SetDestination(value); 671 const G4String& aliasName = aLine.substr(0, << 665 G4cerrbuf.SetDestination(value); 672 G4String aliasValue = aLine.substr(i + 1, aL << 666 } 673 if (aliasValue[0] == '"') { << 667 >> 668 void G4UImanager::SetAlias(const char * aliasLine) >> 669 { >> 670 G4String aLine = aliasLine; >> 671 G4int i = aLine.index(" "); >> 672 G4String aliasName = aLine(0,i); >> 673 G4String aliasValue = aLine(i+1,aLine.length()-(i+1)); >> 674 if(aliasValue(0)=='"') >> 675 { 674 G4String strippedValue; 676 G4String strippedValue; 675 if (aliasValue.back() == '"') { << 677 if(aliasValue(aliasValue.length()-1)=='"') 676 strippedValue = aliasValue.substr(1, ali << 678 { strippedValue = aliasValue(1,aliasValue.length()-2); } 677 } << 679 else 678 else { << 680 { strippedValue = aliasValue(1,aliasValue.length()-1); } 679 strippedValue = aliasValue.substr(1, ali << 681 aliasValue = strippedValue; 680 } << 681 aliasValue = std::move(strippedValue); << 682 } 682 } 683 683 684 aliasList->ChangeAlias(aliasName, aliasValue << 684 aliasList->ChangeAlias(aliasName,aliasValue); 685 } 685 } 686 686 687 // ------------------------------------------- << 687 void G4UImanager::RemoveAlias(const char * aliasName) 688 void G4UImanager::RemoveAlias(const char* alia << 689 { 688 { 690 const G4String& aL = aliasName; << 689 G4String aL = aliasName; 691 G4String targetAlias = G4StrUtil::strip_copy << 690 G4String targetAlias = aL.strip(G4String::both); 692 aliasList->RemoveAlias(targetAlias); 691 aliasList->RemoveAlias(targetAlias); 693 } 692 } 694 693 695 // ------------------------------------------- << 696 void G4UImanager::ListAlias() 694 void G4UImanager::ListAlias() 697 { 695 { 698 aliasList->List(); 696 aliasList->List(); 699 } 697 } 700 698 701 // ------------------------------------------- << 702 void G4UImanager::CreateHTML(const char* dir) 699 void G4UImanager::CreateHTML(const char* dir) 703 { 700 { 704 G4UIcommandTree* tr = FindDirectory(dir); 701 G4UIcommandTree* tr = FindDirectory(dir); 705 if (tr != nullptr) { << 702 if(tr!=0) 706 tr->CreateHTML(); << 703 { tr->CreateHTML(); } 707 } << 704 else 708 else { << 705 { G4cerr << "Directory <" << dir << "> is not found." << G4endl; } 709 G4cerr << "Directory <" << dir << "> is no << 710 } << 711 } 706 } 712 707 713 // ------------------------------------------- << 714 void G4UImanager::ParseMacroSearchPath() 708 void G4UImanager::ParseMacroSearchPath() 715 { 709 { 716 searchDirs.clear(); 710 searchDirs.clear(); 717 711 718 std::size_t idxfirst = 0; << 712 size_t idxfirst = 0; 719 std::size_t idxend = 0; << 713 size_t idxend = 0; 720 G4String pathstring = ""; 714 G4String pathstring = ""; 721 while ((idxend = searchPath.find(':', idxfir << 715 while( (idxend = searchPath.index(':', idxfirst)) != G4String::npos) { 722 pathstring = searchPath.substr(idxfirst, i << 716 pathstring = searchPath.substr(idxfirst, idxend-idxfirst); 723 if (!pathstring.empty()) { << 717 if(pathstring.size() != 0) searchDirs.push_back(pathstring); 724 searchDirs.push_back(pathstring); << 725 } << 726 idxfirst = idxend + 1; 718 idxfirst = idxend + 1; 727 } 719 } 728 720 729 pathstring = searchPath.substr(idxfirst, sea << 721 pathstring = searchPath.substr(idxfirst, searchPath.size()-idxfirst); 730 if (!pathstring.empty()) { << 722 if(pathstring.size() != 0) searchDirs.push_back(pathstring); 731 searchDirs.push_back(std::move(pathstring) << 732 } << 733 } 723 } 734 724 735 // ------------------------------------------- << 725 736 static G4bool FileFound(const G4String& fname) 726 static G4bool FileFound(const G4String& fname) 737 { 727 { 738 G4bool qopen = false; 728 G4bool qopen = false; 739 std::ifstream fs; 729 std::ifstream fs; 740 fs.open(fname.c_str(), std::ios::in); 730 fs.open(fname.c_str(), std::ios::in); 741 if (fs.good()) { << 731 if(fs.good()) { 742 fs.close(); 732 fs.close(); 743 qopen = true; 733 qopen = true; 744 } 734 } 745 return qopen; 735 return qopen; 746 } 736 } 747 737 748 // ------------------------------------------- << 749 G4String G4UImanager::FindMacroPath(const G4St 738 G4String G4UImanager::FindMacroPath(const G4String& fname) const 750 { 739 { 751 G4String macrofile = fname; 740 G4String macrofile = fname; 752 741 753 for (const auto& searchDir : searchDirs) { << 742 for (size_t i = 0; i < searchDirs.size(); i++) { 754 const G4String& fullpath = searchDir + "/" << 743 G4String fullpath = searchDirs[i] + "/" + fname; 755 if (FileFound(fullpath)) { << 744 if ( FileFound(fullpath) ) { 756 macrofile = fullpath; 745 macrofile = fullpath; 757 break; 746 break; 758 } 747 } 759 } 748 } >> 749 760 return macrofile; 750 return macrofile; 761 } 751 } 762 752 763 // ------------------------------------------- << 764 std::vector<G4String>* G4UImanager::GetCommand 753 std::vector<G4String>* G4UImanager::GetCommandStack() 765 { 754 { 766 std::vector<G4String>* returnValue = command 755 std::vector<G4String>* returnValue = commandStack; 767 commandStack = new std::vector<G4String>; 756 commandStack = new std::vector<G4String>; 768 return returnValue; 757 return returnValue; 769 } 758 } 770 759 771 // ------------------------------------------- << 772 void G4UImanager::RegisterBridge(G4UIbridge* b 760 void G4UImanager::RegisterBridge(G4UIbridge* brg) 773 { 761 { 774 if (brg->LocalUI() == this) { << 762 if(brg->LocalUI()==this) 775 G4Exception("G4UImanager::RegisterBridge() << 763 { 776 "G4UIBridge cannot bridge betw << 764 G4Exception("G4UImanager::RegisterBridge()","UI7002",FatalException, 777 } << 765 "G4UIBridge cannot bridge between same object."); 778 else { << 779 bridges->push_back(brg); << 780 } 766 } >> 767 else >> 768 { bridges->push_back(brg); } 781 } 769 } 782 770 783 // ------------------------------------------- << 784 void G4UImanager::SetUpForAThread(G4int tId) 771 void G4UImanager::SetUpForAThread(G4int tId) 785 { 772 { 786 threadID = tId; 773 threadID = tId; 787 G4iosInitialization(); 774 G4iosInitialization(); 788 threadCout = new G4MTcoutDestination(threadI 775 threadCout = new G4MTcoutDestination(threadID); 789 threadCout->SetIgnoreCout(igThreadID); 776 threadCout->SetIgnoreCout(igThreadID); 790 } 777 } 791 778 792 // ------------------------------------------- << 779 void G4UImanager::SetUpForSpecialThread(G4String pref) 793 void G4UImanager::SetUpForSpecialThread(const << 794 { 780 { 795 threadID = G4Threading::GENERICTHREAD_ID; << 781 threadID = G4Threading::GENERICTHREAD_ID; 796 G4Threading::G4SetThreadId(threadID); << 782 G4Threading::G4SetThreadId(threadID); 797 G4iosInitialization(); << 783 G4iosInitialization(); 798 threadCout = new G4MTcoutDestination(threadI << 784 threadCout = new G4MTcoutDestination(threadID); 799 threadCout->SetPrefixString(pref); << 785 threadCout->SetPrefixString(pref); 800 threadCout->SetIgnoreCout(igThreadID); << 786 threadCout->SetIgnoreCout(igThreadID); 801 } 787 } 802 788 803 // ------------------------------------------- << 804 void G4UImanager::SetCoutFileName(const G4Stri 789 void G4UImanager::SetCoutFileName(const G4String& fileN, G4bool ifAppend) 805 { 790 { 806 // for sequential mode, ignore this method. 791 // for sequential mode, ignore this method. 807 if (threadID < 0) { << 792 if(threadID<0) return; 808 return; << 809 } << 810 793 811 if (fileN == "**Screen**") { << 794 if(fileN == "**Screen**") 812 threadCout->SetCoutFileName(fileN, ifAppen << 795 { threadCout->SetCoutFileName(fileN,ifAppend); } 813 } << 796 else 814 else { << 797 { 815 std::stringstream fn; 798 std::stringstream fn; 816 fn << "G4W_" << threadID << "_" << fileN; << 799 fn<<"G4W_"<<threadID<<"_"<<fileN; 817 threadCout->SetCoutFileName(fn.str(), ifAp << 800 threadCout->SetCoutFileName(fn.str(),ifAppend); 818 } 801 } 819 } 802 } 820 803 821 // ------------------------------------------- << 822 void G4UImanager::SetCerrFileName(const G4Stri 804 void G4UImanager::SetCerrFileName(const G4String& fileN, G4bool ifAppend) 823 { 805 { 824 // for sequential mode, ignore this method. 806 // for sequential mode, ignore this method. 825 if (threadID < 0) { << 807 if(threadID<0) return; 826 return; << 827 } << 828 808 829 if (fileN == "**Screen**") { << 809 if(fileN == "**Screen**") 830 threadCout->SetCerrFileName(fileN, ifAppen << 810 { threadCout->SetCerrFileName(fileN,ifAppend); } 831 } << 811 else 832 else { << 812 { 833 std::stringstream fn; 813 std::stringstream fn; 834 fn << "G4W_" << threadID << "_" << fileN; << 814 fn<<"G4W_"<<threadID<<"_"<<fileN; 835 threadCout->SetCerrFileName(fn.str(), ifAp << 815 threadCout->SetCerrFileName(fn.str(),ifAppend); 836 } 816 } 837 } 817 } 838 818 839 // ------------------------------------------- << 840 void G4UImanager::SetThreadPrefixString(const 819 void G4UImanager::SetThreadPrefixString(const G4String& s) 841 { 820 { 842 // for sequential mode, ignore this method. 821 // for sequential mode, ignore this method. 843 if (threadID < 0) { << 822 if(threadID<0) return; 844 return; << 845 } << 846 threadCout->SetPrefixString(s); 823 threadCout->SetPrefixString(s); 847 } 824 } 848 825 849 // ------------------------------------------- << 850 void G4UImanager::SetThreadUseBuffer(G4bool fl 826 void G4UImanager::SetThreadUseBuffer(G4bool flg) 851 { 827 { 852 // for sequential mode, ignore this method. 828 // for sequential mode, ignore this method. 853 if (threadID < 0) { << 829 if(threadID<0) return; 854 return; << 855 } << 856 threadCout->EnableBuffering(flg); 830 threadCout->EnableBuffering(flg); 857 } 831 } 858 832 859 // ------------------------------------------- << 860 void G4UImanager::SetThreadIgnore(G4int tid) 833 void G4UImanager::SetThreadIgnore(G4int tid) 861 { 834 { 862 // for sequential mode, ignore this method. 835 // for sequential mode, ignore this method. 863 if (threadID < 0) { << 836 if(threadID<0) >> 837 { 864 igThreadID = tid; 838 igThreadID = tid; 865 return; 839 return; 866 } 840 } 867 threadCout->SetIgnoreCout(tid); 841 threadCout->SetIgnoreCout(tid); 868 } 842 } 869 843 870 // ------------------------------------------- << 871 void G4UImanager::SetThreadIgnoreInit(G4bool f 844 void G4UImanager::SetThreadIgnoreInit(G4bool flg) 872 { 845 { 873 // for sequential mode, ignore this method. 846 // for sequential mode, ignore this method. 874 if (threadID < 0) { << 847 if(threadID<0) { return; } 875 return; << 876 } << 877 threadCout->SetIgnoreInit(flg); 848 threadCout->SetIgnoreInit(flg); 878 } 849 } 879 850 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 851