Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/FastCaloSim/Core/TFCSBinnedShowerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ class TFCSBinnedShowerBase : public TFCSLateralShapeParametrizationHitBase
// Delete all pointers that were created in get_event()
virtual void delete_event(TFCSSimulationState& simulstate) const = 0;

// Called by TFCSSimulationState::DoAuxInfoCleanup() to free heap-allocated
// aux-info objects. Invoked automatically on simulstate destruction so that
// the BSEventData/BSNHits/BSELayer pointers are never leaked even when no
// subsequent simulate() call cleans them up first.
virtual void CleanAuxInfo(TFCSSimulationState& simulstate) const override
{
delete_event(simulstate);
}

// What should be the average energy per hit in the library
float m_default_hit_energy = 4.;
// What is the maximum number of hits per voxel (for runtime reasons)
Expand Down
1 change: 1 addition & 0 deletions include/FastCaloSim/Core/TFCSSimulationState.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FASTCALOSIM_EXPORT TFCSSimulationState
{
public:
TFCSSimulationState(CLHEP::HepRandomEngine* randomEngine = nullptr);
virtual ~TFCSSimulationState();

CLHEP::HepRandomEngine* randomEngine() { return m_randomEngine; }
void setRandomEngine(CLHEP::HepRandomEngine* engine)
Expand Down
6 changes: 6 additions & 0 deletions source/Core/TFCSBinnedShowerBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ FCSReturnCode TFCSBinnedShowerBase::simulate(
// Reset the total energy
simulstate.set_E(0);

// Register this object as a cleanup handler so that DoAuxInfoCleanup()
// (called from ~TFCSSimulationState) will invoke CleanAuxInfo() ->
// delete_event() even if no subsequent simulate() call runs first.
// AddAuxInfoCleanup uses a set, so repeated calls are idempotent.
simulstate.AddAuxInfoCleanup(this);

get_event(simulstate, eta_center, phi_center, Einit, reference_layer_index);

for (long unsigned int layer_index = 0; layer_index < m_geo->n_layers();
Expand Down
7 changes: 6 additions & 1 deletion source/Core/TFCSSimulationState.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ TFCSSimulationState::TFCSSimulationState(CLHEP::HepRandomEngine* randomEngine)
clear();
}

TFCSSimulationState::~TFCSSimulationState()
{
DoAuxInfoCleanup();
}

void TFCSSimulationState::clear()
{
set_SF(1);
m_Ebin = -1;

m_Etot = 0;
m_E.clear();
m_Efrac.clear();
Expand Down