Import Geant4 11.0.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2021-06-25 16:12:29 +02:00
parent c968e26a39
commit 6399a014b6
4200 changed files with 207479 additions and 237366 deletions
@@ -23,9 +23,9 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4PhysicalVolumeStore implementation for singleton container
// G4PhysicalVolumeStore implementation
//
// 25.07.95, P.Kent - Initial version
// 25.07.95, P.Kent, G.Cosmo
// --------------------------------------------------------------------
#include "G4Types.hh"
@@ -33,6 +33,13 @@
#include "G4GeometryManager.hh"
#include "G4LogicalVolume.hh"
#include "G4AutoLock.hh"
namespace
{
G4Mutex mapMutex = G4MUTEX_INITIALIZER;
}
// ***************************************************************************
// Static class variables
// ***************************************************************************
@@ -83,7 +90,7 @@ void G4PhysicalVolumeStore::Clean()
//
locked = true;
size_t i=0;
std::size_t i=0;
G4PhysicalVolumeStore* store = GetInstance();
#ifdef G4GEOMETRY_VOXELDEBUG
@@ -103,6 +110,7 @@ void G4PhysicalVolumeStore::Clean()
{ G4cout << i-1 << " volumes deleted !" << G4endl; }
#endif
store->bmap.clear(); store->mvalid = false;
locked = false;
store->clear();
}
@@ -117,14 +125,54 @@ void G4PhysicalVolumeStore::SetNotifier(G4VStoreNotifier* pNotifier)
fgNotifier = pNotifier;
}
// ***************************************************************************
// Bring contents of internal map up to date and reset validity flag
// ***************************************************************************
//
void G4PhysicalVolumeStore::UpdateMap()
{
G4AutoLock l(&mapMutex); // to avoid thread contention at initialisation
if (mvalid) return;
bmap.clear();
for(auto pos=GetInstance()->cbegin(); pos!=GetInstance()->cend(); ++pos)
{
const G4String& vol_name = (*pos)->GetName();
auto it = bmap.find(vol_name);
if (it != bmap.cend())
{
it->second.push_back(*pos);
}
else
{
std::vector<G4VPhysicalVolume*> vol_vec { *pos };
bmap.insert(std::make_pair(vol_name, vol_vec));
}
}
mvalid = true;
l.unlock();
}
// ***************************************************************************
// Add Volume to container
// ***************************************************************************
//
void G4PhysicalVolumeStore::Register(G4VPhysicalVolume* pVolume)
{
GetInstance()->push_back(pVolume);
G4PhysicalVolumeStore* store = GetInstance();
store->push_back(pVolume);
const G4String& vol_name = pVolume->GetName();
auto it = store->bmap.find(vol_name);
if (it != store->bmap.cend())
{
it->second.push_back(pVolume);
}
else
{
std::vector<G4VPhysicalVolume*> vol_vec { pVolume };
store->bmap.insert(std::make_pair(vol_name, vol_vec));
}
if (fgNotifier) { fgNotifier->NotifyRegistration(); }
store->mvalid = true;
}
// ***************************************************************************
@@ -134,19 +182,40 @@ void G4PhysicalVolumeStore::Register(G4VPhysicalVolume* pVolume)
//
void G4PhysicalVolumeStore::DeRegister(G4VPhysicalVolume* pVolume)
{
G4PhysicalVolumeStore* store = GetInstance();
if (!locked) // Do not de-register if locked !
{
if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
G4LogicalVolume* motherLogical = pVolume->GetMotherLogical();
if (motherLogical != nullptr) { motherLogical->RemoveDaughter(pVolume); }
for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
for (auto i=store->cbegin(); i!=store->cend(); ++i)
{
if (**i==*pVolume)
{
GetInstance()->erase(i);
store->erase(i);
break;
}
}
const G4String& vol_name = pVolume->GetName();
auto it = store->bmap.find(vol_name);
if (it != store->bmap.cend())
{
if (it->second.size() > 1)
{
for (auto i=it->second.cbegin(); i!=it->second.cend(); ++i)
{
if (**i==*pVolume)
{
it->second.erase(i);
break;
}
}
}
else
{
store->bmap.erase(it);
}
}
}
}
@@ -157,9 +226,21 @@ void G4PhysicalVolumeStore::DeRegister(G4VPhysicalVolume* pVolume)
G4VPhysicalVolume*
G4PhysicalVolumeStore::GetVolume(const G4String& name, G4bool verbose) const
{
for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
G4PhysicalVolumeStore* store = GetInstance();
if (!store->mvalid) { store->UpdateMap(); }
auto pos = store->bmap.find(name);
if(pos != store->bmap.cend())
{
if ((*i)->GetName() == name) { return *i; }
if ((verbose) && (pos->second.size()>1))
{
std::ostringstream message;
message << "There exists more than ONE physical volume in store named: "
<< name << "!" << G4endl
<< "Returning the first found.";
G4Exception("G4PhysicalVolumeStore::GetVolume()",
"GeomMgt1001", JustWarning, message);
}
return pos->second[0];
}
if (verbose)
{