Import Geant4 4.1.0 source tree
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4PhysicalVolumeStore.cc,v 1.7 2001/07/11 09:59:21 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-04-00 $
|
||||
// $Id: G4PhysicalVolumeStore.cc,v 1.9 2002/04/26 16:24:36 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-04-01 $
|
||||
//
|
||||
// G4PhysicalVolumeStore
|
||||
//
|
||||
@@ -30,51 +30,116 @@
|
||||
//
|
||||
// History:
|
||||
// 25.07.95 P.Kent Initial version
|
||||
// ********************************************************************
|
||||
|
||||
#include "G4PhysicalVolumeStore.hh"
|
||||
#include "globals.hh"
|
||||
#include "G4PhysicalVolumeStore.hh"
|
||||
#include "G4GeometryManager.hh"
|
||||
|
||||
// ***************************************************************************
|
||||
// Static class variables
|
||||
// ***************************************************************************
|
||||
//
|
||||
G4PhysicalVolumeStore* G4PhysicalVolumeStore::fgInstance = 0;
|
||||
G4bool G4PhysicalVolumeStore::locked = false;
|
||||
|
||||
// ***************************************************************************
|
||||
// Protected constructor: Construct underlying container with
|
||||
// initial size of 100 entries
|
||||
// ***************************************************************************
|
||||
//
|
||||
G4PhysicalVolumeStore::G4PhysicalVolumeStore()
|
||||
: G4std::vector<G4VPhysicalVolume*>()
|
||||
{
|
||||
reserve(100);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
// Destructor
|
||||
// ***************************************************************************
|
||||
//
|
||||
G4PhysicalVolumeStore::~G4PhysicalVolumeStore()
|
||||
{
|
||||
while (!empty())
|
||||
{
|
||||
// delete front();
|
||||
erase(begin());
|
||||
}
|
||||
Clean();
|
||||
}
|
||||
|
||||
// Static class variable
|
||||
G4PhysicalVolumeStore* G4PhysicalVolumeStore::fgInstance = 0;
|
||||
// ***************************************************************************
|
||||
// Delete all elements from the store
|
||||
// ***************************************************************************
|
||||
//
|
||||
void G4PhysicalVolumeStore::Clean()
|
||||
{
|
||||
// Do nothing if geometry is closed
|
||||
//
|
||||
if (G4GeometryManager::GetInstance()->IsGeometryClosed())
|
||||
{
|
||||
G4cout << "WARNING - Attempt to delete the physical volume store"
|
||||
<< " while geometry closed !" << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Locks store for deletion of volumes. De-registration will be
|
||||
// performed at this stage. G4VPhysicalVolumes will not de-register
|
||||
// themselves.
|
||||
//
|
||||
locked = true;
|
||||
|
||||
size_t i=0;
|
||||
G4PhysicalVolumeStore* store = GetInstance();
|
||||
G4std::vector<G4VPhysicalVolume*>::iterator pos;
|
||||
|
||||
#ifdef G4GEOMETRY_VOXELDEBUG
|
||||
G4cout << "Deleting Physical Volumes ... ";
|
||||
#endif
|
||||
|
||||
for(pos=store->begin(); pos!=store->end(); pos++)
|
||||
{
|
||||
if (*pos) delete *pos; i++;
|
||||
}
|
||||
|
||||
#ifdef G4GEOMETRY_VOXELDEBUG
|
||||
if (store->size() < i-1)
|
||||
{ G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
|
||||
else
|
||||
{ G4cout << i-1 << " volumes deleted !" << G4endl; }
|
||||
#endif
|
||||
|
||||
locked = false;
|
||||
store->clear();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
// Add Solid to container
|
||||
// ***************************************************************************
|
||||
//
|
||||
void G4PhysicalVolumeStore::Register(G4VPhysicalVolume* pVolume)
|
||||
{
|
||||
GetInstance()->push_back(pVolume);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
// Remove Solid from container
|
||||
// ***************************************************************************
|
||||
//
|
||||
void G4PhysicalVolumeStore::DeRegister(G4VPhysicalVolume* pVolume)
|
||||
{
|
||||
for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
|
||||
if (!locked) // Do not de-register if locked !
|
||||
{
|
||||
if (**i==*pVolume)
|
||||
for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
|
||||
{
|
||||
GetInstance()->erase(i);
|
||||
break;
|
||||
if (**i==*pVolume)
|
||||
{
|
||||
GetInstance()->erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
// Return ptr to Store, setting if necessary
|
||||
// ***************************************************************************
|
||||
//
|
||||
G4PhysicalVolumeStore* G4PhysicalVolumeStore::GetInstance()
|
||||
{
|
||||
static G4PhysicalVolumeStore worldStore;
|
||||
@@ -84,5 +149,3 @@ G4PhysicalVolumeStore* G4PhysicalVolumeStore::GetInstance()
|
||||
}
|
||||
return fgInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user