diff --git a/RTCP/Cobalt/OutputProc/src/MeasurementSetFormat.cc b/RTCP/Cobalt/OutputProc/src/MeasurementSetFormat.cc index bee0b3ec12218a33b7d8f3093632dfe00d25c64e..0cf00e3b361a712eb92c86e28f56e7b5887afeca 100644 --- a/RTCP/Cobalt/OutputProc/src/MeasurementSetFormat.cc +++ b/RTCP/Cobalt/OutputProc/src/MeasurementSetFormat.cc @@ -146,6 +146,9 @@ namespace LOFAR void MeasurementSetFormat::createMSTables(const string &MSname, unsigned subband) { try { + int subarray = itsPS.settings.subbands[subband].SAP; + string directionType = itsPS.settings.SAPs[subarray].direction.type; + TableDesc td = MS::requiredTableDesc(); MS::addColumnToDesc(td, MS::DATA, 2); MS::addColumnToDesc(td, MS::WEIGHT_SPECTRUM, 2); @@ -153,9 +156,10 @@ namespace LOFAR // Note it must be done here, because the UVW column in the MS is readonly // (because LofarStMan is used). { + ColumnDesc &col(td.rwColumnDesc("UVW")); TableRecord rec = col.keywordSet().asRecord("MEASINFO"); - rec.define("Ref", "J2000"); + rec.define("Ref", directionType); col.rwKeywordSet().defineRecord("MEASINFO", rec); } @@ -182,9 +186,6 @@ namespace LOFAR LOG_FATAL_STR("AipsError: " << ex.what()); } - // Get subarray id (formerly known as beam). - int subarray = itsPS.settings.subbands[subband].SAP; - fillAntenna(antMPos); fillFeed(); fillField(subarray); diff --git a/RTCP/Cobalt/OutputProc/test/CMakeLists.txt b/RTCP/Cobalt/OutputProc/test/CMakeLists.txt index 5fcbb2c649bd6690bc003844e306ade153f2401a..b0def8dba9afa4c3e7b9ca9e6df74f3b0d7775b0 100644 --- a/RTCP/Cobalt/OutputProc/test/CMakeLists.txt +++ b/RTCP/Cobalt/OutputProc/test/CMakeLists.txt @@ -5,9 +5,9 @@ include(LofarCTest) if(UNITTEST++_FOUND) lofar_add_test(tSubbandWriter tSubbandWriter.cc) lofar_add_test(tOutputThread tOutputThread.cc) + lofar_add_test(tMeasurementSetFormat tMeasurementSetFormat.cc) endif() -lofar_add_test(tMeasurementSetFormat tMeasurementSetFormat.cc) lofar_add_test(tMSWriterDAL tMSWriterDAL.cc) # The MS Writer needs the LOFAR Storage manager and static meta data files. # For production, LOFARROOT is used, but build/source dir structure differs diff --git a/RTCP/Cobalt/OutputProc/test/tMeasurementSetFormat.cc b/RTCP/Cobalt/OutputProc/test/tMeasurementSetFormat.cc index 411f224f544d95cba7b5a66df4c7a935e82bea99..4cbb59da60893bbfcc86c6bd6b3a4e981b75a209 100644 --- a/RTCP/Cobalt/OutputProc/test/tMeasurementSetFormat.cc +++ b/RTCP/Cobalt/OutputProc/test/tMeasurementSetFormat.cc @@ -21,12 +21,16 @@ #include <lofar_config.h> #include <string> +#include <cstdio> #include <Common/LofarLogger.h> #include <Common/Exception.h> #include <OutputProc/MeasurementSetFormat.h> #include <casa/IO/RegularFileIO.h> +#include <casacore/tables/Tables.h> +#include <UnitTest++.h> +#include <boost/format.hpp> using namespace LOFAR; using namespace LOFAR::Cobalt; @@ -36,28 +40,58 @@ using namespace std; // Define handler that tries to print a backtrace. Exception::TerminateHandler t(Exception::terminate); +// create a MS using settings for subband 0 from a parset +void createMS(const string &parsetName, const string &msName) +{ + Parset parset(parsetName); + MeasurementSetFormat msf(parset); + msf.addSubband(msName, 0); + + // Also create the data file, otherwise it is not a true table. + RegularFileIO file(String(msName + "/table.f0data"), + ByteIO::New); +} + +string getMeasInfoRef(const string &msName) +{ + TableDesc desc; + Table::getLayout(desc, msName); + ColumnDesc &col(desc.rwColumnDesc("UVW")); + TableRecord rec = col.keywordSet().asRecord("MEASINFO"); + + String ref; + rec.get("Ref", ref); + + return ref; +} + +TEST(J2000) +{ + const string parsetName = "tMeasurementSetFormat.parset-j2000"; + const string msName = "tMeasurementSetFormat_tmp-j2000.MS"; + + LOG_DEBUG_STR("Testing " << parsetName); + createMS(parsetName, msName); + + CHECK_EQUAL("J2000", getMeasInfoRef(msName)); +} + +TEST(SUN) +{ + const string parsetName = "tMeasurementSetFormat.parset-sun"; + const string msName = "tMeasurementSetFormat_tmp-sun.MS"; + + LOG_DEBUG_STR("Testing " << parsetName); + createMS(parsetName, msName); + + CHECK_EQUAL("SUN", getMeasInfoRef(msName)); +} + + int main() { INIT_LOGGER("tMeasurementSetFormat"); - const string suffixes[] = { "-j2000", "-sun" }; - - for( unsigned i = 0; i < sizeof suffixes / sizeof suffixes[0]; i++ ) - { - const string parsetName = string("tMeasurementSetFormat.parset") + suffixes[i]; - const string msName = string("tMeasurementSetFormat_tmp") + suffixes[i] + ".MS"; - - LOG_DEBUG_STR("Testing " << parsetName); - - Parset parset(parsetName); - MeasurementSetFormat msf(parset); - msf.addSubband(msName, 0); - // Also create the data file, otherwise it is not a true table. - ///FILE* file= fopen ("tMeasurementSetFormat_tmp.ms/f0data", "w"); - ///fclose (file); - RegularFileIO file(String(msName + "/table.f0data"), - ByteIO::New); - } - - return 0; + + return UnitTest::RunAllTests() > 0; }