Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // 27 28 // /vis/multithreading commands - John Allison 29th September 2015 29 30 #include "G4VisCommandsMultithreading.hh" 31 32 #include "G4Threading.hh" 33 #include "G4UIcmdWithAnInteger.hh" 34 #include "G4UIcmdWithAString.hh" 35 #include "G4VisManager.hh" 36 37 // For future use with additional G4ios logging streams 38 #define G4warn G4cout 39 40 ////////////// /vis/multithreading/actionOnEventQueueFull /////////////////////////////////////// 41 42 G4VisCommandMultithreadingActionOnEventQueueFull::G4VisCommandMultithreadingActionOnEventQueueFull() 43 { 44 G4bool omitable; 45 fpCommand = new G4UIcmdWithAString("/vis/multithreading/actionOnEventQueueFull", this); 46 fpCommand->SetGuidance("When event queue for drawing gets full:"); 47 fpCommand->SetGuidance("wait: event processing waits for vis manager to catch up."); 48 fpCommand->SetGuidance("discard: events are discarded for drawing."); 49 fpCommand->SetCandidates("wait discard"); 50 fpCommand->SetParameterName ("wait", omitable = true); 51 fpCommand->SetDefaultValue ("wait"); 52 } 53 54 G4VisCommandMultithreadingActionOnEventQueueFull::~G4VisCommandMultithreadingActionOnEventQueueFull() 55 { 56 delete fpCommand; 57 } 58 59 G4String G4VisCommandMultithreadingActionOnEventQueueFull::GetCurrentValue(G4UIcommand*) 60 { 61 return ""; 62 } 63 64 void G4VisCommandMultithreadingActionOnEventQueueFull::SetNewValue(G4UIcommand*, G4String newValue) 65 { 66 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 67 68 // Only relevant in a MT application 69 if(!G4Threading::IsMultithreadedApplication()) { 70 if (verbosity >= G4VisManager::warnings) { 71 G4warn << "command /vis/multithreading/actionOnEventQueueFull ignored in sequential mode" << G4endl; 72 } 73 return; 74 } 75 76 if (newValue == "wait") { 77 fpVisManager->SetWaitOnEventQueueFull(true); 78 } else { 79 fpVisManager->SetWaitOnEventQueueFull(false); 80 } 81 82 if (verbosity >= G4VisManager::confirmations) { 83 G4cout << 84 "When event queue for drawing is full,"; 85 if (fpVisManager->GetWaitOnEventQueueFull()) { 86 G4cout << " event processing will wait"; 87 } else { 88 G4cout << " events will be discarded for drawing"; 89 } 90 G4cout << G4endl; 91 } 92 } 93 94 ////////////// /vis/multithreading/maxEventQueueSize /////////////////////////////////////// 95 96 G4VisCommandMultithreadingMaxEventQueueSize::G4VisCommandMultithreadingMaxEventQueueSize() 97 { 98 G4bool omitable; 99 fpCommand = new G4UIcmdWithAnInteger("/vis/multithreading/maxEventQueueSize", this); 100 fpCommand->SetGuidance 101 ("Defines maximum event queue size. N <=0 means \"unlimited\"."); 102 fpCommand->SetGuidance 103 ("If adding an event to the visualisation event queue would cause the" 104 " queue size to exceed this value:"); 105 fpCommand->SetGuidance 106 (" if actionOnEventQueueFull==wait the worker threads are paused for a short" 107 " time to give the visualisation manager a chance to catch up."); 108 fpCommand->SetGuidance 109 (" if actionOnEventQueueFull==discard the event is discarded for drawing."); 110 fpCommand->SetParameterName ("maxSize", omitable = true); 111 fpCommand->SetDefaultValue (100); 112 } 113 114 G4VisCommandMultithreadingMaxEventQueueSize::~G4VisCommandMultithreadingMaxEventQueueSize() 115 { 116 delete fpCommand; 117 } 118 119 G4String G4VisCommandMultithreadingMaxEventQueueSize::GetCurrentValue(G4UIcommand*) 120 { 121 return ""; 122 } 123 124 void G4VisCommandMultithreadingMaxEventQueueSize::SetNewValue(G4UIcommand*, G4String newValue) 125 { 126 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); 127 128 // Only relevant in a MT application 129 if(!G4Threading::IsMultithreadedApplication()) { 130 if (verbosity >= G4VisManager::warnings) { 131 G4warn << "command /vis/multithreading/maxEventQueueSize ignored in sequential mode" << G4endl; 132 } 133 return; 134 } 135 136 G4int maxEventQueueSize = fpCommand->GetNewIntValue(newValue); 137 fpVisManager->SetMaxEventQueueSize(maxEventQueueSize); 138 139 if (verbosity >= G4VisManager::confirmations) { 140 G4cout << 141 "Maximum event queue size has been set to " 142 << fpVisManager->GetMaxEventQueueSize() 143 << G4endl; 144 } 145 } 146