From 4c99d521e0126064c26f3f4f7356d4a92a12cefa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20J=C3=BCrges?= <jurges@astron.nl>
Date: Thu, 31 Jan 2019 15:21:43 +0000
Subject: [PATCH] SW-546:  Simplify the dtor a bit

---
 RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc | 94 +++++++++++++++---------
 1 file changed, 59 insertions(+), 35 deletions(-)

diff --git a/RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc b/RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc
index 657b0ae8cc0..cb8b1d391d7 100644
--- a/RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc
+++ b/RTCP/Cobalt/OutputProc/src/TBB_Dipole.cc
@@ -158,43 +158,67 @@ namespace LOFAR
 
     TBB_Dipole::~TBB_Dipole()
     {
-      // Executed by the main thread after joined with all workers, so no need to lock or delay cancellation.
-      if (isInitialized()) {
-        try {
-          if (doTransient()) {
-            itsDipoleDataset()->resize1D(itsDumpInfo.itsDatasetLen);
-          } else { // spectral mode
-            //itsDipoleGroup()->resize1D(itsDumpInfo.itsDatasetLen * 2); // TODO: remove times 2 once DAL supports TBB spectral dataset of complex<int16_t>. Also, use resize() if switched to create() (2D).
-          }
-        } catch (exception& exc) { // dal::DALException, or std::bad_alloc from vector constr
-          LOG_WARN_STR("TBB: failed to resize HDF5 dipole dataset to external data size: " << exc.what());
-        }
+        /**
+         * Executed by the main thread after joined with all workers, so no
+         * need to lock or delay cancellation.
+         */
+        if(isInitialized())
+        {
+            const bool transientMode(doTransient());
+            try
+            {
+                if(transientMode == true)
+                {
+                    itsDipoleDataset()->resize1D(itsDumpInfo.itsDatasetLen);
+                }
+            }
+            catch(exception& exc)
+            {
+                // dal::DALException, or std::bad_alloc from vector constr
+                LOG_WARN_STR("TBB: failed to resize HDF5 dipole dataset to "
+                    "external data size: "
+                    << exc.what());
+            }
 
-        try {
-          // Thus in values (scalar for transient mode, complex for subband mode)
-          if (doTransient()) {
-            itsDipoleDataset()->dataLength().value = itsDumpInfo.itsDatasetLen;
-          } else { // spectral mode
-            //TODO: fill in
-          }
-        } catch (dal::DALException& exc) {
-          LOG_WARN_STR("TBB: failed to set dipole DATA_LENGTH attribute: " << exc.what());
-        }
-        try {
-          /*
-           * We write flags at the end, because HDF5 attributes can only be (re)set, not updated.
-           * TODO: If an .h5 internal (non-chunked!) 1D dataset would be possible without pre-specifying size,
-           * that would be better. Then we can write flags while data comes in. Else, leave as-is.
-           */
-          if (doTransient()) {
-            itsDipoleDataset()->flagOffsets().create(itsDumpInfo.itsFlagOffsets.size()).set(itsDumpInfo.itsFlagOffsets);
-          } else { // spectral mode
-            //TODO: fill in
-          }
-        } catch (dal::DALException& exc) {
-          LOG_WARN_STR("TBB: failed to set dipole FLAG_OFFSETS attribute: " << exc.what());
+            try
+            {
+                // Thus in values (scalar for transient mode, complex for subband mode)
+                if(transientMode == true)
+                {
+                    itsDipoleDataset()->dataLength().value =
+                        itsDumpInfo.itsDatasetLen;
+                }
+            }
+            catch(dal::DALException& exc)
+            {
+                LOG_WARN_STR("TBB: failed to set dipole DATA_LENGTH attribute: "
+                    << exc.what());
+            }
+            try
+            {
+                /**
+                 * We write flags at the end, because HDF5 attributes can only
+                 * be (re)set, not updated.
+                 *
+                 * TODO: If an .h5 internal (non-chunked!) 1D dataset would be
+                 * possible without pre-specifying size, that would be better.
+                 * Then we can write flags while data comes in. Else, leave
+                 * as-is.
+                 */
+                if(doTransient())
+                {
+                    itsDipoleDataset()->flagOffsets().create(
+                        itsDumpInfo.itsFlagOffsets.size()).set(
+                            itsDumpInfo.itsFlagOffsets);
+                }
+            }
+            catch(dal::DALException& exc)
+            {
+                LOG_WARN_STR("TBB: failed to set dipole FLAG_OFFSETS "
+                    "attribute: "
+                    << exc.what());
+            }
         }
-      }
     }
 
     // Add a new flag range at the end or extend the last stored flag range. 'len' may not be 0.
-- 
GitLab