From ee3d28c413df983c2e6f6fae722ca58a7c6e62f2 Mon Sep 17 00:00:00 2001 From: Paul Veen Date: Thu, 13 Nov 2025 16:55:30 +0100 Subject: [PATCH 1/2] [Common] Fix memory leak Memory leak which seems to have a strong effect on memory usage and performance when multiple matching candidates are saved. Fixed by introducing TrackRealigned class that deletes in destructor of the class. --- Common/Tasks/qaMuon.cxx | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Common/Tasks/qaMuon.cxx b/Common/Tasks/qaMuon.cxx index 7a0d1497e49..0fcb4dea54e 100644 --- a/Common/Tasks/qaMuon.cxx +++ b/Common/Tasks/qaMuon.cxx @@ -241,6 +241,22 @@ struct muonQa { Configurable nolaterthanRealign{"ccdb-no-later-than-new", std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object of new basis"}; } configCCDB; + // Derived version of mch::Track class that handles the associated clusters as internal objects and deletes them in the destructor + class TrackRealigned : public mch::Track + { + public: + TrackRealigned() = default; + ~TrackRealigned() + { + // delete the clusters associated to this track + for (const auto& par : *this) { + if (par.getClusterPtr()) { + delete par.getClusterPtr(); + } + } + } + }; + //// Variables for histograms configuration Configurable fNCandidatesMax{"nCandidatesMax", 5, ""}; @@ -1465,7 +1481,7 @@ struct muonQa { } template - bool FillClusters(TMCHTrack const& muon, TFwdCls const& mchcls, Var& fgValues, mch::Track& convertedTrack) + bool FillClusters(TMCHTrack const& muon, TFwdCls const& mchcls, Var& fgValues, TrackRealigned& convertedTrack) { int removable = 0; auto clustersSliced = mchcls.sliceBy(perMuon, muon.globalIndex()); // Slice clusters by muon id @@ -2325,7 +2341,7 @@ struct muonQa { } //// Fill MCH clusters: do re-alignment if asked - mch::Track mchrealignedTmp; + TrackRealigned mchrealignedTmp; VarClusters fgValuesClsTmp; if (!FillClusters(muon, clusters, fgValuesClsTmp, mchrealignedTmp)) { continue; // Refit is not valid @@ -2424,7 +2440,7 @@ struct muonQa { FillPropagation<1>(muon, fgValuesColl, fgValuesMCH, fgValuesMCHpv); // copied in a separate variable //// Fill MCH clusters: re-align clusters if required - mch::Track mchrealigned; + TrackRealigned mchrealigned; VarClusters fgValuesCls; if (!FillClusters(muon, clusters, fgValuesCls, mchrealigned)) { continue; // if refit was not passed @@ -2501,7 +2517,7 @@ struct muonQa { FillPropagation<1>(mchtrack, fgValuesCollMCH, VarTrack{}, fgValuesMCHpv); // saved in separate variable fgValuesMCHpv //// Fill MCH clusters: re-align clusters if required - mch::Track mchrealigned; + TrackRealigned mchrealigned; VarClusters fgValuesCls; if (!FillClusters(mchtrack, clusters, fgValuesCls, mchrealigned)) { continue; // if refit was not passed @@ -2589,7 +2605,7 @@ struct muonQa { VarTrack fgValuesMuon1, fgValuesMuonPV1; VarTrack fgValuesMuon2, fgValuesMuonPV2; - mch::Track mchrealigned1, mchrealigned2; + TrackRealigned mchrealigned1, mchrealigned2; VarClusters fgValuesCls1, fgValuesCls2; if (!FillClusters(muonTrack1, clusters, fgValuesCls1, mchrealigned1) || !FillClusters(muonTrack2, clusters, fgValuesCls2, mchrealigned2)) { continue; // Refit is not valid @@ -3092,7 +3108,7 @@ struct muonQa { VarTrack fgValuesMuon1, fgValuesMuonPV1; VarTrack fgValuesMuon2, fgValuesMuonPV2; - mch::Track mchrealigned1, mchrealigned2; + TrackRealigned mchrealigned1, mchrealigned2; VarClusters fgValuesCls1, fgValuesCls2; if (!FillClusters(muonTrack1, clusters, fgValuesCls1, mchrealigned1) || !FillClusters(muonTrack2, clusters, fgValuesCls2, mchrealigned2)) { continue; // Refit is not valid @@ -3249,7 +3265,7 @@ struct muonQa { FillMatching(muonTrack1, fgValuesMCH1, fgValuesMFT1); FillMatching(muonTrack2, fgValuesMCH2, fgValuesMFT2); - mch::Track mchrealigned1, mchrealigned2; + TrackRealigned mchrealigned1, mchrealigned2; VarClusters fgValuesCls1, fgValuesCls2; if (!FillClusters(mchTrack1, clusters, fgValuesCls1, mchrealigned1) || !FillClusters(mchTrack2, clusters, fgValuesCls2, mchrealigned2)) { continue; // Refit is not valid From a72ee5bd00f1a93c3d7642be3609dddd5300f864 Mon Sep 17 00:00:00 2001 From: Paul Veen Date: Thu, 13 Nov 2025 17:00:01 +0100 Subject: [PATCH 2/2] Fixed PR formatting --- Common/Tasks/qaMuon.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/Tasks/qaMuon.cxx b/Common/Tasks/qaMuon.cxx index 0fcb4dea54e..c1e7ececa36 100644 --- a/Common/Tasks/qaMuon.cxx +++ b/Common/Tasks/qaMuon.cxx @@ -244,7 +244,7 @@ struct muonQa { // Derived version of mch::Track class that handles the associated clusters as internal objects and deletes them in the destructor class TrackRealigned : public mch::Track { - public: + public: TrackRealigned() = default; ~TrackRealigned() {