Skip to content

Commit f019420

Browse files
sawenzelclaude
andcommitted
Adopt decoded hit containers in the o2-sim hit merger
This removes a full copy of every hit container that reaches the hit merger as a TMessage. - collectHits allocated a new container, copied the decoded one into it and deleted the original. - It now takes ownership of the decoded container. - Hits in shared memory belong to the worker and are still copied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 35c4f5c commit f019420

1 file changed

Lines changed: 11 additions & 26 deletions

File tree

‎Detectors/Base/include/DetectorsBase/Detector.h‎

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -569,40 +569,25 @@ class DetImpl : public o2::base::Detector
569569
using HitPtr_t = decltype(static_cast<Det*>(this)->Det::getHits(probe));
570570
std::string name = static_cast<Det*>(this)->getHitBranchNames(probe);
571571

572-
auto copyToBuffer = [this, eventID](HitPtr_t hitdata, Collector_t& collectbuffer, int probe) {
573-
std::vector<std::vector<std::unique_ptr<Hit_t>>>* hitvector = nullptr;
574-
{
575-
auto eventIter = collectbuffer.find(eventID);
576-
if (eventIter == collectbuffer.end()) {
577-
// key insertion and traversal are thread-safe with tbb so no need
578-
// to protect
579-
collectbuffer[eventID] = std::vector<std::vector<std::unique_ptr<Hit_t>>>();
580-
}
581-
hitvector = &(collectbuffer[eventID]);
582-
}
583-
if (probe >= hitvector->size()) {
584-
hitvector->resize(probe + 1);
572+
// stores one hit container of this event and probe in the collector
573+
auto store = [eventID, &hitcollector](std::unique_ptr<Hit_t> hits, int probe) {
574+
auto& hitvector = hitcollector[eventID]; // tbb insertion is thread-safe
575+
if (probe >= hitvector.size()) {
576+
hitvector.resize(probe + 1);
585577
}
586-
// add empty hit bucket to list for this event and probe
587-
(*hitvector)[probe].emplace_back(new Hit_t());
588-
// copy the data into this bucket
589-
*((*hitvector)[probe].back()) = *hitdata;
578+
hitvector[probe].emplace_back(std::move(hits));
590579
};
591580

592581
while (name.size() > 0) {
593582
if (!shm) {
594-
// for each branch name we extract/decode hits from the message parts ...
595-
auto hitsptr = decodeTMessage<HitPtr_t>(parts, index++);
596-
if (hitsptr) {
597-
// ... and copy them to the buffer
598-
copyToBuffer(hitsptr, hitcollector, probe);
599-
delete hitsptr;
583+
// a decoded TMessage is ours, so we adopt it
584+
if (auto hitsptr = decodeTMessage<HitPtr_t>(parts, index++)) {
585+
store(std::unique_ptr<Hit_t>(hitsptr), probe);
600586
}
601587
} else {
602-
// for each branch name we extract/decode hits from the message parts ...
588+
// hits in shared memory belong to the worker, so we copy them
603589
auto hitsptr = decodeShmMessage<HitPtr_t>(parts, index++, busy);
604-
// ... and copy them to the buffer
605-
copyToBuffer(hitsptr, hitcollector, probe);
590+
store(std::make_unique<Hit_t>(*hitsptr), probe);
606591
}
607592
// next name
608593
probe++;

0 commit comments

Comments
 (0)