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