From 4c895c2e593adb4e7806eb6cf5351c88b002de33 Mon Sep 17 00:00:00 2001
From: Alexander van Amesfoort <amesfoort@astron.nl>
Date: Tue, 29 Aug 2017 17:47:11 +0000
Subject: [PATCH] Task #5441: COBALT RSP raw support: output .parset: improve
 guarding and LOG_WARN for invalid DataslotList value. Bogus LOG_WARN happened
 much more often than expected, e.g. on any obs with less than 75% used of max
 nr beamlets.

---
 RTCP/Cobalt/CoInterface/src/Parset.cc      |  4 ++--
 RTCP/Cobalt/OutputProc/src/OutputThread.cc | 23 ++++++++++++++--------
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/RTCP/Cobalt/CoInterface/src/Parset.cc b/RTCP/Cobalt/CoInterface/src/Parset.cc
index be93b7d9cb7..83d947cf80e 100644
--- a/RTCP/Cobalt/CoInterface/src/Parset.cc
+++ b/RTCP/Cobalt/CoInterface/src/Parset.cc
@@ -914,7 +914,7 @@ namespace LOFAR
         vector<ObservationSettings::FileLocation> locations = getFileLocations("RSPRaw");
         const bool locationsAutoDetected = locations.empty();
         if (locationsAutoDetected) {
-          LOG_INFO("RSP raw: trying to auto-detect storage locations from correlated and/or beamformed storage locations");
+          LOG_INFO("RSP raw: trying to auto-detect storage locations from correlated and/or coherent stokes and/or incoherent stokes storage locations");
           const vector<ObservationSettings::FileLocation> correlated_locations = getFileLocations("Correlated");
           const vector<ObservationSettings::FileLocation> coherent_locations   = getFileLocations("CoherentStokes");
           const vector<ObservationSettings::FileLocation> incoherent_locations = getFileLocations("IncoherentStokes");
@@ -923,7 +923,7 @@ namespace LOFAR
           locations.insert(locations.end(), coherent_locations.begin(),   coherent_locations.end());
           locations.insert(locations.end(), incoherent_locations.begin(), incoherent_locations.end());
           if (locations.empty()) {
-            THROW(CoInterfaceException, "No RSP raw locations specified and could not derive any location(s) from correlated, coherent, or incoherent file locations (even if not enabled).");
+            THROW(CoInterfaceException, "No RSP raw locations specified and could not derive any location(s) from correlated, coherent stokes, or incoherent stokes file locations (even if not enabled).");
           }
 
           // Purge duplicate hostname locations. By clearing filenames first, we can simply do sort() and unique().
diff --git a/RTCP/Cobalt/OutputProc/src/OutputThread.cc b/RTCP/Cobalt/OutputProc/src/OutputThread.cc
index 805329a0d6b..1aa976caecc 100644
--- a/RTCP/Cobalt/OutputProc/src/OutputThread.cc
+++ b/RTCP/Cobalt/OutputProc/src/OutputThread.cc
@@ -469,6 +469,21 @@ namespace LOFAR
         string rspBoardListValue(1, '[');
         for (unsigned b = 0; b < nrBoards; ++b)
         {
+          unsigned nrBeamlets = rspRawParset.settings.rspRaw.nrBeamletsPerBoardList[b];
+          if (nrBeamlets == 0) {
+            // It is valid to completely filter streams, but they must all be at the end in the list.
+            // If nrBeamlets half-way is 0 we cannot generate a valid dataslot list, which computes nrBeamlets-1.
+            for (++b; b < nrBoards; ++b) {
+              if (nrBeamlets != 0) {
+                LOG_WARN_STR("makeRspRawParset(): empty nr beamlets per board found for antenna field " <<
+                             antFieldName << " followed by non-empty nr beamlets. Observation data output unaffected, " <<
+                             "but cannot write valid DataslotList in RSP *output* parset to support offline post-processing.");
+                break;
+              }
+            }
+            break;
+          }
+
           if (b > 0) {
             rspPortsValue += ", ";
             dataslotListValue += ", ";
@@ -477,14 +492,6 @@ namespace LOFAR
 
           rspPortsValue += "file:" + rspRawParset.getFileName(RSP_RAW_DATA, af * nrBoards + b);
 
-          unsigned nrBeamlets = rspRawParset.settings.rspRaw.nrBeamletsPerBoardList[b];
-          if (nrBeamlets == 0) {
-            // It is valid to completely filter a stream, but unless it's the last stream(s) (not checked),
-            // we cannot generate a valid dataslot list w/ nrBeamlets-1. Users have to check output parset anyway.
-            LOG_WARN_STR("makeRspRawParset(): empty nr beamlets per board found for antenna field " <<
-                         antFieldName << ": setting nr beamlets to 1 to generate valid RSP *output* parset");
-            nrBeamlets = 1;
-          }
           dataslotListValue += str(boost::format("0..%u") % (nrBeamlets - 1));
           rspBoardListValue += str(boost::format("%u*%u") % nrBeamlets % b);
 
-- 
GitLab