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