From 302bf02e16b0e320a4232619408d3d6d39f6e309 Mon Sep 17 00:00:00 2001
From: Chris Broekema <broekema@astron.nl>
Date: Tue, 18 Aug 2009 15:08:45 +0000
Subject: [PATCH] Bug #1011: Added RSP TimeStamp to logging

---
 RTCP/Storage/include/Storage/RTStorage.h     |  2 ++
 RTCP/Storage/include/Storage/SubbandWriter.h |  3 +++
 RTCP/Storage/src/RTStorage.cc                | 17 ++++++++++++++---
 RTCP/Storage/src/SubbandWriter.cc            | 15 +++++++++++++--
 4 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/RTCP/Storage/include/Storage/RTStorage.h b/RTCP/Storage/include/Storage/RTStorage.h
index 70a435a8234..f34c7a68008 100644
--- a/RTCP/Storage/include/Storage/RTStorage.h
+++ b/RTCP/Storage/include/Storage/RTStorage.h
@@ -18,6 +18,7 @@
 #include <Interface/Exceptions.h>
 #include <Interface/PipelineOutput.h>
 #include <Interface/MultiDimArray.h>
+#include <Interface/RSPTimeStamp.h>
 
 #include <Storage/Format.h>
 #include <Storage/InputThread.h>
@@ -50,6 +51,7 @@ namespace LOFAR {
 				       // writes, for O_DIRECT
       Matrix<int>  itsPreviousSequenceNumbers;
       
+      TimeStamp    itsSyncedStamp;
 
       NSTimer itsWriteTimer;
       double  bytesWritten;
diff --git a/RTCP/Storage/include/Storage/SubbandWriter.h b/RTCP/Storage/include/Storage/SubbandWriter.h
index 53affa58ede..14e62f29499 100644
--- a/RTCP/Storage/include/Storage/SubbandWriter.h
+++ b/RTCP/Storage/include/Storage/SubbandWriter.h
@@ -38,6 +38,7 @@
 #include <Interface/PipelineOutput.h>
 #include <Interface/StreamableData.h>
 #include <Interface/Queue.h>
+#include <Interface/RSPTimeStamp.h>
 #include <Storage/InputThread.h>
 #include <Stream/Stream.h>
 
@@ -96,6 +97,8 @@ class SubbandWriter
 
     NSTimer		    itsWriteTimer;
 
+    TimeStamp               itsSyncedStamp;
+
 #ifdef USE_MAC_PI
     bool itsWriteToMAC;
     GCF::CEPPMLlight::CEPPropertySet* itsPropertySet;
diff --git a/RTCP/Storage/src/RTStorage.cc b/RTCP/Storage/src/RTStorage.cc
index 7861486abc9..860ebaf9aae 100644
--- a/RTCP/Storage/src/RTStorage.cc
+++ b/RTCP/Storage/src/RTStorage.cc
@@ -58,6 +58,14 @@ RTStorage::~RTStorage()
   
 void RTStorage::preprocess() 
 {
+  const double startTime    = itsPS->startTime();
+  const double sampleFreq   = itsPS->sampleRate();
+  const unsigned seconds    = static_cast<unsigned>(floor(startTime));
+  const unsigned samples    = static_cast<unsigned>((startTime - floor(startTime)) * sampleFreq);
+
+  itsSyncedStamp.setStationClockSpeed(static_cast<unsigned>(sampleFreq * 1024));
+  itsSyncedStamp = TimeStamp(seconds, samples);
+
   /// Get various observation parameters
   itsNrSubbands = itsPS->nrSubbands();
   if (itsNrSubbands % itsSize == 0) {
@@ -115,7 +123,7 @@ void RTStorage::preprocess()
 
       itsPreviousSequenceNumbers[i][j] = -1;
     }
-  }    
+  }
 }
 
 
@@ -175,7 +183,10 @@ void RTStorage::writeLogMessage()
 #if defined HAVE_MPI
 	       ", rank = " << itsRank <<
 #endif
-	       ", count = " << counter ++);
+	       ", count = " << counter ++ <<
+	       ", timestamp = " << itsSyncedStamp);
+
+  itsSyncedStamp += itsPS->nrSubbandSamples() * itsPS->IONintegrationSteps();
 }
 
 
@@ -213,7 +224,7 @@ bool RTStorage::processSubband(unsigned sb)
   itsWriteTimer.start();
   /// write data to correct fd
   for (unsigned i = 0; i < itsNrOutputs; i++) {
-    data->write( myFDs[sb][i], true, itsAlignment);
+    data->write( myFDs[sb][i], true, itsAlignment );
   }
   itsWriteTimer.stop();
 
diff --git a/RTCP/Storage/src/SubbandWriter.cc b/RTCP/Storage/src/SubbandWriter.cc
index 730826255e5..58982e944ab 100644
--- a/RTCP/Storage/src/SubbandWriter.cc
+++ b/RTCP/Storage/src/SubbandWriter.cc
@@ -164,6 +164,14 @@ void SubbandWriter::preprocess()
     itsNrSubbandsPerStorage = (itsNrSubbands / itsSize) + 1;
   }
 
+
+  const double sampleFreq   = itsPS->sampleRate();
+  const unsigned seconds    = static_cast<unsigned>(floor(startTime));
+  const unsigned samples    = static_cast<unsigned>((startTime - floor(startTime)) * sampleFreq);
+
+  itsSyncedStamp.setStationClockSpeed(static_cast<unsigned>(sampleFreq * 1024));
+  itsSyncedStamp = TimeStamp(seconds, samples);
+
   LOG_TRACE_VAR_STR("SubbandsPerStorage = " << itsNrSubbandsPerStorage);
 
   itsMyNrSubbands = 0;
@@ -281,9 +289,12 @@ void SubbandWriter::writeLogMessage()
 
   LOG_INFO_STR("time = " << buf <<
 #if defined HAVE_MPI
-	  ", rank = " << itsRank <<
+	       ", rank = " << itsRank <<
 #endif
-	  ", count = " << counter ++);
+	       ", count = " << counter ++ <<
+	       ", timestamp = " << itsSyncedStamp) ;
+  
+  itsSyncedStamp += itsPS->nrSubbandSamples() * itsPS->IONintegrationSteps();
 }
 
 
-- 
GitLab