Import Geant4 10.4.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2017-06-30 10:49:55 +02:00
parent 3a5407696b
commit 1a1316fea4
2180 changed files with 237880 additions and 59109 deletions
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4AdjointPrimaryGeneratorAction.cc 102566 2017-02-09 08:35:24Z gcosmo $
// $Id: G4AdjointPrimaryGeneratorAction.cc 102435 2017-01-27 08:28:15Z gcosmo $
//
/////////////////////////////////////////////////////////////////////////////
// Class Name: G4AdjointPrimaryGeneratorAction
+1 -1
View File
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4AdjointSimManager.cc 102566 2017-02-09 08:35:24Z gcosmo $
// $Id: G4AdjointSimManager.cc 102435 2017-01-27 08:28:15Z gcosmo $
//
/////////////////////////////////////////////////////////////////////////////
// Class Name: G4AdjointCrossSurfChecker
+1 -1
View File
@@ -433,7 +433,7 @@ void G4MTRunManager::SetUserInitialization(G4VUserDetectorConstruction *userDC)
void G4MTRunManager::SetUserAction(G4UserRunAction* userAction)
{
G4RunManager::SetUserAction(userAction);
userAction->SetMaster();
if(userAction) userAction->SetMaster();
}
void G4MTRunManager::SetUserAction(G4VUserPrimaryGeneratorAction* /*userAction*/)
+2
View File
@@ -97,6 +97,8 @@ G4PhysicsListWorkspace::InitialiseWorkspace()
// just copy the contents !!
fpVUPLSIM->NewSubInstances();
fpVPCSIM->NewSubInstances();
// The following line is fundamental! If we call NewSubInstances it will not work
// See: https://jira-geant4.kek.jp/browse/DEV-284
fpVMPLSIM->WorkerCopySubInstanceArray();
// Additional initialization if needed - beyond copying memory
+7 -1
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4RunManager.cc 99345 2016-09-19 06:51:23Z gcosmo $
// $Id: G4RunManager.cc 103291 2017-03-24 14:00:49Z gcosmo $
//
//
@@ -963,6 +963,12 @@ void G4RunManager::ReinitializeGeometry(G4bool destroyFirst, G4bool prop)
{
kernel->GeometryHasBeenModified();
geometryInitialized = false;
// Notify the VisManager as well
if(G4Threading::IsMasterThread())
{
G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
if(pVVisManager) pVVisManager->GeometryHasChanged();
}
}
}
+25 -9
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4RunManagerKernel.cc 102620 2017-02-10 08:11:22Z gcosmo $
// $Id: G4RunManagerKernel.cc 103291 2017-03-24 14:00:49Z gcosmo $
//
//
@@ -37,7 +37,9 @@
#include "G4ExceptionHandler.hh"
#include "G4PrimaryTransformer.hh"
#include "G4GeometryManager.hh"
#include "G4FieldManagerStore.hh"
#include "G4NavigationHistoryPool.hh"
#include "G4PathFinder.hh"
#include "G4TransportationManager.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
@@ -292,6 +294,20 @@ G4RunManagerKernel::~G4RunManagerKernel()
G4UnitDefinition::ClearUnitsTable();
if(verboseLevel>1) G4cout << "Units table cleared." << G4endl;
// deletion of path-finder field-manager store, geometry and transportation manager
G4PathFinder* pFinder = G4PathFinder::GetInstanceIfExist();
if (pFinder) delete pFinder;
G4FieldManagerStore* fmStore = G4FieldManagerStore::GetInstanceIfExist();
if (fmStore) delete fmStore;
G4GeometryManager* gManager = G4GeometryManager::GetInstanceIfExist();
if (gManager) delete gManager;
G4TransportationManager* tManager = G4TransportationManager::GetInstanceIfExist();
if (tManager)
{
delete tManager;
if(verboseLevel>1) G4cout << "TransportationManager deleted." << G4endl;
}
// deletion of navigation levels
if(verboseLevel>1) G4NavigationHistoryPool::GetInstance()->Print();
delete G4NavigationHistoryPool::GetInstance();
@@ -347,10 +363,10 @@ void G4RunManagerKernel::WorkerDefineWorldVolume(G4VPhysicalVolume* worldVol,
G4ApplicationState currentState = stateManager->GetCurrentState();
if(currentState!=G4State_Init)
{
G4cout << "Current application state is "
<< stateManager->GetStateString(currentState) << G4endl;
if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
{
G4cout << "Current application state is "
<< stateManager->GetStateString(currentState) << G4endl;
G4Exception("G4RunManagerKernel::DefineWorldVolume",
"DefineWorldVolumeAtIncorrectState",
FatalException,
@@ -361,8 +377,8 @@ void G4RunManagerKernel::WorkerDefineWorldVolume(G4VPhysicalVolume* worldVol,
// "DefineWorldVolumeAtIncorrectState",
// JustWarning,
// "Geant4 kernel is not Init state : Assuming Init state.");
G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
<<G4endl;
//G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
// <<G4endl;
stateManager->SetNewState(G4State_Init);
}
}
@@ -411,10 +427,10 @@ void G4RunManagerKernel::DefineWorldVolume(G4VPhysicalVolume* worldVol,
G4ApplicationState currentState = stateManager->GetCurrentState();
if(currentState!=G4State_Init)
{
G4cout << "Current application state is "
<< stateManager->GetStateString(currentState) << G4endl;
if(!(currentState==G4State_Idle||currentState==G4State_PreInit))
{
G4cout << "Current application state is "
<< stateManager->GetStateString(currentState) << G4endl;
G4Exception("G4RunManagerKernel::DefineWorldVolume",
"DefineWorldVolumeAtIncorrectState",
FatalException,
@@ -425,8 +441,8 @@ void G4RunManagerKernel::DefineWorldVolume(G4VPhysicalVolume* worldVol,
// "DefineWorldVolumeAtIncorrectState",
// JustWarning,
// "Geant4 kernel is not Init state : Assuming Init state.");
G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
<<G4endl;
//G4cout<<"Warning : Geant4 kernel is not Init state : Assuming Init state."
// <<G4endl;
stateManager->SetNewState(G4State_Init);
}
}
+39 -36
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VModularPhysicsList.cc 100421 2016-10-21 12:49:57Z gcosmo $
// $Id: G4VModularPhysicsList.cc 103803 2017-04-27 14:03:05Z gcosmo $
//
//
// ------------------------------------------------------------
@@ -35,6 +35,7 @@
//
#include "G4VModularPhysicsList.hh"
#include "G4StateManager.hh"
#include <algorithm>
// This macros change the references to fields that are now encapsulated
// in the class G4VMPLData.
@@ -58,8 +59,7 @@ G4VModularPhysicsList::G4VModularPhysicsList()
G4VModularPhysicsList::~G4VModularPhysicsList()
{
G4PhysConstVector::iterator itr;
for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
delete (*itr);
}
G4MT_physicsVector->clear();
@@ -93,8 +93,7 @@ G4VModularPhysicsList & G4VModularPhysicsList::operator=(const G4VModularPhysics
verboseLevel = right.verboseLevel;
if(G4MT_physicsVector !=0) {
G4PhysConstVector::iterator itr;
for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
delete (*itr);
}
G4MT_physicsVector->clear();
@@ -108,8 +107,7 @@ G4VModularPhysicsList & G4VModularPhysicsList::operator=(const G4VModularPhysics
void G4VModularPhysicsList::ConstructParticle()
{
// create particles
G4PhysConstVector::iterator itr;
for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
(*itr)->ConstructParticle();;
}
}
@@ -131,8 +129,7 @@ void G4VModularPhysicsList::ConstructProcess()
G4AutoLock l(&constructProcessMutex); //Protection to be removed (A.Dotti)
AddTransportation();
G4PhysConstVector::iterator itr;
for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
(*itr)->ConstructProcess();
}
}
@@ -169,8 +166,8 @@ void G4VModularPhysicsList::RegisterPhysics(G4VPhysicsConstructor* fPhysics)
}
// Check if physics with the physics_type same as one of given physics
G4PhysConstVector::iterator itr;
for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
auto itr = G4MT_physicsVector->begin();
for (; itr!= G4MT_physicsVector->end(); ++itr) {
if ( pType == (*itr)->GetPhysicsType()) break;
}
if (itr!= G4MT_physicsVector->end()) {
@@ -228,7 +225,7 @@ void G4VModularPhysicsList::ReplacePhysics(G4VPhysicsConstructor* fPhysics)
}
// Check if physics with the physics_type same as one of given physics
G4PhysConstVector::iterator itr= G4MT_physicsVector->begin();
auto itr= G4MT_physicsVector->begin();
for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
if ( pType == (*itr)->GetPhysicsType()) break;
}
@@ -266,23 +263,23 @@ void G4VModularPhysicsList::RemovePhysics(G4int pType)
return;
}
for (G4PhysConstVector::iterator itr = G4MT_physicsVector->begin();
itr!= G4MT_physicsVector->end();) {
if ( pType == (*itr)->GetPhysicsType()) {
G4String pName = (*itr)->GetPhysicsName();
for (auto itr = G4MT_physicsVector->begin();
itr!= G4MT_physicsVector->end();) {
if ( pType == (*itr)->GetPhysicsType()) {
G4String pName = (*itr)->GetPhysicsName();
#ifdef G4VERBOSE
if (verboseLevel > 0){
G4cout << "G4VModularPhysicsList::RemovePhysics: "
<< pName << " is removed"
<< G4endl;
}
if (verboseLevel > 0){
G4cout << "G4VModularPhysicsList::RemovePhysics: "
<< pName << " is removed"
<< G4endl;
}
#endif
G4MT_physicsVector->erase(itr);
break;
} else {
itr++;
G4MT_physicsVector->erase(itr);
break;
} else {
itr++;
}
}
}
}
void G4VModularPhysicsList::RemovePhysics(G4VPhysicsConstructor* fPhysics)
@@ -296,7 +293,7 @@ void G4VModularPhysicsList::RemovePhysics(G4VPhysicsConstructor* fPhysics)
return;
}
for (G4PhysConstVector::iterator itr = G4MT_physicsVector->begin();
for (auto itr = G4MT_physicsVector->begin();
itr!= G4MT_physicsVector->end();) {
if ( fPhysics == (*itr)) {
G4String pName = (*itr)->GetPhysicsName();
@@ -325,7 +322,7 @@ void G4VModularPhysicsList::RemovePhysics(const G4String& name)
return;
}
for (G4PhysConstVector::iterator itr = G4MT_physicsVector->begin();
for (auto itr = G4MT_physicsVector->begin();
itr!= G4MT_physicsVector->end();) {
G4String pName = (*itr)->GetPhysicsName();
if ( name == pName) {
@@ -347,7 +344,7 @@ void G4VModularPhysicsList::RemovePhysics(const G4String& name)
const G4VPhysicsConstructor* G4VModularPhysicsList::GetPhysics(G4int idx) const
{
G4int i;
G4PhysConstVector::iterator itr= G4MT_physicsVector->begin();
auto itr= G4MT_physicsVector->begin();
for (i=0; i<idx && itr!= G4MT_physicsVector->end() ; ++i) ++itr;
if (itr!= G4MT_physicsVector->end()) return (*itr);
else return 0;
@@ -355,8 +352,8 @@ const G4VPhysicsConstructor* G4VModularPhysicsList::GetPhysics(G4int idx) const
const G4VPhysicsConstructor* G4VModularPhysicsList::GetPhysics(const G4String& name) const
{
G4PhysConstVector::iterator itr;
for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
auto itr = G4MT_physicsVector->begin();
for (; itr!= G4MT_physicsVector->end(); ++itr) {
if ( name == (*itr)->GetPhysicsName()) break;
}
if (itr!= G4MT_physicsVector->end()) return (*itr);
@@ -365,8 +362,8 @@ const G4VPhysicsConstructor* G4VModularPhysicsList::GetPhysics(const G4String& n
const G4VPhysicsConstructor* G4VModularPhysicsList::GetPhysicsWithType(G4int pType) const
{
G4PhysConstVector::iterator itr;
for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
auto itr = G4MT_physicsVector->begin();
for (; itr!= G4MT_physicsVector->end(); ++itr) {
if ( pType == (*itr)->GetPhysicsType()) break;
}
if (itr!= G4MT_physicsVector->end()) return (*itr);
@@ -377,11 +374,17 @@ const G4VPhysicsConstructor* G4VModularPhysicsList::GetPhysicsWithType(G4int pTy
void G4VModularPhysicsList::SetVerboseLevel(G4int value)
{
verboseLevel = value;
// Loop over constructors
G4PhysConstVector::iterator itr;
for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
(*itr)->SetVerboseLevel(verboseLevel);
}
}
void G4VModularPhysicsList::TerminateWorker()
{
//See https://jira-geant4.kek.jp/browse/DEV-284
std::for_each( G4MT_physicsVector->begin() , G4MT_physicsVector->end() ,
[](G4PhysConstVector::value_type el) { el->TerminateWorker();});
G4VUserPhysicsList::TerminateWorker();
}
+29 -1
View File
@@ -34,7 +34,8 @@
// ------------------------------------------------------------
#include "G4VPhysicsConstructor.hh"
#include "G4PhysicsBuilderInterface.hh"
#include <algorithm>
// This field helps to use the class G4VPCManager
//
G4VPCManager G4VPhysicsConstructor::subInstanceManager;
@@ -42,6 +43,7 @@ G4VPCManager G4VPhysicsConstructor::subInstanceManager;
void G4VPCData::initialize()
{
_aParticleIterator = G4ParticleTable::GetParticleTable()->GetIterator();
_builders = new PhysicsBuilders_V;
}
@@ -73,6 +75,8 @@ G4VPhysicsConstructor::G4VPhysicsConstructor(const G4String& name, G4int type)
G4VPhysicsConstructor::~G4VPhysicsConstructor()
{
//Master/Sequential needs to cleanup too
G4VPhysicsConstructor::TerminateWorker();
}
G4ParticleTable::G4PTblDicIterator* G4VPhysicsConstructor::GetParticleIterator() const
@@ -80,3 +84,27 @@ G4ParticleTable::G4PTblDicIterator* G4VPhysicsConstructor::GetParticleIterator()
return (subInstanceManager.offset[g4vpcInstanceID])._aParticleIterator;
}
G4VPhysicsConstructor::PhysicsBuilder_V G4VPhysicsConstructor::GetBuilders() const
{
const auto& tls = *((subInstanceManager.offset[g4vpcInstanceID])._builders);
PhysicsBuilder_V copy(tls.size());
int i = 0;
for ( const auto& el : tls ) { copy[i++] = el; }
return copy;
}
void G4VPhysicsConstructor::AddBuilder(G4PhysicsBuilderInterface* bld)
{
(subInstanceManager.offset[g4vpcInstanceID])._builders->push_back(bld);
}
void G4VPhysicsConstructor::TerminateWorker()
{
if ( subInstanceManager.offset[g4vpcInstanceID]._builders != nullptr ) {
std::for_each( subInstanceManager.offset[g4vpcInstanceID]._builders->begin() ,
subInstanceManager.offset[g4vpcInstanceID]._builders->end() ,
[](PhysicsBuilder_V::value_type bld) { delete bld;});
subInstanceManager.offset[g4vpcInstanceID]._builders->clear();
}
}
+10 -1
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VUserDetectorConstruction.cc 101679 2016-11-21 09:30:00Z gcosmo $
// $Id: G4VUserDetectorConstruction.cc 104521 2017-06-02 07:17:28Z gcosmo $
//
#include "G4VUserDetectorConstruction.hh"
@@ -250,6 +250,15 @@ void G4VUserDetectorConstruction::SetSensitiveDetector
//Get existing SD if already set and check if it is of the special type
G4VSensitiveDetector* originalSD = logVol->GetSensitiveDetector();
if ( originalSD == aSD ) {
G4ExceptionDescription msg;
msg << "Attempting to add multiple times the same sensitive detector (\"";
msg << originalSD->GetName()<<"\") is not allowed, skipping.";
G4Exception("G4VUserDetectorConstruction::SetSensitiveDetector",
"Run0054",JustWarning,msg);
return;
}
if ( originalSD == nullptr ) {
logVol->SetSensitiveDetector(aSD);
} else {
+7 -1
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VUserPhysicsList.cc 101155 2016-11-08 08:21:41Z gcosmo $
// $Id: G4VUserPhysicsList.cc 103803 2017-04-27 14:03:05Z gcosmo $
//
//
// ------------------------------------------------------------
@@ -150,6 +150,12 @@ void G4VUserPhysicsList::InitializeWorker()
G4MT_theMessenger = new G4UserPhysicsListMessenger(this);
}
void G4VUserPhysicsList::TerminateWorker()
{
RemoveProcessManager();
delete G4MT_theMessenger;
G4MT_theMessenger = nullptr;
}
////////////////////////////////////////////////////////
G4VUserPhysicsList::~G4VUserPhysicsList()
{
+4 -3
View File
@@ -91,8 +91,9 @@ G4WorkerRunManager::G4WorkerRunManager() : G4RunManager(workerRM) {
#include "G4MTRunManager.hh"
G4WorkerRunManager::~G4WorkerRunManager() {
// Delete thread-local process manager objects
physicsList->RemoveProcessManager();
// Delete thread-local data process manager objects
physicsList->TerminateWorker();
// physicsList->RemoveProcessManager();
//Put these pointers to zero: owned by master thread
//If not to zero, the base class destructor will attempt to
@@ -539,7 +540,7 @@ void G4WorkerRunManager::SetUserInitialization(G4VUserPhysicsList* pl)
void G4WorkerRunManager::SetUserAction(G4UserRunAction* userAction)
{
G4RunManager::SetUserAction(userAction);
userAction->SetMaster(false);
if(userAction) userAction->SetMaster(false);
}
void G4WorkerRunManager::SetupDefaultRNGEngine()
+107 -104
View File
@@ -34,6 +34,13 @@
#include "G4ParticlesWorkspace.hh"
#include "G4PhysicsListWorkspace.hh"
#include "G4Region.hh"
#include "G4RegionStore.hh"
#include "G4LogicalVolume.hh"
#include "G4Region.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolumeStore.hh"
void G4WorkerThread::SetThreadId(G4int tid)
{
threadId = tid;
@@ -56,88 +63,84 @@ G4int G4WorkerThread::GetNumberThreads() const
void G4WorkerThread::BuildGeometryAndPhysicsVector()
{
// Initialise all split classes in the geometry with copy of data from master thread
// Initialise all split classes in the geometry
// with copy of data from master thread
G4GeometryWorkspacePool::GetInstance()->CreateAndUseWorkspace();
G4SolidsWorkspacePool::GetInstance()->CreateAndUseWorkspace();
G4ParticlesWorkspace::GetPool()->CreateAndUseWorkspace();
G4PhysicsListWorkspace::GetPool()->CreateAndUseWorkspace();
// const_cast<G4VUPLManager&>(G4VUserPhysicsList::GetSubInstanceManager()).NewSubInstances();
// const_cast<G4VPCManager&>(G4VPhysicsConstructor::GetSubInstanceManager()).NewSubInstances();
// const_cast<G4VMPLManager&>(G4VModularPhysicsList::GetSubInstanceManager()).WorkerCopySubInstanceArray();
}
void G4WorkerThread::DestroyGeometryAndPhysicsVector()
{
#if 0
// Manage Geometry Workspace explicitly
fGeometryWrk->ReleaseAndDestroyWorkspace();
delete fGeometryWrk;
fGeometryWrk=0;
#else
// Alternative:
// Initialise all split classes in the geometry with copy of data from master thread
// G4GeometryWorkspacePool::GetInstance()->ReleaseAndDestroyMyWorkspace();
G4GeometryWorkspacePool::GetInstance()->GetWorkspace()->DestroyWorkspace();
G4SolidsWorkspacePool::GetInstance()->GetWorkspace()->DestroyWorkspace();
G4ParticlesWorkspace::GetPool()->GetWorkspace()->DestroyWorkspace();
G4PhysicsListWorkspace::GetPool()->GetWorkspace()->DestroyWorkspace();
#endif
// Initialise all split classes in the geometry
// with copy of data from master thread
// const_cast<G4VUPLManager&>(G4VUserPhysicsList::GetSubInstanceManager()).FreeWorker();
// const_cast<G4VPCManager&>(G4VPhysicsConstructor::GetSubInstanceManager()).FreeWorker();
// const_cast<G4VMPLManager&>(G4VModularPhysicsList::GetSubInstanceManager()).FreeWorker();
G4GeometryWorkspacePool::GetInstance()->CleanUpAndDestroyAllWorkspaces();
G4SolidsWorkspacePool::GetInstance()->CleanUpAndDestroyAllWorkspaces();
G4ParticlesWorkspace::GetPool()->CleanUpAndDestroyAllWorkspaces();
G4PhysicsListWorkspace::GetPool()->CleanUpAndDestroyAllWorkspaces();
}
#include "G4Region.hh"
#include "G4RegionStore.hh"
#include "G4LogicalVolume.hh"
#include "G4Region.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolumeStore.hh"
void G4WorkerThread::UpdateGeometryAndPhysicsVectorFromMaster()
{
//=================================================
//Step-0: keep sensitive detector and field manager
//=================================================
// =================================================
// Step-0: keep sensitive detector and field manager
// =================================================
// First remember SD and Filed Associated with worker
// in order to re-use it
// (note that all the stuff after this will reset SD and Field
typedef std::map<G4LogicalVolume*,std::pair<G4VSensitiveDetector*,G4FieldManager*> > LV2SDFM;
// in order to re-use it
// (note that all the stuff after this will reset SD and Field)
typedef std::map<G4LogicalVolume*,
std::pair<G4VSensitiveDetector*,G4FieldManager*> > LV2SDFM;
LV2SDFM lvmap;
// typedef std::map<G4LogicalVolume*,std::pair<G4Region*,G4bool> > LV2Region;
// LV2Region lv2rmap;
typedef std::map<G4Region*,std::pair<G4FastSimulationManager*,G4UserSteppingAction*> > R2FSM;
typedef std::map<G4Region*,
std::pair<G4FastSimulationManager*,G4UserSteppingAction*> > R2FSM;
R2FSM rgnmap;
G4LogicalVolumeStore* mLogVolStore = G4LogicalVolumeStore::GetInstance();
for(size_t ip=0; ip<mLogVolStore->size(); ip++)
{
G4LogicalVolume *lv = (*mLogVolStore)[ip];
//The following needs an explanation.
//Consider the case in which the user adds one LogVolume between the runs. The problem is that the thread-local part
//(split class) of the G4LogicalVolume object is not initialized for workers because the initialization is done once when the
//thread starts (see G4MTRunManagerKernel::StartThread Step-2 that calls G4WorkerThread::BuildGeometryAndPhysicsVector in this class)
//The problem is that pointers of SD and FM for these newly added LV
//may be invalid pointers (because never initialized, we have seen this behavior in our testing). If now we remember
//them and re-use them in Step-4 below we set invalid pointers to LV for this thread.
//Thus we need a way to know if for a given LV we need to remember or not the SD and FM pointers.
//To solve this problem: We assume that the ConstructSDandField is called also by Master thread
//thus for newly added LV the shadow pointers of SD and Fields are correct.
// (LIMITATION: this assumption may be too stringent, a user to save memory could instantiate SD only
// for workers, but we require this not to happen!).
// Thus is a SD and FieldMgr are needed for this particular LV, and shadow are !=0 it means that user
// wants an SD and FM to be associated with LV, we get the values and we remember them.
// The following needs an explanation.
// Consider the case in which the user adds one LogVolume between
// the runs. The problem is that the thread-local part (split class)
// of the G4LogicalVolume object is not initialized for workers
// because the initialization is done once when the thread starts
// (see G4MTRunManagerKernel::StartThread Step-2 that calls
// G4WorkerThread::BuildGeometryAndPhysicsVector in this class).
// The problem is that pointers of SD and FM for these newly added LV
// may be invalid pointers (because never initialized, we have seen
// this behavior in our testing). If now we remember them and re-use
// them in Step-4 below we set invalid pointers to LV for this thread.
// Thus we need a way to know if for a given LV we need to remember
// or not the SD and FM pointers.
// To solve this problem: We assume that the ConstructSDandField() is
// called also by Master thread, thus for newly added LV the shadow
// pointers of SD and Fields are correct.
// (LIMITATION: this assumption may be too stringent, a user to save
// memory could instantiate SD only for workers, but we require this
// not to happen!).
// Thus if a SD and FieldMgr are needed for this particular LV, and
// shadow are !=0 it means that user wants an SD and FM to be
// associated with LV, we get the values and we remember them.
//
G4VSensitiveDetector* sd = 0;
G4FieldManager* fmgr = 0;
if ( lv->GetMasterSensitiveDetector() != 0 ) sd = lv->GetSensitiveDetector();
if ( lv->GetMasterFieldManager() != 0 ) fmgr = lv->GetFieldManager();
if ( sd || fmgr ) lvmap[lv] = std::make_pair(sd,fmgr);
// G4Region* rgn = lv->GetRegion();
// G4bool isRoot = lv->IsRootRegion();
// if ( rgn || isRoot ) lv2rmap[lv] = std::make_pair(rgn,isRoot);
if ( lv->GetMasterSensitiveDetector() != 0 )
{
sd = lv->GetSensitiveDetector();
}
if ( lv->GetMasterFieldManager() != 0 )
{
fmgr = lv->GetFieldManager();
}
if ( sd || fmgr )
{
lvmap[lv] = std::make_pair(sd,fmgr);
}
}
G4RegionStore* mRegStore = G4RegionStore::GetInstance();
for(size_t ir=0; ir<mRegStore->size(); ir++)
@@ -145,55 +148,48 @@ void G4WorkerThread::UpdateGeometryAndPhysicsVectorFromMaster()
G4Region* reg = (*mRegStore)[ir];
G4FastSimulationManager* fsm = reg->GetFastSimulationManager();
G4UserSteppingAction* usa = reg->GetRegionalSteppingAction();
if ( reg || usa ) rgnmap[reg] = std::make_pair(fsm,usa);
if ( reg || usa )
{
rgnmap[reg] = std::make_pair(fsm,usa);
}
}
//===========================
//Step-1: Clean the workspace
// Step-1: Clean the workspace
//===========================
G4GeometryWorkspace* geomWorkspace= G4GeometryWorkspacePool::GetInstance()->GetWorkspace();
G4GeometryWorkspace* geomWorkspace =
G4GeometryWorkspacePool::GetInstance()->GetWorkspace();
geomWorkspace->DestroyWorkspace();
G4SolidsWorkspace* solidWorkspace = G4SolidsWorkspacePool::GetInstance()->GetWorkspace();
G4SolidsWorkspace* solidWorkspace =
G4SolidsWorkspacePool::GetInstance()->GetWorkspace();
solidWorkspace->DestroyWorkspace();
//===========================
//Step-2: Re-create and initialize workspace
// Step-2: Re-create and initialize workspace
//===========================
geomWorkspace->InitialiseWorkspace();
solidWorkspace->InitialiseWorkspace();
// Alternative
//
// To wipe, release and get a new one ...
// G4GeometryWorkspacePool *fWorkspaceMgr= G4GeometryWorkspaceOutlet::GetInstance();
// fWorkspaceMgr->ReleaseAndDestroyMyWorkspace();
// Now re-create
// fWorkspaceMgr->CreateAndUseWorkspace();
//===================================================
//Step-4: Restore sensitive detector and field manaer
// Step-4: Restore sensitive detector and field manaer
//===================================================
for ( LV2SDFM::const_iterator it = lvmap.begin() ; it != lvmap.end() ; ++it )
for ( LV2SDFM::const_iterator it = lvmap.begin() ;
it != lvmap.end() ; ++it )
{
G4LogicalVolume* lv = it->first;
G4VSensitiveDetector* sd = (it->second).first;
G4FieldManager* fmgr = (it->second).second;
if(fmgr) lv->SetFieldManager(fmgr, false); //What should be the second parameter? We use always false for MT mode
if(sd) lv->SetSensitiveDetector(sd);
if (fmgr) // What should be the second parameter?
{ // We use always false for MT mode
lv->SetFieldManager(fmgr, false);
}
if (sd)
{
lv->SetSensitiveDetector(sd);
}
}
// for ( LV2Region::const_iterator it2 = lv2rmap.begin() ; it2 != lv2rmap.end() ; it2++ )
// {
// G4LogicalVolume* lv2 = it2->first;
// G4Region* rgn = (it2->second).first;
// if(rgn) lv2->SetRegion(rgn);
// G4bool isRoot = (it2->second).second;
// lv2->SetRegionRootFlag(isRoot);
// }
for ( R2FSM::const_iterator it3 = rgnmap.begin() ; it3 != rgnmap.end() ; it3++ )
for ( R2FSM::const_iterator it3 = rgnmap.begin() ;
it3 != rgnmap.end() ; it3++ )
{
G4Region* reg = it3->first;
G4FastSimulationManager* fsm = (it3->second).first;
@@ -206,36 +202,43 @@ void G4WorkerThread::UpdateGeometryAndPhysicsVectorFromMaster()
void G4WorkerThread::SetPinAffinity(G4int affinity) const
{
if ( affinity == 0 ) return;
#if !defined(WIN32)
G4cout<<"AFFINITY SET"<<G4endl;
//Assign this thread to cpus in a round robin way
G4cout << "AFFINITY SET" << G4endl;
// Assign this thread to cpus in a round robin way
G4int offset = affinity;
G4int cpuindex = 0;
if ( std::abs(offset)>G4Threading::G4GetNumberOfCores() ) {
G4Exception("G4WorkerThread::SetPinAffinity","Run0100",
JustWarning,
"Cannot set thread affinity, affinity parameter larger than number of cores");
if ( std::abs(offset)>G4Threading::G4GetNumberOfCores() )
{
G4Exception("G4WorkerThread::SetPinAffinity()","Run0100", JustWarning,
"Cannot set thread affinity, affinity parameter larger than number of cores");
return;
}
if (offset>0) { //Start assigning affinity to given CPU
if (offset>0) // Start assigning affinity to given CPU
{
--offset;
cpuindex = (GetThreadId()+offset) % G4Threading::G4GetNumberOfCores(); //Round robin
} else {//Exclude the given CPU
cpuindex = (GetThreadId()+offset) % G4Threading::G4GetNumberOfCores();
// Round robin
}
else // Exclude the given CPU
{
offset *= -1;
--offset;
G4int myidx = GetThreadId()%(G4Threading::G4GetNumberOfCores()-1);
cpuindex = myidx + (myidx>=offset);
}
G4cout<<"Setting affinity to:"<<cpuindex<<G4endl;
//Avoid compilation warning in C90 standard w/o MT
#if defined(G4MULTITHREADED)
G4cout << "Setting affinity to:" << cpuindex << G4endl;
#if defined(G4MULTITHREADED) // Avoid compilation warning in C90 standard w/o MT
G4Thread t = G4THREADSELF();
#else
G4Thread t;
#endif
G4bool success = G4Threading::G4SetPinAffinity(cpuindex,t);
if ( ! success ) {
G4Exception("G4MTRunManagerKernel::StarThread","Run0101",JustWarning,"Cannot set thread affinity.");
if ( ! success )
{
G4Exception("G4MTRunManagerKernel::StarThread()", "Run0101",
JustWarning, "Cannot set thread affinity.");
}
#endif
}