Import Geant4 11.3.1 source tree

This commit is contained in:
Gabriele Cosmo
2025-03-24 16:45:22 +01:00
parent 32390e802b
commit df176550b3
388 changed files with 29491 additions and 29435 deletions
+19
View File
@@ -6,6 +6,25 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2025-03-05 Gabriele Cosmo (geommng-V11-02-07)
- Applied clang-tidy to G4GeometryManager and some code cleanup.
Moved additional checks/warnings under verbosity level.
## 2025-03-03 Gabriele Cosmo
- In G4VSolid::EstimateCubicVolume(..), initialise local variable to zero
to silence invalid false positive warnings reported in compilation of CMSSW.
## 2025-02-25 John Apostolakis
- In G4GeometryManager, fix in ConfigureParallelOptimisation() to reset
logical volumes iterator; in ReportWorkerIsDoneOptimising(), added checks
to report fatal error if incorrect number of volumes was voxelised, and warns
if number of workers reporting is not as expected.
In ConfigureParallelOptimisation(), reports on the times it was called.
## 2025-02-03 Gabriele Cosmo
- G4UAdapter: removed fake default constructor, clearing compilation warnings
on gcc-14.
## 2024-08-26 Gabriele Cosmo (geommng-V11-02-06)
- G4GeometryManager: temporarily disable default parallel optimisation.
Fixed spelling for method OptimiseInParallel(..).
@@ -196,13 +196,6 @@ class G4UAdapter : public G4VSolid, protected UnplacedVolume_t
// Smart access function - creates on request and stores for future
// access. A null pointer means "not available".
public: // without description
G4UAdapter(__void__&);
// Fake default constructor for usage restricted to direct object
// persistency for clients requiring preallocation of memory for
// persistifiable objects.
G4UAdapter(const G4UAdapter& rhs);
G4UAdapter& operator=(const G4UAdapter& rhs);
// Copy constructor and assignment operator.
@@ -257,13 +250,6 @@ class G4UAdapter : public G4VSolid, protected UnplacedVolume_t
// Inline implementations
template <class UnplacedVolume_t>
G4UAdapter<UnplacedVolume_t>::G4UAdapter(__void__& a)
: G4VSolid(a), UnplacedVolume_t(*this),
kHalfTolerance(0.5*kCarTolerance)
{
}
template <class UnplacedVolume_t>
G4UAdapter<UnplacedVolume_t>::~G4UAdapter()
{
@@ -113,7 +113,7 @@ G4GeometryManager::~G4GeometryManager()
fgInstance = nullptr;
fIsClosed = false;
if( fWallClockTimer && G4Threading::IsMasterThread() )
if( (fWallClockTimer != nullptr) && G4Threading::IsMasterThread() )
{
delete fWallClockTimer;
fWallClockTimer= nullptr;
@@ -240,11 +240,9 @@ G4bool G4GeometryManager::BuildOptimisations(G4bool allOpts, G4bool verbose)
fOptimiseInParallelConfigured = fParallelVoxelOptimisationRequested
&& G4Threading::IsMultithreadedApplication();
static unsigned int NumCallsBuildOptimisations = 0; // WORKAROUND - TODO fix
if( fOptimiseInParallelConfigured && (NumCallsBuildOptimisations==0) )
if( fOptimiseInParallelConfigured )
{
PrepareParallelOptimisation(allOpts, verbose);
++NumCallsBuildOptimisations;
}
else
{
@@ -285,7 +283,7 @@ void G4GeometryManager::BuildOptimisationsSequential(G4bool allOpts,
for (auto & n : *Store)
{
if (verbose) timer.Start();
if (verbose) { timer.Start(); }
volume=n;
// For safety, check if there are any existing voxels and
// delete before replacement
@@ -374,7 +372,7 @@ void
G4GeometryManager::CreateListOfVolumesToOptimise(G4bool allOpts, G4bool verbose)
{
// Prepare the work - must be called only in one thread !!
G4LogicalVolumeStore* Store = G4LogicalVolumeStore::GetInstance();
if( !fVolumesToOptimise.empty() )
@@ -416,9 +414,11 @@ G4GeometryManager::CreateListOfVolumesToOptimise(G4bool allOpts, G4bool verbose)
}
if(verbose)
G4cout << "** G4GeometryManager::PrepareOptimisationWork: "
{
G4cout << "** G4GeometryManager::CreateListOfVolumesToOptimise: "
<< " Number of volumes for voxelisation = "
<< fVolumesToOptimise.size() << G4endl;
}
fLogVolumeIterator = fVolumesToOptimise.cbegin();
}
@@ -482,9 +482,13 @@ void G4GeometryManager::RequestParallelOptimisation(G4bool flag, G4bool verbose)
//
void G4GeometryManager::ConfigureParallelOptimisation(G4bool verbose)
{
static G4ThreadLocal unsigned int numCallsConfig = 0;
++numCallsConfig;
if(verbose)
{
G4cout << "** G4GeometryManager::ConfigureParallelOptimisation() called. "
G4cout << "** G4GeometryManager::ConfigureParallelOptimisation() called "
<< " for the " << numCallsConfig << " time. "
<< " LEAVING all the work (of voxel optimisation) to the threads/tasks !"
<< G4endl;
}
@@ -501,6 +505,9 @@ void G4GeometryManager::ConfigureParallelOptimisation(G4bool verbose)
fTotalNumberVolumesOptimised = 0; // Number of volumes done
fWallClockStarted = false; // Will need to restart it!
fLogVolumeIterator = fVolumesToOptimise.cbegin();
// Reset the iterator -- else to be sure that work is done correctly
}
// ***************************************************************************
@@ -528,8 +535,8 @@ void G4GeometryManager::UndertakeOptimisation()
G4bool verbose = fVerboseParallel;
G4LogicalVolume* logVolume = nullptr;
fParallelVoxelOptimisationUnderway = true;
fParallelVoxelOptimisationUnderway = true;
// Start timer - if not already done
if( ( !fWallClockStarted ) && verbose )
{
@@ -546,7 +553,7 @@ void G4GeometryManager::UndertakeOptimisation()
while( (logVolume = ObtainVolumeToOptimise()) != nullptr )
{
if (verbose) fetimer.Start();
if (verbose) { fetimer.Start(); }
G4SmartVoxelHeader* head = logVolume->GetVoxelHeader();
delete head;
@@ -601,7 +608,7 @@ void G4GeometryManager::UndertakeOptimisation()
<< "but found that voxels headers are missing in "
<< badVolumes << " volumes.";
G4Exception("G4GeometryManager::UndertakeOptimisation()",
"GeomMng002", FatalException, errmsg);
"GeomMgt002", FatalException, errmsg);
}
// Create report
@@ -688,18 +695,80 @@ G4int G4GeometryManager::CheckOptimisation()
// ***************************************************************************
//
G4int
G4GeometryManager::ReportWorkerIsDoneOptimising(unsigned int numVolumesOptimised)
G4GeometryManager::ReportWorkerIsDoneOptimising(unsigned int nVolOptimised)
{
// Check that all are done and, if so, signal that optimisation is finished
G4int orderReporting;
G4AutoLock lock(statResultsMutex);
orderReporting = ++fNumberThreadsReporting;
fTotalNumberVolumesOptimised += numVolumesOptimised;
fTotalNumberVolumesOptimised += nVolOptimised;
if (fNumberThreadsReporting == G4Threading::GetNumberOfRunningWorkerThreads())
if( fVerboseParallel )
{
InformOptimisationIsFinished(fVerboseParallel);
std::cout << "G4GeometryManager: the " << orderReporting
<< " worker has finished. "
<< " Total volumes voxelised = "
<< fTotalNumberVolumesOptimised
<< " out of " << fVolumesToOptimise.size() << G4endl;
}
if ( fNumberThreadsReporting == G4Threading::GetNumberOfRunningWorkerThreads()
|| fTotalNumberVolumesOptimised == fVolumesToOptimise.size() )
{
const auto TotalThreads = G4Threading::GetNumberOfRunningWorkerThreads();
auto tid= G4Threading::G4GetThreadId();
// -- Some Checks
if( fTotalNumberVolumesOptimised != fVolumesToOptimise.size() )
{
G4ExceptionDescription errmsg;
errmsg << " [thread " << tid << " ] "
<< " ERROR: Number of volumes 'voxelised' = "
<< fTotalNumberVolumesOptimised
<< " is not equal to the total number requested "
<< fVolumesToOptimise.size() << " !! " << G4endl;
G4Exception("G4GeometryManager::ReportWorkerIsDoneOptimising()",
"GeomMgt0003", FatalException, errmsg);
}
if( fVerboseParallel )
{
if( fNumberThreadsReporting > TotalThreads )
{
G4ExceptionDescription errmsg;
errmsg << " [thread " << tid << " ] "
<< " WARNING: Number of threads 'reporting' = "
<< fNumberThreadsReporting
<< " exceeds the total number of threads "
<< TotalThreads << " !! " << G4endl
<< " *Missed* calling ConfigureParallelOptimisation() to reset. ";
G4Exception("G4GeometryManager::ReportWorkerIsDoneOptimising()",
"GeomMgt1002", JustWarning, errmsg);
}
else
{
if( fTotalNumberVolumesOptimised == fVolumesToOptimise.size()
&& ( fNumberThreadsReporting < TotalThreads ) )
{
G4ExceptionDescription errmsg;
errmsg << " [thread " << tid << " ] "
<< " WARNING: All volumes optimised, yet only "
<< fNumberThreadsReporting << " threads reported out of "
<< TotalThreads;
G4Exception("G4GeometryManager::ReportWorkerIsDoneOptimising()",
"GeomMgt1002", JustWarning, errmsg);
}
}
}
// -- End of Checks
// Report the end
if( fNumberThreadsReporting <= G4Threading::GetNumberOfRunningWorkerThreads() )
{
// Close the work, and (if verbosity is on) report statistics
InformOptimisationIsFinished(fVerboseParallel);
}
}
return orderReporting;
@@ -859,8 +928,7 @@ void G4GeometryManager::SetWorldMaximumExtent(G4double extent)
//
void
G4GeometryManager::ReportVoxelStats( std::vector<G4SmartVoxelStat> & stats,
G4double totalCpuTime,
std::ostream &os )
G4double totalCpuTime, std::ostream &os )
{
os << "--------------------------------------------------------------------------------"
<< G4endl;
+32 -31
View File
@@ -218,7 +218,8 @@ G4double G4VSolid::GetCubicVolume()
G4double G4VSolid::EstimateCubicVolume(G4int nStat, G4double epsilon) const
{
G4int iInside=0;
G4double px,py,pz,minX,maxX,minY,maxY,minZ,maxZ,volume,halfepsilon;
G4double px, py, pz, volume, halfepsilon;
G4double minX=0., maxX=0., minY=0., maxY=0., minZ=0., maxZ=0.;
G4ThreeVector p;
EInside in;
@@ -235,8 +236,8 @@ G4double G4VSolid::EstimateCubicVolume(G4int nStat, G4double epsilon) const
// limits
if(nStat < 100) nStat = 100;
if(epsilon > 0.01) epsilon = 0.01;
if(nStat < 100) { nStat = 100; }
if(epsilon > 0.01) { epsilon = 0.01; }
halfepsilon = 0.5*epsilon;
for(auto i = 0; i < nStat; ++i )
@@ -246,7 +247,7 @@ G4double G4VSolid::EstimateCubicVolume(G4int nStat, G4double epsilon) const
pz = minZ-halfepsilon+(maxZ-minZ+epsilon)*G4QuickRand();
p = G4ThreeVector(px,py,pz);
in = Inside(p);
if(in != kOutside) ++iInside;
if(in != kOutside) { ++iInside; }
}
volume = (maxX-minX+epsilon)*(maxY-minY+epsilon)
* (maxZ-minZ+epsilon)*iInside/nStat;
@@ -360,15 +361,15 @@ G4double G4VSolid::EstimateSurfaceArea(G4int nstat, G4double ell) const
G4double dist = 0;
if (in == kInside)
{
if (DistanceToOut(p) >= eps) continue;
if (DistanceToOut(p) >= eps) { continue; }
G4int icase = 0;
if (Inside(G4ThreeVector(px-del, py, pz)) != kInside) icase += 1;
if (Inside(G4ThreeVector(px+del, py, pz)) != kInside) icase += 2;
if (Inside(G4ThreeVector(px, py-del, pz)) != kInside) icase += 4;
if (Inside(G4ThreeVector(px, py+del, pz)) != kInside) icase += 8;
if (Inside(G4ThreeVector(px, py, pz-del)) != kInside) icase += 16;
if (Inside(G4ThreeVector(px, py, pz+del)) != kInside) icase += 32;
if (icase == 0) continue;
if (Inside(G4ThreeVector(px-del, py, pz)) != kInside) { icase += 1; }
if (Inside(G4ThreeVector(px+del, py, pz)) != kInside) { icase += 2; }
if (Inside(G4ThreeVector(px, py-del, pz)) != kInside) { icase += 4; }
if (Inside(G4ThreeVector(px, py+del, pz)) != kInside) { icase += 8; }
if (Inside(G4ThreeVector(px, py, pz-del)) != kInside) { icase += 16; }
if (Inside(G4ThreeVector(px, py, pz+del)) != kInside) { icase += 32; }
if (icase == 0) { continue; }
G4ThreeVector v = directions[icase];
dist = DistanceToOut(p, v);
G4ThreeVector n = SurfaceNormal(p + v*dist);
@@ -376,22 +377,22 @@ G4double G4VSolid::EstimateSurfaceArea(G4int nstat, G4double ell) const
}
else if (in == kOutside)
{
if (DistanceToIn(p) >= eps) continue;
if (DistanceToIn(p) >= eps) { continue; }
G4int icase = 0;
if (Inside(G4ThreeVector(px-del, py, pz)) != kOutside) icase += 1;
if (Inside(G4ThreeVector(px+del, py, pz)) != kOutside) icase += 2;
if (Inside(G4ThreeVector(px, py-del, pz)) != kOutside) icase += 4;
if (Inside(G4ThreeVector(px, py+del, pz)) != kOutside) icase += 8;
if (Inside(G4ThreeVector(px, py, pz-del)) != kOutside) icase += 16;
if (Inside(G4ThreeVector(px, py, pz+del)) != kOutside) icase += 32;
if (icase == 0) continue;
if (Inside(G4ThreeVector(px-del, py, pz)) != kOutside) { icase += 1; }
if (Inside(G4ThreeVector(px+del, py, pz)) != kOutside) { icase += 2; }
if (Inside(G4ThreeVector(px, py-del, pz)) != kOutside) { icase += 4; }
if (Inside(G4ThreeVector(px, py+del, pz)) != kOutside) { icase += 8; }
if (Inside(G4ThreeVector(px, py, pz-del)) != kOutside) { icase += 16; }
if (Inside(G4ThreeVector(px, py, pz+del)) != kOutside) { icase += 32; }
if (icase == 0) { continue; }
G4ThreeVector v = directions[icase];
dist = DistanceToIn(p, v);
if (dist == kInfinity) continue;
if (dist == kInfinity) { continue; }
G4ThreeVector n = SurfaceNormal(p + v*dist);
dist *= -(v.dot(n));
}
if (dist < eps) ++icount;
if (dist < eps) { ++icount; }
}
return dX*dY*dZ*icount/npoints/dd;
}
@@ -567,14 +568,14 @@ void G4VSolid::ClipPolygon( G4ThreeVectorList& pPolygon,
pPolygon.clear();
if ( outputPolygon.empty() ) return;
if ( outputPolygon.empty() ) { return; }
G4VoxelLimits simpleLimit2;
simpleLimit2.AddLimit(kXAxis,-kInfinity,pVoxelLimit.GetMaxXExtent());
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
if ( pPolygon.empty() ) return;
else outputPolygon.clear();
if ( pPolygon.empty() ) { return; }
outputPolygon.clear();
}
if ( pVoxelLimit.IsYLimited() ) // && pAxis != kYAxis)
{
@@ -587,14 +588,14 @@ void G4VSolid::ClipPolygon( G4ThreeVectorList& pPolygon,
pPolygon.clear();
if ( outputPolygon.empty() ) return;
if ( outputPolygon.empty() ) { return; }
G4VoxelLimits simpleLimit2;
simpleLimit2.AddLimit(kYAxis,-kInfinity,pVoxelLimit.GetMaxYExtent());
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
if ( pPolygon.empty() ) return;
else outputPolygon.clear();
if ( pPolygon.empty() ) { return; }
outputPolygon.clear();
}
if ( pVoxelLimit.IsZLimited() ) // && pAxis != kZAxis)
{
@@ -607,7 +608,7 @@ void G4VSolid::ClipPolygon( G4ThreeVectorList& pPolygon,
pPolygon.clear();
if ( outputPolygon.empty() ) return;
if ( outputPolygon.empty() ) { return; }
G4VoxelLimits simpleLimit2;
simpleLimit2.AddLimit(kZAxis,-kInfinity,pVoxelLimit.GetMaxZExtent());
@@ -635,8 +636,8 @@ G4VSolid::ClipPolygonToSimpleLimits( G4ThreeVectorList& pPolygon,
for (i = 0 ; i < noVertices ; ++i )
{
vStart = pPolygon[i];
if ( i == noVertices-1 ) vEnd = pPolygon[0];
else vEnd = pPolygon[i+1];
if ( i == noVertices-1 ) { vEnd = pPolygon[0]; }
else { vEnd = pPolygon[i+1]; }
if ( pVoxelLimit.Inside(vStart) )
{