Skip to content

Commit d0f3e08

Browse files
sawenzelclaude
andcommitted
Rebuild the geometry voxels after alignment
This fixes a crash of o2-sim in multithreaded Geant4 mode when the alignment is applied. - TGeoPhysicalNode::Align only flags the voxels and assembly bounding boxes of the mother volumes for a rebuild. - The rebuild then happens lazily during navigation, concurrently in several transport threads, and corrupts the heap. - They are now rebuilt once at the end of MisalignGeometry, before transport starts. https://its.cern.ch/jira/browse/O2-7305 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 30e8785 commit d0f3e08

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎Steer/src/O2MCApplication.cxx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "DetectorsBase/GeometryManagerParam.h"
4747
#include <TGeoParallelWorld.h>
4848
#include <TGeoVolume.h>
49+
#include <TGeoVoxelFinder.h>
4950
#include <TBuffer3D.h>
5051
#include <TGeoTessellated.h>
5152
#include <DetectorsBase/O2Tessellated.h>
@@ -357,6 +358,24 @@ bool O2MCApplicationBase::MisalignGeometry()
357358
// performs possible optimizations (shape replacements on the runtime geometry)
358359
fixTGeoRuntimeShapes();
359360

361+
// alignment leaves voxels and assembly boxes to be rebuilt lazily during navigation, which
362+
// is a data race between Geant4 transport threads; rebuild them here once
363+
TIter nextvol(gGeoManager->GetListOfVolumes());
364+
while (auto vol = static_cast<TGeoVolume*>(nextvol())) {
365+
if (vol->IsAssembly()) {
366+
vol->GetShape()->ComputeBBox();
367+
}
368+
}
369+
nextvol.Reset();
370+
int nvoxelized = 0;
371+
while (auto vol = static_cast<TGeoVolume*>(nextvol())) {
372+
if (auto voxels = vol->GetVoxels(); voxels && voxels->NeedRebuild()) {
373+
voxels->Voxelize();
374+
++nvoxelized;
375+
}
376+
}
377+
LOG(info) << "Rebuilt the voxels of " << nvoxelized << " volumes after alignment";
378+
360379
// return original return value of misalignment procedure
361380
return true;
362381
}

0 commit comments

Comments
 (0)