From b4cda71870da80c81a603f040f7cd5f3d251c54c Mon Sep 17 00:00:00 2001
From: Dominik Smith <smith@th.physik.uni-frankfurt.de>
Date: Thu, 6 Jul 2023 12:23:59 +0200
Subject: [PATCH] Added vector memory reservation to unpackers in cbm::algo.

---
 algo/detectors/bmon/UnpackBmon.cxx | 3 +++
 algo/detectors/much/UnpackMuch.cxx | 3 +++
 algo/detectors/tof/UnpackTof.cxx   | 3 +++
 3 files changed, 9 insertions(+)

diff --git a/algo/detectors/bmon/UnpackBmon.cxx b/algo/detectors/bmon/UnpackBmon.cxx
index 475a3093e0..8719d9593c 100644
--- a/algo/detectors/bmon/UnpackBmon.cxx
+++ b/algo/detectors/bmon/UnpackBmon.cxx
@@ -44,6 +44,9 @@ namespace cbm::algo
     // --- Interpret MS content as sequence of SMX messages
     auto message = reinterpret_cast<const critof001::Message*>(msContent);
 
+    const uint32_t maxDigis = numMessages - 2;  // -2 for the TS_MSB and EPOCH messages
+    result.first.reserve(maxDigis);
+
     // --- The first message in the MS is expected to be of type EPOCH.
     if (message[0].getMessageType() != critof001::MSG_EPOCH) {
       result.second.fNumErrInvalidFirstMessage++;
diff --git a/algo/detectors/much/UnpackMuch.cxx b/algo/detectors/much/UnpackMuch.cxx
index 850f5ef1f5..4ebd73300d 100644
--- a/algo/detectors/much/UnpackMuch.cxx
+++ b/algo/detectors/much/UnpackMuch.cxx
@@ -49,6 +49,9 @@ namespace cbm::algo
       return result;
     }
 
+    const uint32_t maxDigis = numMessages - 2;  // -2 for the TS_MSB and EPOCH messages
+    result.first.reserve(maxDigis);
+
     // --- Interpret MS content as sequence of SMX messages
     auto message = reinterpret_cast<const stsxyter::Message*>(msContent);
 
diff --git a/algo/detectors/tof/UnpackTof.cxx b/algo/detectors/tof/UnpackTof.cxx
index 5ce7650562..7bd71d827e 100644
--- a/algo/detectors/tof/UnpackTof.cxx
+++ b/algo/detectors/tof/UnpackTof.cxx
@@ -44,6 +44,9 @@ namespace cbm::algo
     // --- Interpret MS content as sequence of Critof messages
     auto message = reinterpret_cast<const critof001::Message*>(msContent);
 
+    const uint32_t maxDigis = numMessages - 2;  // -2 for the TS_MSB and EPOCH messages
+    result.first.reserve(maxDigis);
+
     // --- The first message in the MS is expected to be of type EPOCH.
     if (message[0].getMessageType() != critof001::MSG_EPOCH) {
       result.second.fNumErrInvalidFirstMessage++;
-- 
GitLab