From f64e6b34e93c0d8d2dedb01822bd046aa6b31960 Mon Sep 17 00:00:00 2001
From: Andre Offringa <offringa@astron.nl>
Date: Thu, 23 May 2024 10:30:24 +0000
Subject: [PATCH] Fix compilation on platforms where size_t != 64 bit

---
 common/ParameterSet.h          | 14 ++++++++++++++
 external/aocommon              |  2 +-
 steps/DDECal.cc                |  2 +-
 steps/test/unit/tApplyCalH5.cc | 11 +++++------
 4 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/common/ParameterSet.h b/common/ParameterSet.h
index 7b6b01125..4b585d136 100644
--- a/common/ParameterSet.h
+++ b/common/ParameterSet.h
@@ -293,6 +293,20 @@ class ParameterSet {
   std::vector<uint64_t> getUint64Vector(const std::string& aKey,
                                         const std::vector<uint64_t>& aValue,
                                         bool expandable = false) const;
+  std::vector<size_t> getSizeTVector(const std::string& aKey,
+                                     bool expandable = false) const {
+    static_assert(sizeof(size_t) == 8 || sizeof(size_t) == 4);
+    // Lambda is necessary because returning the wrong type won't compile in the
+    // main function, even when inside a if constexpr.
+    auto pick_overload = [&](const std::string& aKey, bool expandable = false) {
+      if constexpr (sizeof(size_t) == 8) {
+        return getUint64Vector(aKey, expandable);
+      } else if constexpr (sizeof(size_t) == 4) {
+        return getUint32Vector(aKey, expandable);
+      }
+    };
+    return pick_overload(aKey, expandable);
+  }
   std::vector<float> getFloatVector(const std::string& aKey,
                                     bool expandable = false) const;
   std::vector<float> getFloatVector(const std::string& aKey,
diff --git a/external/aocommon b/external/aocommon
index ea534da2f..e34551baf 160000
--- a/external/aocommon
+++ b/external/aocommon
@@ -1 +1 @@
-Subproject commit ea534da2fda4ec24329c5ca2bbee344f42806546
+Subproject commit e34551baf386a9f7c908bef7b30e0ce6194174b8
diff --git a/steps/DDECal.cc b/steps/DDECal.cc
index 3575f46b2..538e24db1 100644
--- a/steps/DDECal.cc
+++ b/steps/DDECal.cc
@@ -90,7 +90,7 @@ DDECal::DDECal(const common::ParameterSet& parset, const std::string& prefix)
 
   if (parset.isDefined(prefix + "solutions_per_direction")) {
     itsSolutionsPerDirection =
-        parset.getUint64Vector(prefix + "solutions_per_direction");
+        parset.getSizeTVector(prefix + "solutions_per_direction");
   }
 
   if (itsSolutionsPerDirection.size() > itsDirections.size()) {
diff --git a/steps/test/unit/tApplyCalH5.cc b/steps/test/unit/tApplyCalH5.cc
index 3b8750786..6689df563 100644
--- a/steps/test/unit/tApplyCalH5.cc
+++ b/steps/test/unit/tApplyCalH5.cc
@@ -21,7 +21,6 @@
 #include "../../../common/StringTools.h"
 #include "../../../common/StreamUtil.h"
 
-using casacore::max;
 using dp3::base::DPBuffer;
 using dp3::base::DPInfo;
 using dp3::common::ParameterSet;
@@ -361,13 +360,13 @@ void createH5Parm(std::vector<double> times, std::vector<double> freqs,
   soltab.SetFreqs(freqs);
   soltab.SetAntennas(antNames);
 
-  unsigned int ntimes = max(times.size(), 1);
-  unsigned int nfreqs = max(freqs.size(), 1);
+  const size_t ntimes = std::max<size_t>(times.size(), 1u);
+  const size_t nfreqs = std::max<size_t>(freqs.size(), 1u);
   std::vector<double> values(ntimes * nfreqs * nAntennas);
   std::vector<double> weights(ntimes * nfreqs * nAntennas);
-  for (unsigned int ant = 0; ant < nAntennas; ++ant) {
-    for (unsigned int t = 0; t < ntimes; ++t) {
-      for (unsigned int f = 0; f < nfreqs; ++f) {
+  for (size_t ant = 0; ant < nAntennas; ++ant) {
+    for (size_t t = 0; t < ntimes; ++t) {
+      for (size_t f = 0; f < nfreqs; ++f) {
         values[ant * ntimes * nfreqs + t * nfreqs + f] =
             1. / (100. * (t % 100) + (1 + f));
         weights[ant * ntimes * nfreqs + t * nfreqs + f] = 1.;
-- 
GitLab