From 49c6e4d6943726f846a3f75ab048a6cec09b6da5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20J=C3=BCrges?= <jurges@astron.nl>
Date: Thu, 31 Jan 2019 11:00:52 +0000
Subject: [PATCH] SW-546:  Lazy init of sub-band earlier

---
 RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc | 153 ++++++++++++-----------
 1 file changed, 79 insertions(+), 74 deletions(-)

diff --git a/RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc b/RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc
index 641a7330af2..9fcec95f836 100644
--- a/RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc
+++ b/RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc
@@ -362,6 +362,85 @@ namespace LOFAR
                        "this frame.");
                 return;
             }
+            /**
+             * Lazily initialize last part of the book keeping map from the 1st
+             * frame that is received for a sub-band.
+             * subBandBookKeeping[bandNr].isInitialised is set to false when
+             * TBB_Dipole::init gets called and sets up the book keeping map.
+             *
+             * Also create a new TBB_SubbandDataset in the DipoleGroup
+             */
+            else if(currentSubBand.isInitialised == false)
+            {
+                currentSubBand.time0 = frame.header.time;
+                currentSubBand.slice0 = sliceNr;
+
+                currentSubBand.dataSet.reset(new dal::TBB_SubbandDataset(
+                    itsDipoleGroup()->subband(bandNr)));
+                // Store the data in the hdf5 file.  Do not provide a file name!
+                currentSubBand.dataSet->create1D(currentSubBand.totalSizeInSamples,
+                    currentSubBand.totalSizeInSamples, "",
+                    currentSubBand.dataSet->LITTLE);
+
+                currentSubBand.dataSet->groupType().value = "SubbandDataset";
+
+                currentSubBand.dataSet->time().value = currentSubBand.time0;
+
+                currentSubBand.dataSet->bandNumber().value = bandNr;
+                currentSubBand.dataSet->sliceNumber().value = sliceNr;
+                currentSubBand.dataSet->samplesPerFrame().value = -1;
+                currentSubBand.dataSet->centralFrequency().value =
+                    currentSubBand.centralFrequency;
+                currentSubBand.dataSet->centralFrequencyUnit().value = "Hz";
+                currentSubBand.dataSet->timeResolution().value =
+                    SPECTRAL_TRANSFORM_SIZE /
+                        (frame.header.sampleFreq * 1000000.0);
+                currentSubBand.dataSet->timeResolutionUnit().value =
+                    "s";
+                // Filled in when the sub-band is complete:
+                currentSubBand.dataSet->dataLength().value = 0;
+                /**
+                 * ATTENTION!
+                 * Storing this value makes no sense.  Only if all frames of a
+                 * sub-band contain the same number of samples then this value
+                 * is representing something real.
+                 * But obviously this is only true if all n frames of a
+                 * sub-band, 0 < n < infinity, contain exactly the same number
+                 * of samples.
+                 *
+                 * A simple example that is pretty general where this does not
+                 * hold:
+                 * - Every sub-band that has a last frame with less than 480
+                 *   samples would have two values:  480 and the number of
+                 *   samples in the last frame.
+                 */
+                currentSubBand.dataSet->samplesPerFrame().value =
+                    frame.header.nOfSamplesPerFrame;
+
+                // TODO
+                currentSubBand.dataSet->bandwidth().value = 0;
+                currentSubBand.dataSet->bandwidthUnit().value =
+                    "not filled in";
+
+                currentSubBand.isInitialised = true;
+
+                LOG_INFO_STR("TBB:  Band #"
+                    << currentSubBand.bandNr
+                    << " initialised with the following data:  time0 = "
+                    << currentSubBand.time0
+                    << ", slice0 = "
+                    << currentSubBand.slice0
+                    << ", HDF5 SubbandDataset name = "
+                    << currentSubBand.dataSet->name()
+                    << " , dipole = "
+                    << itsDipoleGroup()->name()
+                    << ", station id = "
+                    << static_cast< uint32_t >(frame.header.stationID)
+                    << ", rsp = "
+                    << static_cast< uint32_t >(frame.header.rspID)
+                    << ", rcu = "
+                    << static_cast< uint32_t >(frame.header.rcuID));
+            }
         }
         else
         {
@@ -371,80 +450,6 @@ namespace LOFAR
             return;
         }
 
