Skip to content

Commit 333cdd5

Browse files
MCKinematicsReader: keep the loaded tracks instead of copying them, free the baskets
loadTracksForSourceAndEvent deep-copied the vector which ROOT allocated for us (a pointer to nullptr was passed, so it is ours) and deleted the original: +1x the event at peak (373 MB for a PbPb event with 6.5M MCTracks). The vector is now stored directly and the branch address reset. In addition, the decompressed baskets (~1x the event for the split MCTrack branch) are dropped once the event is the last entry of its TTree cluster, i.e. when no later entry can reuse them, which keeps small events sharing baskets as fast as before (QED, 10k events: 0.17 s either way, 0.70 s when dropping after every event). For the PbPb event: peak memory in use 1628 -> 1232 MB, held after releaseTracksForSourceAndEvent 882 -> 443 MB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d745182 commit 333cdd5

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎Steer/src/MCKinematicsReader.cxx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,15 @@ void MCKinematicsReader::loadTracksForSourceAndEvent(int source, int event) cons
9292
std::vector<MCTrack>* loadtracks = nullptr;
9393
br->SetAddress(&loadtracks);
9494
br->GetEntry(event);
95-
mTracks[source][event] = new std::vector<o2::MCTrack>;
96-
*mTracks[source][event] = *loadtracks;
97-
delete loadtracks;
95+
// ROOT allocated the vector for us and we own it (we passed a pointer to nullptr): keep it instead of copying it
96+
mTracks[source][event] = loadtracks;
97+
br->ResetAddress(); // the branch must not refer to the stored vector (nor to the local pointer) any more
98+
// free the decompressed baskets (~ the size of the event) if no later entry reads them, i.e. at the end of its cluster
99+
auto clusterIt = br->GetTree()->GetClusterIterator(event);
100+
clusterIt.Next();
101+
if (event + 1 >= clusterIt.GetNextEntry()) {
102+
br->DropBaskets("all");
103+
}
98104
}
99105
}
100106
}

0 commit comments

Comments
 (0)