Skip to content

Commit

Permalink
Adjust component deletion order
Browse files Browse the repository at this point in the history
This is in response to GlueX filling histograms in component destructors
  • Loading branch information
nathanwbrei committed Dec 5, 2024
1 parent 1a5c914 commit 2605036
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/libraries/JANA/Services/JComponentManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,33 @@ JComponentManager::JComponentManager() {

JComponentManager::~JComponentManager() {

for (auto* src : m_evt_srces) {
delete src;
}
for (auto* proc : m_evt_procs) {
delete proc;
for (auto* src_gen : m_src_gens) {
delete src_gen;
}
for (auto* fac_gen : m_fac_gens) {
delete fac_gen;
}
for (auto* src_gen : m_src_gens) {
delete src_gen;

for (auto* src : m_evt_srces) {
LOG_TRACE(GetLogger()) << "Destroying source with type=" << src->GetTypeName();
delete src;
}
for (auto* unfolder : m_unfolders) {
LOG_TRACE(GetLogger()) << "Destroying unfolder with type=" << unfolder->GetTypeName();
delete unfolder;
}

// The order of deletion here sadly matters, because GlueX likes to fill
// histograms inside component destructors. Thus event processors must be destroyed after
// all other components, and the last component to be destroyed should be the _first_ event
// processor, because that's the one that is usually provided by the main program and handles
// the ROOT output file. We may eventually want to move all ROOT file operations to a separate
// JService which would be closed and destroyed after all other components.

for (int i=m_evt_procs.size()-1; i >= 0; --i) {
LOG_TRACE(GetLogger()) << "Destroying processor with type=" << m_evt_procs[i]->GetTypeName();
delete m_evt_procs[i];
}
}

void JComponentManager::Init() {
Expand Down
1 change: 1 addition & 0 deletions src/libraries/JANA/Topology/JTopologyBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ void JTopologyBuilder::attach_level(JEventLevel current_level, JUnfoldArrow* par
// --------------------------
JEventPool* pool_at_level = new JEventPool(m_components, m_max_inflight_events, m_location_count, current_level);
pools.push_back(pool_at_level); // Hand over ownership of the pool to the topology
LOG_INFO(GetLogger()) << "Created event pool with level=" << current_level << " and size=" << m_max_inflight_events;

// --------------------------
// 1. Source
Expand Down

0 comments on commit 2605036

Please sign in to comment.