-        /**
-         * Lazily initialize last part of the book keeping map from the 1st
-         * frame that is received for a sub-band.
-         * subBandBookKeeping[bandNr].isInitialised is set to false when
-         * TBB_Dipole::init gets called and sets up the book keeping map.
-         *
-         * Also create a new TBB_SubbandDataset in the DipoleGroup
-         */
-        const uint32_t sliceNr{getSpectralModeSliceNr(frame.header)};
-        if(currentSubBand.isInitialised == false)
-        {
-            currentSubBand.time0 = frame.header.time;
-            currentSubBand.slice0 = sliceNr;
-
-            currentSubBand.dataSet.reset(new dal::TBB_SubbandDataset(
-                itsDipoleGroup()->subband(bandNr)));
-            // Store the data in the hdf5 file.  Do not provide a file name!
-            currentSubBand.dataSet->create1D(currentSubBand.totalSizeInSamples,
-                currentSubBand.totalSizeInSamples, "",
-                currentSubBand.dataSet->LITTLE);
-            currentSubBand.dataSet->groupType().value = "SubbandDataset";
-            currentSubBand.dataSet->time().value = currentSubBand.time0;
-
-            currentSubBand.dataSet->bandNumber().value = bandNr;
-            currentSubBand.dataSet->sliceNumber().value = sliceNr;
-            currentSubBand.dataSet->samplesPerFrame().value = -1;
-            // Filled in when the sub-band is complete.
-            currentSubBand.dataSet->dataLength().value = 0;
-            /**
-             * ATTENTION!
-             * Storing this value makes no sense.  Only if all frames of a
-             * sub-band contain the same number of samples then this value is
-             * representing something real.
-             * But obviously this is only true if all n frames of a sub-band,
-             * 0 < n < infinity, contain exactly the same number of samples.
-             *
-             * A simple example that is pretty general where this does not hold:
-             * - Every sub-band that has a last frame with less than 480
-             *   samples would have two values:  480 and the number of samples
-             *   in the last frame.
-             */
-            currentSubBand.dataSet->samplesPerFrame().value =
-                frame.header.nOfSamplesPerFrame;
-
-            // TODO
-            currentSubBand.dataSet->centralFrequency().value = 0;
-            currentSubBand.dataSet->centralFrequencyUnit().value =
-                "not filled in";
-            currentSubBand.dataSet->bandwidth().value = 0;
-            currentSubBand.dataSet->bandwidthUnit().value = "not filled in";
-            currentSubBand.dataSet->timeResolution().value = 1;
-            currentSubBand.dataSet->timeResolutionUnit().value =
-                "not filled in";
-
-            currentSubBand.isInitialised = true;
-
-            LOG_INFO_STR("TBB:  Band #"
-                << currentSubBand.bandNr
-                << " initialised with the following data:  time0 = "
-                << currentSubBand.time0
-                << ", slice0 = "
-                << currentSubBand.slice0
-                << ", HDF5 SubbandDataset name = "
-                << currentSubBand.dataSet->name()
-                << " , dipole = "
-                << itsDipoleGroup()->name()
-                << ", station id = "
-                << static_cast< uint32_t >(frame.header.stationID)
-                << ", rsp = "
-                << static_cast< uint32_t >(frame.header.rspID)
-                << ", rcu = "
-                << static_cast< uint32_t >(frame.header.rcuID));
-        }
-
         /**
          * Out-of-order frame arrival has not been seen for Dutch stations.
          * TBB from int'l stations is not (yet) dumped to CEP.
-- 
GitLab