diff --git a/CMakeLists.txt b/CMakeLists.txt index eb16dd4a8ae0822ba947fa69acb4e5fbbe585964..121f6f4fd357eaef45f85f5eebe67c4ba953e600 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -580,12 +580,12 @@ if(BUILD_TESTING) set(OS_SPECIFIC_TESTS) # No specific tests for Apple else() # These run only on Linux - set(OS_SPECIFIC_TESTS # steps/dynamic_test_step/test/tDynamicTestStep.cc # - # This test still fails - ) - add_library(dp3_testdyndp3 SHARED + # Note: The tests in tDynamicTestStep still fail and are disabled. + # TODO(AST-1045): Either remove or test this feature. + set(OS_SPECIFIC_TESTS steps/dynamic_test_step/test/tDynamicTestStep.cc) + add_library(DP3_testdyndp3 SHARED steps/dynamic_test_step/DynamicTestStep.cc) - target_link_libraries(dp3_testdyndp3 LIBDP3) + target_link_libraries(DP3_testdyndp3 LIBDP3) endif() set(TEST_FILENAMES diff --git a/base/DP3.cc b/base/DP3.cc index e3dbefa4c2d7dc0ac6cf339bf5e5cda66434ff78..da16fe30d3df1fae45da1c615810872367ee3cff 100644 --- a/base/DP3.cc +++ b/base/DP3.cc @@ -75,7 +75,7 @@ namespace dp3 { namespace base { // Initialize the statics. -std::map<std::string, DP3::StepCtor*> DP3::theirStepMap; +std::map<std::string, DP3::StepCreator*> DP3::theirStepMap; /// Create an output step, either an MSWriter, MSUpdater or an MSBDAWriter /// If no data are modified (for example if only count was done), @@ -220,7 +220,7 @@ static std::shared_ptr<Step> makeSingleStep(const std::string& type, step = std::make_shared<steps::NullStep>(); } else { // Maybe the step is defined in a dynamic library. - step = DP3::findStepCtor(type)(inputStep, parset, prefix); + step = DP3::FindStepCreator(type)(parset, prefix); } if (!step) { throw std::runtime_error("Could not create step of type '" + type + "'"); @@ -228,12 +228,12 @@ static std::shared_ptr<Step> makeSingleStep(const std::string& type, return step; } -void DP3::registerStepCtor(const std::string& type, StepCtor* func) { +void DP3::RegisterStepCreator(const std::string& type, StepCreator* func) { theirStepMap[type] = func; } -DP3::StepCtor* DP3::findStepCtor(const std::string& type) { - std::map<std::string, StepCtor*>::const_iterator iter = +DP3::StepCreator* DP3::FindStepCreator(const std::string& type) { + std::map<std::string, StepCreator*>::const_iterator iter = theirStepMap.find(type); if (iter != theirStepMap.end()) { return iter->second; @@ -250,8 +250,7 @@ DP3::StepCtor* DP3::findStepCtor(const std::string& type) { } // Try to load and initialize the dynamic library. - casacore::DynLib dl(libname, string("libdppp_"), "register_" + libname, - false); + casacore::DynLib dl(libname, "libDP3_", "register_" + libname, false); if (dl.getHandle()) { // See if registered now. iter = theirStepMap.find(type); @@ -262,7 +261,7 @@ DP3::StepCtor* DP3::findStepCtor(const std::string& type) { throw std::runtime_error( "Step type " + type + " is unknown and no shared library lib" + libname + - " or libdppp_" + libname + " found in (DY)LD_LIBRARY_PATH"); + " or libDP3_" + libname + " found in (DY)LD_LIBRARY_PATH"); } dp3::common::Fields DP3::GetChainRequiredFields( @@ -298,7 +297,7 @@ dp3::common::Fields DP3::SetChainProvidedFields( return provided_fields; } -void DP3::execute(const string& parsetName, int argc, char* argv[]) { +void DP3::Execute(const string& parsetName, int argc, char* argv[]) { casacore::Timer timer; common::NSTimer nstimer; nstimer.start(); @@ -326,7 +325,7 @@ void DP3::execute(const string& parsetName, int argc, char* argv[]) { unsigned int numThreads = parset.getInt("numthreads", 0); // Create the steps, link them together - std::shared_ptr<InputStep> firstStep = makeMainSteps(parset); + std::shared_ptr<InputStep> firstStep = MakeMainSteps(parset); Step::ShPtr step = firstStep; Step::ShPtr lastStep; @@ -431,12 +430,12 @@ void DP3::execute(const string& parsetName, int argc, char* argv[]) { // The destructors are called automatically at this point. } -std::shared_ptr<InputStep> DP3::makeMainSteps( +std::shared_ptr<InputStep> DP3::MakeMainSteps( const common::ParameterSet& parset) { std::shared_ptr<InputStep> input_step = InputStep::CreateReader(parset); std::shared_ptr<Step> last_step = input_step; - std::shared_ptr<Step> step = makeStepsFromParset( + std::shared_ptr<Step> step = MakeStepsFromParset( parset, "", "steps", *input_step, false, input_step->outputs()); if (step) { input_step->setNextStep(step); @@ -475,7 +474,7 @@ std::shared_ptr<InputStep> DP3::makeMainSteps( return input_step; } -Step::ShPtr DP3::makeStepsFromParset(const common::ParameterSet& parset, +Step::ShPtr DP3::MakeStepsFromParset(const common::ParameterSet& parset, const std::string& prefix, const std::string& step_names_key, InputStep& inputStep, bool terminateChain, diff --git a/base/Main.cc b/base/Main.cc index 564e1c3e41f1b14b5d47dc3d3ca4874d640f3858..cbf3c54cd96fe017f01094beee072a1407b8c51e 100644 --- a/base/Main.cc +++ b/base/Main.cc @@ -69,7 +69,7 @@ int main(int argc, char* argv[]) { } // Execute the parset file. - dp3::base::DP3::execute(parsetName, argc, argv); + dp3::base::DP3::Execute(parsetName, argc, argv); } catch (std::exception& err) { std::cerr << "\nstd exception detected: " << err.what() << '\n'; return 1; diff --git a/base/test/unit/tDP3.cc b/base/test/unit/tDP3.cc index c925a6d0ec044edc8e43be076437a309b65a5939..33d75574224d1eb5368799816965681d624d68f9 100644 --- a/base/test/unit/tDP3.cc +++ b/base/test/unit/tDP3.cc @@ -258,7 +258,7 @@ void CreateCopyMs() { ostr << "msout.overwrite=true\n"; ostr << "steps=[]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); } BOOST_FIXTURE_TEST_CASE(test_copy, FixtureDirectory) { @@ -278,7 +278,7 @@ BOOST_FIXTURE_TEST_CASE(test_copy_column, FixtureDirectory) { ostr << "msout=" << kCopyColumnMS << '\n'; ostr << "steps=[]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // First copy standard data and weight columns { @@ -290,7 +290,7 @@ BOOST_FIXTURE_TEST_CASE(test_copy_column, FixtureDirectory) { ostr << "msout.weightcolumn=COPY_WEIGHT\n"; ostr << "steps=[]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // Copy custom data and weight columns. { @@ -304,7 +304,7 @@ BOOST_FIXTURE_TEST_CASE(test_copy_column, FixtureDirectory) { ostr << "msout.weightcolumn=COPY2_WEIGHT\n"; ostr << "steps=[]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); Table table_copy(kCopyColumnMS); BOOST_CHECK_GT(table_copy.nrow(), 0u); @@ -336,7 +336,7 @@ BOOST_FIXTURE_TEST_CASE(test_multi_in_basic, FixtureDirectory) { ostr << "msout=" << kMultiMS << '\n'; ostr << "steps=[]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); CheckCopy(kMultiMS, {false, false}); } @@ -357,7 +357,7 @@ BOOST_FIXTURE_TEST_CASE(test_multi_in_missing_data, FixtureDirectory) { ostr << "msout=" << kMissingDataMS << '\n'; ostr << "steps=[]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); const Table tab(kMissingDataMS); BOOST_CHECK_EQUAL(tab.nrow(), kNCopyMsTimeSlots * kNBaselinesRemaining); BOOST_CHECK(allEQ(ArrayColumn<Complex>(tab, "DATA").getColumn(), Complex())); @@ -380,7 +380,7 @@ BOOST_FIXTURE_TEST_CASE(test_multi_in_missing_ms, FixtureDirectory) { ostr << "msout=" << kMultiMS << '\n'; ostr << "steps=[]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); CheckCopy(kMultiMS, {true, false, true, true}); } @@ -475,7 +475,7 @@ BOOST_FIXTURE_TEST_CASE(test_avg_single, FixtureDirectory) { ostr << "avg.timestep=20\n"; ostr << "avg.freqstep=100\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); CheckAvg("tNDPPP_tmp.avg.MS"); } @@ -501,7 +501,7 @@ BOOST_FIXTURE_TEST_CASE(test_avg_multiple, FixtureDirectory) { ostr << "avg4.timestep=2\n"; ostr << "avg4.freqstep=4\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); CheckAvg("tNDPPP_tmp.avg.MS"); } @@ -548,10 +548,10 @@ BOOST_FIXTURE_TEST_CASE(test_avg_multiple_outputs, FixtureDirectory) { ostr4 << "avg4.timestep=2\n"; ostr4 << "avg4.freqstep=4\n"; } - DP3::execute("tNDPPP_tmp.parset1"); - DP3::execute("tNDPPP_tmp.parset2"); - DP3::execute("tNDPPP_tmp.parset3"); - DP3::execute("tNDPPP_tmp.parset4"); + DP3::Execute("tNDPPP_tmp.parset1"); + DP3::Execute("tNDPPP_tmp.parset2"); + DP3::Execute("tNDPPP_tmp.parset3"); + DP3::Execute("tNDPPP_tmp.parset4"); CheckAvg("tNDPPP_tmp.avg4.MS"); } @@ -571,7 +571,7 @@ BOOST_FIXTURE_TEST_CASE(test_avg_start_time, FixtureDirectory) { ostr << "avg.timestep=2\n"; ostr << "avg.freqstep=100\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // Only check the times in the averaged MS. Table table_input(kInputMs); @@ -620,7 +620,7 @@ BOOST_FIXTURE_TEST_CASE(test_update_basic, FixtureCopyInput) { ostr << "msout=''\n"; ostr << "steps=[]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // Check that the flags did not change. const Table table_input(kInputMs); @@ -640,7 +640,7 @@ BOOST_FIXTURE_TEST_CASE(test_update_flags, FixtureCopyInput) { ostr << "steps=[preflag]\n"; ostr << "preflag.blmin=1e6\n"; // should flag all data } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // Check that all flags are true. const Table table_copy(kCopyMs); @@ -660,7 +660,7 @@ BOOST_FIXTURE_TEST_CASE(test_update_scale, FixtureCopyInput) { ostr << "scaledata.stations=*\n"; ostr << "scaledata.scalesize=false\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // Check that all data is doubled and that the flags remain equal. const Table table_input(kInputMs); @@ -778,7 +778,7 @@ void CreateFlaggedMs() { ostr << "preflag.flag2.chan=[0,2,6..8]\n"; ostr << "average.timestep=6\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); } } // namespace @@ -817,8 +817,8 @@ BOOST_FIXTURE_TEST_CASE(test_flags_shifted, FixtureDirectory) { ostr2 << "average.timestep=3\n"; ostr2 << "average.freqstep=2\n"; } - DP3::execute("tNDPPP_tmp.parset1"); - DP3::execute("tNDPPP_tmp.parset2"); + DP3::Execute("tNDPPP_tmp.parset1"); + DP3::Execute("tNDPPP_tmp.parset2"); CheckFullResFlags(kFlaggedMs); } @@ -852,8 +852,8 @@ BOOST_FIXTURE_TEST_CASE(test_flags_averaged_channel, FixtureDirectory) { ostr2 << "average.timestep=3\n"; ostr2 << "average.freqstep=2\n"; } - DP3::execute("tNDPPP_tmp.parset1"); - DP3::execute("tNDPPP_tmp.parset2"); + DP3::Execute("tNDPPP_tmp.parset1"); + DP3::Execute("tNDPPP_tmp.parset2"); CheckFullResFlags(kFlaggedMs); } @@ -878,7 +878,7 @@ BOOST_FIXTURE_TEST_CASE(test_flags_set_clear, FixtureDirectory) { ostr << "steps=[preflag]\n"; ostr << "preflag.baseline=[[*]]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); CheckFullResFlags(kAllFlaggedMs); // Full res flags shouldn't change. BOOST_CHECK( allEQ(ArrayColumn<bool>(Table(kAllFlaggedMs), "FLAG").getColumn(), true)); @@ -894,7 +894,7 @@ BOOST_FIXTURE_TEST_CASE(test_flags_set_clear, FixtureDirectory) { ostr << "preflag.mode=clear\n"; ostr << "preflag.baseline=[[*]]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); CheckFullResFlags(kAllClearMs); // Full res flags shouldn't change. BOOST_CHECK( allEQ(ArrayColumn<bool>(Table(kAllClearMs), "FLAG").getColumn(), false)); @@ -912,7 +912,7 @@ BOOST_FIXTURE_TEST_CASE(test_station_add, FixtureDirectory) { ostr << "steps=[stationadd]\n"; ostr << "stationadd.stations={RTnew:[RT0..2]}\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); Table antenna_in(kInputMs + "/ANTENNA"); Table antenna_out(kOutputMs + "/ANTENNA"); @@ -953,7 +953,7 @@ BOOST_FIXTURE_TEST_CASE(test_filter_baseline, FixtureDirectory) { ostr << "filter.baseline=!RT[16]&&*\n"; ostr << "filter.remove=true\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // Note: the ANTENNA table also contained RT8, RT9, etc., but they do not // have baselines. So these were removed as well meaning only 0,2,7 are left. @@ -1033,7 +1033,7 @@ BOOST_FIXTURE_TEST_CASE(test_filter_keep_baselines, FixtureDirectory) { ostr << "filter.remove=true\n"; } } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // Note: the ANTENNA table also contained RT8, RT9, etc., but they do not // have baselines. So these were removed meaning only 0,1,2,6,7 are left. @@ -1102,7 +1102,7 @@ BOOST_FIXTURE_TEST_CASE(test_filter_different_data_column, FixtureCopyInput) { ostr << "filter.baseline=!RT[16]&&*\n"; ostr << "filter.remove=False\n"; } - BOOST_CHECK_NO_THROW(DP3::execute(kParsetFile)); + BOOST_CHECK_NO_THROW(DP3::Execute(kParsetFile)); } BOOST_FIXTURE_TEST_CASE(test_multi_out, FixtureDirectory) { @@ -1115,7 +1115,7 @@ BOOST_FIXTURE_TEST_CASE(test_multi_out, FixtureDirectory) { ostr << "msout.overwrite=true\n"; ostr << "steps=[]\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // Test if update data works fine with multiple outputs: // Read from tNDPPP_tmp.MS, write to MS_out, update to MS_out. @@ -1134,7 +1134,7 @@ BOOST_FIXTURE_TEST_CASE(test_multi_out, FixtureDirectory) { ostr << "out2.name=.\n"; // Defaults to the previous out, so .MS_out. ostr << "out2.datacolumn=DATA_2\n"; } - DP3::execute(kParsetFile); + DP3::Execute(kParsetFile); // Check that the tables exist and that they contain the specified columns. Table table_ref("tNDPPP_tmp.MS_ref"); @@ -1166,7 +1166,7 @@ BOOST_FIXTURE_TEST_CASE(test_error_out_avg, FixtureDirectory) { ostr << "out2.name=.\n"; // update not possible when avg ostr << "msout=''\n"; } - BOOST_CHECK_THROW(DP3::execute(kParsetFile), std::runtime_error); + BOOST_CHECK_THROW(DP3::Execute(kParsetFile), std::runtime_error); } BOOST_FIXTURE_TEST_CASE(test_error_out_filter, FixtureDirectory) { @@ -1183,7 +1183,7 @@ BOOST_FIXTURE_TEST_CASE(test_error_out_filter, FixtureDirectory) { ostr << "out2.name=./tNDPPP_tmp.MSx\n"; // update not possible (filter) ostr << "msout=''\n"; } - BOOST_CHECK_THROW(DP3::execute(kParsetFile), std::runtime_error); + BOOST_CHECK_THROW(DP3::Execute(kParsetFile), std::runtime_error); } BOOST_AUTO_TEST_CASE(test_required_fields) { diff --git a/include/dp3/base/DP3.h b/include/dp3/base/DP3.h index 4770d67ed79c3b5ba389627ec1dd9c4e4d02d868..b34c76ecdad4f07a4fcbf10bb3be319daa5644c0 100644 --- a/include/dp3/base/DP3.h +++ b/include/dp3/base/DP3.h @@ -26,37 +26,36 @@ namespace base { class DP3 { public: /// Define the function to create a step from the given parameterset. - typedef steps::Step::ShPtr StepCtor(steps::InputStep*, - const common::ParameterSet&, - const std::string& prefix); + using StepCreator = std::shared_ptr<steps::Step>(const common::ParameterSet&, + const std::string& prefix); /// Add a function creating a Step to the map. - static void registerStepCtor(const std::string&, StepCtor*); + static void RegisterStepCreator(const std::string&, StepCreator*); /// Create a step object from the given parameters. /// It looks up the step type in theirStepMap. If not found, it will /// try to load a shared library with that name and execute the /// register function in it. - static StepCtor* findStepCtor(const std::string& type); + static StepCreator* FindStepCreator(const std::string& type); /// Execute the steps defined in the parset file. /// Possible parameters given at the command line are taken into account. - static void execute(const std::string& parsetName, int argc = 0, + static void Execute(const std::string& parsetName, int argc = 0, char* argv[] = 0); /// Create a chain of step objects that are connected together. /// A writer will be added to the steps if it is not defined, /// and a terminating NullStep is added. - static std::shared_ptr<steps::InputStep> makeMainSteps( + static std::shared_ptr<steps::InputStep> MakeMainSteps( const common::ParameterSet& parset); /// Create a chain of step objects that are connected together. - /// Unlike makeMainSteps(), this does neither add a writer nor + /// Unlike MakeMainSteps(), this does neither add a writer nor /// terminate the chain with a NullStep. /// @param step_names_key Parset key for getting the step names. /// @return The first step of the step chain or a null pointer if the chain is /// empty. - static std::shared_ptr<steps::Step> makeStepsFromParset( + static std::shared_ptr<steps::Step> MakeStepsFromParset( const common::ParameterSet& parset, const std::string& prefix, const std::string& step_names_key, steps::InputStep& inputStep, bool terminateChain, steps::Step::MsType initial_step_output); @@ -80,7 +79,7 @@ class DP3 { private: /// The map to create a step object from its type name. - static std::map<std::string, StepCtor*> theirStepMap; + static std::map<std::string, StepCreator*> theirStepMap; }; } // namespace base diff --git a/steps/DDECal.cc b/steps/DDECal.cc index 887f6e0cc27a04a2e9504ad91f847e0565c55178..d7cbfa4e6e06dbbab7f04f077bb6276826689bbf 100644 --- a/steps/DDECal.cc +++ b/steps/DDECal.cc @@ -184,7 +184,7 @@ void DDECal::setModelNextSteps(Step& step, const std::string& direction, if (parset.isDefined(step_names_key)) { Step::ShPtr first_step = - base::DP3::makeStepsFromParset(parset, "", step_names_key, itsInput, + base::DP3::MakeStepsFromParset(parset, "", step_names_key, itsInput, false, steps::Step::MsType::kRegular); if (first_step) { diff --git a/steps/Split.cc b/steps/Split.cc index 920b038828fccd0fed15f91845009079e4364f8e..31b6426e29986a8b2030301dfd23bd5380a75996 100644 --- a/steps/Split.cc +++ b/steps/Split.cc @@ -63,7 +63,7 @@ Split::Split(InputStep* input, const common::ParameterSet& parset, parsetCopy.replace(replace_parameters_[j], replace_values[j][i]); } std::shared_ptr<Step> first_step = - base::DP3::makeStepsFromParset(parsetCopy, prefix, "steps", *input, + base::DP3::MakeStepsFromParset(parsetCopy, prefix, "steps", *input, true, steps::Step::MsType::kRegular); if (first_step) { first_step->setPrevStep(this); diff --git a/steps/dynamic_test_step/DynamicTestStep.cc b/steps/dynamic_test_step/DynamicTestStep.cc index 9f5f3ec74a49d72a78824255d4b01f43429b21cc..4e993facd0708aa00b095648a6517d82f01ec9f4 100644 --- a/steps/dynamic_test_step/DynamicTestStep.cc +++ b/steps/dynamic_test_step/DynamicTestStep.cc @@ -1,11 +1,11 @@ -// TestDyn.cc: Test of a dynamically loaded DPPP step +// TestDyn.cc: Test of a dynamically loaded DP3 step // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy) // SPDX-License-Identifier: GPL-3.0-or-later // // @author Ger van Diepen // @file -// @brief Test of a dynamically loaded DPPP step +// @brief Test of a dynamically loaded DP3 step #include "DynamicTestStep.h" @@ -16,17 +16,13 @@ namespace dp3 { namespace steps { namespace dynamic_test_step { -DynamicTestStep::DynamicTestStep(InputStep* input, - const common::ParameterSet& pset, +DynamicTestStep::DynamicTestStep(const common::ParameterSet& parset, const std::string& prefix) - : Averager(pset, prefix) {} + : Averager(parset, prefix) {} -DynamicTestStep::~DynamicTestStep() {} - -Step::ShPtr DynamicTestStep::makeStep(InputStep* input, - const common::ParameterSet& pset, - const std::string& prefix) { - return std::make_shared<DynamicTestStep>(input, pset, prefix); +std::shared_ptr<Step> DynamicTestStep::MakeStep( + const common::ParameterSet& parset, const std::string& prefix) { + return std::make_shared<DynamicTestStep>(parset, prefix); } } // namespace dynamic_test_step @@ -35,7 +31,7 @@ Step::ShPtr DynamicTestStep::makeStep(InputStep* input, // Define the function to make the TestDynStep 'constructor' known. // Its suffix must be the (lowercase) name of the package (library). -void register_testdyndppp() { - dp3::base::DP3::registerStepCtor( - "TestDynDPPP", dp3::steps::dynamic_test_step::DynamicTestStep::makeStep); +void register_testdyndp3() { + dp3::base::DP3::RegisterStepCreator( + "TestDynDP3", dp3::steps::dynamic_test_step::DynamicTestStep::MakeStep); } diff --git a/steps/dynamic_test_step/DynamicTestStep.h b/steps/dynamic_test_step/DynamicTestStep.h index 95ce1a894fea78ead0af1bfde5b169f06c15771a..02ded9190d03980a342f2edd1ff583867d0a049b 100644 --- a/steps/dynamic_test_step/DynamicTestStep.h +++ b/steps/dynamic_test_step/DynamicTestStep.h @@ -6,8 +6,8 @@ /// @brief Test of a dynamically loaded DPPP step /// @author Ger van Diepen -#ifndef TESTDYNDPPP_TESTDYNSTEP_H -#define TESTDYNDPPP_TESTDYNSTEP_H +#ifndef DP3_STEPS_DYNAMICTESTSTEP_H_ +#define DP3_STEPS_DYNAMICTESTSTEP_H_ #include <dp3/steps/Step.h> #include "../../steps/Averager.h" @@ -25,10 +25,9 @@ namespace dynamic_test_step { class DynamicTestStep : public Averager { public: - DynamicTestStep(InputStep*, const common::ParameterSet&, const std::string&); - virtual ~DynamicTestStep(); - static Step::ShPtr makeStep(InputStep*, const common::ParameterSet&, - const std::string&); + DynamicTestStep(const common::ParameterSet&, const std::string&); + static std::shared_ptr<Step> MakeStep(const common::ParameterSet&, + const std::string&); }; } // namespace dynamic_test_step @@ -37,7 +36,7 @@ class DynamicTestStep : public Averager { // Define the function (without name mangling) to register the 'constructor'. extern "C" { -void register_testdyndppp(); +void register_testdyndp3(); } #endif diff --git a/steps/dynamic_test_step/test/tDynamicTestStep.cc b/steps/dynamic_test_step/test/tDynamicTestStep.cc index 863226ef8db2dc0bdbf69200a62db26467fb8eaa..a09afc84b1394aaccf2460f5ba9fb1d1011c718e 100644 --- a/steps/dynamic_test_step/test/tDynamicTestStep.cc +++ b/steps/dynamic_test_step/test/tDynamicTestStep.cc @@ -8,26 +8,26 @@ // Only the way the average steps are created is different. // Average is used underneath TestDynStep. -#include "tStepCommon.h" -#include "mock/ThrowStep.h" -#include <dp3/base/DPBuffer.h> -#include "../../base/DPInfo.h" -#include "../../base/InputStep.h" -#include "../../base/DPRun.h" - -#include "../../common/ParameterSet.h" -#include "../../common/StringTools.h" +#include <boost/test/unit_test.hpp> #include <casacore/casa/Arrays/ArrayMath.h> #include <casacore/casa/Arrays/ArrayLogical.h> +#include <casacore/casa/BasicMath/Math.h> -#include <boost/test/unit_test.hpp> +#include <dp3/base/DP3.h> +#include <dp3/common/Types.h> +#include "../../../common/ParameterSet.h" +#include "../../../common/StringTools.h" + +#include "../../test/unit/tStepCommon.h" +#include "../../test/unit/mock/ThrowStep.h" -using namespace LOFAR; using namespace dp3::base; using namespace casacore; +using dp3::steps::Step; -BOOST_AUTO_TEST_SUITE(dyn_step) +// TODO(AST-1045): Either remove or test support for Steps in dynamic libraries. +BOOST_AUTO_TEST_SUITE(dyn_step, *boost::unit_test::disabled()) // Simple class to generate input arrays. // It can only set all flags to true or all false. @@ -148,7 +148,7 @@ class TestOutput : public dp3::steps::test::ThrowStep { BOOST_CHECK(allNear(imag(buf.getData()), imag(result), 1e-5)); BOOST_CHECK(allEQ(buf.getFlags(), itsFlag)); BOOST_CHECK(near(buf.getTime(), 2 + 5 * (itsCount * itsNAvgTime + - (itsNAvgTime - 1) / 2.))); + (itsNAvgTime - 1) / 2.0))); BOOST_CHECK(allNear(buf.getWeights(), resultw, 1e-5)); if (navgtime == itsNAvgTime) { Matrix<double> uvw(3, itsNBl); @@ -214,7 +214,7 @@ class TestInput3 : public dp3::steps::MockInput { buf.setData(data); buf.setWeights(weights); buf.setFlags(flags); - Vector<rownr_t> rownrs(1, itsCount); + Vector<dp3::common::rownr_t> rownrs(1, itsCount); buf.setRowNrs(rownrs); getNextStep()->process(buf); ++itsCount; @@ -237,8 +237,8 @@ class TestInput3 : public dp3::steps::MockInput { std::string()); // Define the frequencies. std::vector<double> chanFreqs; - std::vector<double> chanWidth(itsNChan, 100000.); - for (int i = 0; i < itsNChan; i++) { + std::vector<double> chanWidth(itsNrChan, 100000.); + for (int i = 0; i < itsNrChan; i++) { chanFreqs.push_back(1050000. + i * 100000.); } info().set(std::move(chanFreqs), std::move(chanWidth)); @@ -438,15 +438,14 @@ void test1(int ntime, int nbl, int nchan, int ncorr, int navgtime, int navgchan, << " ncorr=" << ncorr << " navgtime=" << navgtime << " navgchan=" << navgchan << endl; // Create the steps. - TestInput* in = new TestInput(ntime, nbl, nchan, ncorr, flag); - Step::ShPtr step1(in); + auto in = std::make_shared<TestInput>(ntime, nbl, nchan, ncorr, flag); dp3::common::ParameterSet parset; parset.add("freqstep", std::to_string(navgchan)); parset.add("timestep", std::to_string(navgtime)); - Step::ShPtr step2 = DPRun::findStepCtor("TestDynDPPP")(in, parset, ""); - Step::ShPtr step3( - new TestOutput(ntime, nbl, nchan, ncorr, navgtime, navgchan, flag)); - dp3::steps::test::Execute({step1, step2, step3}); + std::shared_ptr<Step> step = DP3::FindStepCreator("TestDynDP3")(parset, ""); + auto out = std::make_shared<TestOutput>(ntime, nbl, nchan, ncorr, navgtime, + navgchan, flag); + dp3::steps::test::Execute({in, step, out}); } // Like test1, but the averaging is done in two steps. @@ -455,49 +454,43 @@ void test2(int ntime, int nbl, int nchan, int ncorr, bool flag) { << " ncorr=" << ncorr << " navgtime=2" << " navgchan=4" << endl; // Create the steps. - TestInput* in = new TestInput(ntime, nbl, nchan, ncorr, flag); - Step::ShPtr step1(in); + auto in = std::make_shared<TestInput>(ntime, nbl, nchan, ncorr, flag); dp3::common::ParameterSet parset1, parset2; parset1.add("freqstep", "4"); parset2.add("timestep", "2"); - Step::ShPtr step2a = DPRun::findStepCtor("TestDynDPPP")(in, parset1, ""); - Step::ShPtr step2b = DPRun::findStepCtor("TestDynDPPP")(in, parset2, ""); - Step::ShPtr step3(new TestOutput(ntime, nbl, nchan, ncorr, 2, 4, flag)); - dp3::steps::test::Execute({step1, step2a, step2b, step3}); + std::shared_ptr<Step> step1 = DP3::FindStepCreator("TestDynDP3")(parset1, ""); + std::shared_ptr<Step> step2 = DP3::FindStepCreator("TestDynDP3")(parset2, ""); + auto out = std::make_shared<TestOutput>(ntime, nbl, nchan, ncorr, 2, 4, flag); + dp3::steps::test::Execute({in, step1, step2, out}); } // Do tests with weighting and some flagged points. void test3(int nrbl, int nrcorr) { { - cout << "test3: ntime=2 nrbl=" << nrbl << " nchan=2 ncorr=" << nrcorr - << endl; - cout << " navgtime=2 navgchan=2" << endl; // Create the steps. - TestInput3* in = new TestInput3(2, nrbl, 2, nrcorr); - Step::ShPtr step1(in); + auto in = std::make_shared<TestInput3>(2, nrbl, 2, nrcorr); dp3::common::ParameterSet parset1; parset1.add("freqstep", "2"); parset1.add("timestep", "2"); - Step::ShPtr step2a = DPRun::findStepCtor("TestDynDPPP")(in, parset1, ""); - Step::ShPtr step3(new TestOutput3(2, nrbl, 2, nrcorr)); - dp3::steps::test::Execute({step1, step2a, step3}); + std::shared_ptr<Step> step = + DP3::FindStepCreator("TestDynDP3")(parset1, ""); + auto out = std::make_shared<TestOutput3>(2, nrbl, 2, nrcorr); + dp3::steps::test::Execute({in, step, out}); } { - cout << "test3: ntime=4 nrbl=" << nrbl << " nchan=8 ncorr=" << nrcorr - << endl; - cout << " [navgtime=2 navgchan=4], [navgtime=2 navgchan=2]" << endl; // Create the steps. - TestInput3* in = new TestInput3(4, nrbl, 8, nrcorr); - Step::ShPtr step1(in); + auto in = std::make_shared<TestInput3>(4, nrbl, 8, nrcorr); dp3::common::ParameterSet parset1, parset2; parset1.add("freqstep", "4"); parset1.add("timestep", "2"); parset2.add("freqstep", "2"); parset2.add("timestep", "2"); - Step::ShPtr step2a = DPRun::findStepCtor("TestDynDPPP")(in, parset1, ""); - Step::ShPtr step2b = DPRun::findStepCtor("TestDynDPPP")(in, parset2, ""); - Step::ShPtr step3(new TestOutput3(4, nrbl, 8, nrcorr)); - dp3::steps::test::Execute({step1, step2a step2b, step3}); + std::shared_ptr<Step> step1 = + DP3::FindStepCreator("TestDynDP3")(parset1, ""); + std::shared_ptr<Step> step2 = + DP3::FindStepCreator("TestDynDP3")(parset2, ""); + auto out = std::make_shared<TestOutput3>(4, nrbl, 8, nrcorr); + dp3::steps::test::Execute({in, step1, step2, out}); } } @@ -505,23 +498,20 @@ void test3(int nrbl, int nrcorr) { // promoted to the FULLRES flags. void test4(int nrbl, int nrcorr, int flagstep) { { - cout << "test4: ntime=4 nrbl=" << nrbl << " nchan=8 ncorr=" << nrcorr - << endl; - cout << " [navgtime=2 navgchan=2], [flagstep=" << flagstep - << "] [navgtime=2 navgchan=4]" << endl; // Create the steps. - TestInput3* in = new TestInput3(4, nrbl, 8, nrcorr); - Step::ShPtr step1(in); + auto in = std::make_shared<TestInput3>(4, nrbl, 8, nrcorr); dp3::common::ParameterSet parset1, parset2; parset1.add("freqstep", "2"); parset1.add("timestep", "2"); parset2.add("freqstep", "4"); parset2.add("timestep", "2"); - Step::ShPtr step2a = DPRun::findStepCtor("TestDynDPPP")(in, parset1, ""); - Step::ShPtr step2b(new TestFlagger(flagstep)); - Step::ShPtr step2c = DPRun::findStepCtor("TestDynDPPP")(in, parset2, ""); - Step::ShPtr step3(new TestOutput4(4, nrbl, 8, nrcorr, flagstep)); - dp3::steps::test::Execute({step1, step2a, step2b, step2c}); + std::shared_ptr<Step> step1 = + DP3::FindStepCreator("TestDynDP3")(parset1, ""); + auto flagger = std::make_shared<TestFlagger>(flagstep); + std::shared_ptr<Step> step2 = + DP3::FindStepCreator("TestDynDP3")(parset2, ""); + auto out = std::make_shared<TestOutput4>(4, nrbl, 8, nrcorr, flagstep); + dp3::steps::test::Execute({in, step1, flagger, step2, out}); } }