Skip to content
Snippets Groups Projects
Commit fd93e2fb authored by Thomas Jürges's avatar Thomas Jürges
Browse files

SW-546: Change the offset type to int64_t

Offsets can also be negative.  A uint64_t obviously cannot accomodate negative
values.
parent 89d0551c
No related branches found
No related tags found
No related merge requests found
...@@ -295,9 +295,9 @@ namespace LOFAR ...@@ -295,9 +295,9 @@ namespace LOFAR
* but this makes flagging lost packets more complicated than how we deal with it using appendFlags() below. * but this makes flagging lost packets more complicated than how we deal with it using appendFlags() below.
* Also, fake out-of-order occurs when data is dumped (incorrectly) across the frozen TBB write pointer (LOFAR control bug). * Also, fake out-of-order occurs when data is dumped (incorrectly) across the frozen TBB write pointer (LOFAR control bug).
*/ */
if (frame.header.time < itsDumpInfo.itsTime0 || if(frame.header.time < itsDumpInfo.itsTime0
((frame.header.time == itsDumpInfo.itsTime0) || ((frame.header.time == itsDumpInfo.itsTime0)
&& (sliceNr < itsDumpInfo.itsSliceNr0))) && (sliceNr < itsDumpInfo.itsSliceNr0)))
{ {
logErrorRateLimited(&itsLastLogErrorTime, "TBB: received an " logErrorRateLimited(&itsLastLogErrorTime, "TBB: received an "
"out-of-order packet! Current start time of first frame for " "out-of-order packet! Current start time of first frame for "
...@@ -316,18 +316,22 @@ namespace LOFAR ...@@ -316,18 +316,22 @@ namespace LOFAR
* actually falls half-way). * actually falls half-way).
* *
* Calculate the offset of the frame start from the time stamp of the * Calculate the offset of the frame start from the time stamp of the
* first received frame. * first received frame. Use 64 bit integers so that negative numbers
* can be handled.
*/ */
uint64_t offset = frame.header.time - itsDumpInfo.itsTime0; int64_t offset{frame.header.time};
LOG_INFO_STR("TBBDipole: offset = frame.header.time - itsDumpInfo.itsTime0" offset -= itsDumpInfo.itsTime0;
LOG_INFO_STR("TBB: offset = frame.header.time - itsDumpInfo.itsTime0"
<< offset << ", " << frame.header.time << ", " << itsDumpInfo.itsTime0); << offset << ", " << frame.header.time << ", " << itsDumpInfo.itsTime0);
/** /**
* Convert the offset in [s] to samples containing a complex numbers of * Convert the offset in [s] to the total number of samples (containing a
* two 16 bit integers. sampleFreq is in MHz. * complex number of two 16 bit integers). sampleFreq is in MHz.
*/ */
offset *= (frame.header.sampleFreq * 1000000U); offset *= (frame.header.sampleFreq * 1000000);
LOG_INFO_STR("TBBDipole: offset *= (frame.header.sampleFreq * 1000000U)" LOG_INFO_STR("TBB: offset *= (frame.header.sampleFreq * 1000000)"
<< offset << ", " << static_cast< uint32_t >(frame.header.sampleFreq)); << offset << ", " << static_cast< uint32_t >(frame.header.sampleFreq));
/** /**
* Divide the offset, i.e. the number of samples by the size of an FFT * Divide the offset, i.e. the number of samples by the size of an FFT
* block. The result is the index of the raw voltage sampling window * block. The result is the index of the raw voltage sampling window
...@@ -344,7 +348,7 @@ namespace LOFAR ...@@ -344,7 +348,7 @@ namespace LOFAR
* the begin of a voltage window is also the begin of a frequency window. * the begin of a voltage window is also the begin of a frequency window.
*/ */
offset /= SPECTRAL_TRANSFORM_SIZE; offset /= SPECTRAL_TRANSFORM_SIZE;
LOG_INFO_STR("TBBDipole: offset /= SPECTRAL_TRANSFORM_SIZE" LOG_INFO_STR("TBB: offset /= SPECTRAL_TRANSFORM_SIZE"
<< offset << ", " << SPECTRAL_TRANSFORM_SIZE); << offset << ", " << SPECTRAL_TRANSFORM_SIZE);
/** /**
...@@ -359,7 +363,7 @@ namespace LOFAR ...@@ -359,7 +363,7 @@ namespace LOFAR
*/ */
if(frame.header.sampleFreq == 200) if(frame.header.sampleFreq == 200)
{ {
uint32_t time0{itsDumpInfo.itsTime0}; int64_t time0{itsDumpInfo.itsTime0};
/** /**
* Is the current frame not the first frame and is its time stamp an * Is the current frame not the first frame and is its time stamp an
* even number? * even number?
...@@ -383,15 +387,16 @@ namespace LOFAR ...@@ -383,15 +387,16 @@ namespace LOFAR
offset += (frame.header.time - time0) / 2; // 1 extra slice every 2 seconds offset += (frame.header.time - time0) / 2; // 1 extra slice every 2 seconds
} }
LOG_INFO_STR("TBBDipole: offset after even second correction = " LOG_INFO_STR("TBB: offset after even second correction = " << offset);
<< offset);
/** /**
* Add to the offset * Add to the offset
* Attention! * Attention!
* Both slice numbers are already divided by 1024! * Both slice numbers are already divided by 1024!
*/ */
offset += sliceNr - itsDumpInfo.itsSliceNr0; offset += sliceNr;
LOG_INFO_STR("TBBDipole: offset += sliceNr - itsDumpInfo.itsSliceNr0" offset -= itsDumpInfo.itsSliceNr0;
LOG_INFO_STR("TBB: offset += sliceNr - itsDumpInfo.itsSliceNr0"
<< offset << ", " << sliceNr << ", " << itsDumpInfo.itsSliceNr0 << offset << ", " << sliceNr << ", " << itsDumpInfo.itsSliceNr0
<< ", " << SPECTRAL_TRANSFORM_SIZE); << ", " << SPECTRAL_TRANSFORM_SIZE);
...@@ -451,7 +456,7 @@ namespace LOFAR ...@@ -451,7 +456,7 @@ namespace LOFAR
// TODO 20181127: do we have enough reserved space to write all subbands in one file? // TODO 20181127: do we have enough reserved space to write all subbands in one file?
// Since we are writing around HDF5, there is no need to lock. Resize the HDF5 dataset in the destructor. // Since we are writing around HDF5, there is no need to lock. Resize the HDF5 dataset in the destructor.
LOG_INFO_STR("TBBDipole: offset passed to pwrite:" LOG_INFO_STR("TBB: offset passed to pwrite:"
<< offset << ", offset casted for pwrite = " << (off_t)(offset * 2 * sizeof(int16_t))); << offset << ", offset casted for pwrite = " << (off_t)(offset * 2 * sizeof(int16_t)));
pwrite(itsDumpInfo.itsRawFile->fd, frame.payload.data, frame.header.nOfSamplesPerFrame * 2 * sizeof(int16_t), pwrite(itsDumpInfo.itsRawFile->fd, frame.payload.data, frame.header.nOfSamplesPerFrame * 2 * sizeof(int16_t),
(off_t)(offset * 2 * sizeof(int16_t))); (off_t)(offset * 2 * sizeof(int16_t)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment