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,15 +23,22 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4LogicalVolumeStore implementation for singleton container
// G4LogicalVolumeStore implementation
//
// 10.07.95 - P.Kent, Initial version
// 10.07.95, P.Kent, G.Cosmo
// --------------------------------------------------------------------
#include "G4Types.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4GeometryManager.hh"
#include "G4AutoLock.hh"
namespace
{
G4Mutex mapMutex = G4MUTEX_INITIALIZER;
}
// ***************************************************************************
// Static class variables
// ***************************************************************************
@@ -81,7 +88,7 @@ void G4LogicalVolumeStore::Clean()
//
locked = true;
size_t i = 0;
std::size_t i = 0;
G4LogicalVolumeStore* store = GetInstance();
#ifdef G4GEOMETRY_VOXELDEBUG
@@ -102,6 +109,7 @@ void G4LogicalVolumeStore::Clean()
{ G4cout << i-1 << " volumes deleted !" << G4endl; }
#endif
store->bmap.clear(); store->mvalid = false;
locked = false;
store->clear();
}
@@ -116,14 +124,54 @@ void G4LogicalVolumeStore::SetNotifier(G4VStoreNotifier* pNotifier)
fgNotifier = pNotifier;
}
// ***************************************************************************
// Bring contents of internal map up to date and reset validity flag
// ***************************************************************************
//
void G4LogicalVolumeStore::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<G4LogicalVolume*> vol_vec { *pos };
bmap.insert(std::make_pair(vol_name, vol_vec));
}
}
mvalid = true;
l.unlock();
}
// ***************************************************************************
// Add volume to container
// ***************************************************************************
//
void G4LogicalVolumeStore::Register(G4LogicalVolume* pVolume)
{
GetInstance()->push_back(pVolume);
G4LogicalVolumeStore* 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<G4LogicalVolume*> vol_vec { pVolume };
store->bmap.insert(std::make_pair(vol_name, vol_vec));
}
if (fgNotifier) { fgNotifier->NotifyRegistration(); }
store->mvalid = true;
}
// ***************************************************************************
@@ -132,17 +180,38 @@ void G4LogicalVolumeStore::Register(G4LogicalVolume* pVolume)
//
void G4LogicalVolumeStore::DeRegister(G4LogicalVolume* pVolume)
{
G4LogicalVolumeStore* store = GetInstance();
if (!locked) // Do not de-register if locked !
{
if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
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);
}
}
}
}
@@ -153,9 +222,21 @@ void G4LogicalVolumeStore::DeRegister(G4LogicalVolume* pVolume)
G4LogicalVolume*
G4LogicalVolumeStore::GetVolume(const G4String& name, G4bool verbose) const
{
for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
G4LogicalVolumeStore* 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 logical volume in store named: "
<< name << "!" << G4endl
<< "Returning the first found.";
G4Exception("G4LogicalVolumeStore::GetVolume()",
"GeomMgt1001", JustWarning, message);
}
return pos->second[0];
}
if (verbose)
{
@@ -166,7 +247,7 @@ G4LogicalVolumeStore::GetVolume(const G4String& name, G4bool verbose) const
G4Exception("G4LogicalVolumeStore::GetVolume()",
"GeomMgt1001", JustWarning, message);
}
return 0;
return nullptr;
}
// ***************************************************************************