diff --git a/Framework/Muon/inc/MantidMuon/CalMuonDetectorPhases.h b/Framework/Muon/inc/MantidMuon/CalMuonDetectorPhases.h index 70e10a03b3a7ded435dc971bb7f0edc749e66a87..8deac0094b854f8ec03e50a6088e45330efd26bd 100644 --- a/Framework/Muon/inc/MantidMuon/CalMuonDetectorPhases.h +++ b/Framework/Muon/inc/MantidMuon/CalMuonDetectorPhases.h @@ -57,13 +57,13 @@ private: removeExpDecay(const API::MatrixWorkspace_sptr &wsInput); /// Fit the workspace void fitWorkspace(const API::MatrixWorkspace_sptr &ws, double freq, - std::string groupName, API::ITableWorkspace_sptr &resTab, + std::string groupName, API::ITableWorkspace_sptr resTab, API::WorkspaceGroup_sptr &resGroup); /// Create the fitting function as string std::string createFittingFunction(double freq, bool fixFreq); /// Extract asymmetry and phase from fitting results - void extractDetectorInfo(const API::ITableWorkspace_sptr ¶mTab, - const API::ITableWorkspace_sptr &resultsTab, + void extractDetectorInfo(API::ITableWorkspace ¶mTab, + API::ITableWorkspace &resultsTab, const Indexing::SpectrumNumber spectrumNumber); /// Find frequency to use in sequential fit double getFrequency(const API::MatrixWorkspace_sptr &ws); diff --git a/Framework/Muon/src/CalMuonDeadTime.cpp b/Framework/Muon/src/CalMuonDeadTime.cpp index 74c277c8f3a1b5b1eee0a1390ff8f76778965b1f..978033da35fb637eef07d094def1dca58512d06f 100644 --- a/Framework/Muon/src/CalMuonDeadTime.cpp +++ b/Framework/Muon/src/CalMuonDeadTime.cpp @@ -11,7 +11,7 @@ #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/Run.h" #include "MantidAPI/TableRow.h" -#include "MantidAPI/WorkspaceFactory.h" +#include "MantidDataObjects/TableWorkspace.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/PhysicalConstants.h" @@ -22,6 +22,7 @@ namespace Mantid { namespace Algorithms { using namespace Kernel; +using namespace DataObjects; // Register the class into the algorithm factory DECLARE_ALGORITHM(CalMuonDeadTime) @@ -95,8 +96,7 @@ void CalMuonDeadTime::exec() { // Do the initial setup of the ouput table-workspace - API::ITableWorkspace_sptr outTable = - API::WorkspaceFactory::Instance().createTable("TableWorkspace"); + API::ITableWorkspace_sptr outTable = boost::make_shared<TableWorkspace>(); outTable->addColumn("int", "spectrum"); outTable->addColumn("double", "dead-time"); diff --git a/Framework/Muon/src/CalMuonDetectorPhases.cpp b/Framework/Muon/src/CalMuonDetectorPhases.cpp index c88d4bf8d710a8214cbdeb8ea2bba5b7e1eb80a9..9cde6be97b3635bfb2aa0facd7d7e463e37f7442 100644 --- a/Framework/Muon/src/CalMuonDetectorPhases.cpp +++ b/Framework/Muon/src/CalMuonDetectorPhases.cpp @@ -15,8 +15,8 @@ #include "MantidAPI/MultiDomainFunction.h" #include "MantidAPI/Run.h" #include "MantidAPI/TableRow.h" -#include "MantidAPI/WorkspaceFactory.h" #include "MantidAPI/WorkspaceGroup.h" +#include "MantidDataObjects/TableWorkspace.h" #include "MantidIndexing/IndexInfo.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/PhysicalConstants.h" @@ -30,6 +30,7 @@ namespace Mantid { namespace Algorithms { using namespace Kernel; +using namespace DataObjects; // Register the algorithm into the AlgorithmFactory DECLARE_ALGORITHM(CalMuonDetectorPhases) @@ -127,7 +128,7 @@ void CalMuonDetectorPhases::exec() { double freq = getFrequency(tempWS); // Create the output workspaces - auto tab = API::WorkspaceFactory::Instance().createTable("TableWorkspace"); + TableWorkspace_sptr tab = boost::make_shared<TableWorkspace>(); auto group = boost::make_shared<API::WorkspaceGroup>(); // Get the name of 'DataFitted' @@ -152,7 +153,7 @@ void CalMuonDetectorPhases::exec() { */ void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws, double freq, std::string groupName, - API::ITableWorkspace_sptr &resTab, + API::ITableWorkspace_sptr resTab, API::WorkspaceGroup_sptr &resGroup) { int nhist = static_cast<int>(ws->getNumberHistograms()); @@ -177,8 +178,7 @@ void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws, [](double value) { return value == 0.; }); if (emptySpectrum) { g_log.warning("Spectrum " + std::to_string(wsIndex) + " is empty"); - auto tab = - API::WorkspaceFactory::Instance().createTable("TableWorkspace"); + TableWorkspace_sptr tab = boost::make_shared<TableWorkspace>(); tab->addColumn("str", "Name"); tab->addColumn("double", "Value"); tab->addColumn("double", "Error"); @@ -191,7 +191,7 @@ void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws, } } - extractDetectorInfo(tab, resTab, indexInfo.spectrumNumber(wsIndex)); + extractDetectorInfo(*tab, *resTab, indexInfo.spectrumNumber(wsIndex)); } else { auto fit = createChildAlgorithm("Fit"); @@ -217,7 +217,7 @@ void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws, // Now we have our fitting results stored in tab // but we need to extract the relevant information, i.e. // the detector phases (parameter 'p') and asymmetries ('A') - extractDetectorInfo(tab, resTab, indexInfo.spectrumNumber(wsIndex)); + extractDetectorInfo(*tab, *resTab, indexInfo.spectrumNumber(wsIndex)); } } } @@ -229,12 +229,11 @@ void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws, * @param spectrumNumber :: [input] Spectrum number */ void CalMuonDetectorPhases::extractDetectorInfo( - const API::ITableWorkspace_sptr ¶mTab, - const API::ITableWorkspace_sptr &resultsTab, + API::ITableWorkspace ¶mTab, API::ITableWorkspace &resultsTab, const Indexing::SpectrumNumber spectrumNumber) { - double asym = paramTab->Double(0, 1); - double phase = paramTab->Double(2, 1); + double asym = paramTab.Double(0, 1); + double phase = paramTab.Double(2, 1); // If asym<0, take the absolute value and add \pi to phase // f(x) = A * cos( w * x - p) = -A * cos( w * x - p - PI) if (asym < 0) { @@ -247,7 +246,7 @@ void CalMuonDetectorPhases::extractDetectorInfo( phase = phase - factor * 2. * M_PI; } // Copy parameters to new row in results table - API::TableRow row = resultsTab->appendRow(); + API::TableRow row = resultsTab.appendRow(); row << static_cast<int>(spectrumNumber) << asym << phase; } diff --git a/Framework/Muon/src/EstimateMuonAsymmetryFromCounts.cpp b/Framework/Muon/src/EstimateMuonAsymmetryFromCounts.cpp index aee33457b2058a34eabd68194196910781ce37fc..2c3ffb6429cff9058be0225ab43a2b0a5048e5ae 100644 --- a/Framework/Muon/src/EstimateMuonAsymmetryFromCounts.cpp +++ b/Framework/Muon/src/EstimateMuonAsymmetryFromCounts.cpp @@ -13,8 +13,8 @@ #include "MantidAPI/IFunction.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/Run.h" -#include "MantidAPI/WorkspaceFactory.h" #include "MantidAPI/Workspace_fwd.h" +#include "MantidDataObjects/WorkspaceCreation.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/PhysicalConstants.h" #include "MantidMuon/MuonAlgorithmHelper.h" @@ -26,6 +26,7 @@ namespace Mantid { namespace Algorithms { +using namespace Mantid::DataObjects; using namespace Kernel; using API::Progress; using std::size_t; @@ -121,11 +122,10 @@ void EstimateMuonAsymmetryFromCounts::exec() { // Create output workspace with same dimensions as input API::MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace"); if (inputWS != outputWS) { - outputWS = API::WorkspaceFactory::Instance().create(inputWS); + outputWS = create<API::MatrixWorkspace>(*inputWS); } bool extraData = getProperty("OutputUnNormData"); - API::MatrixWorkspace_sptr unnormWS = - API::WorkspaceFactory::Instance().create(outputWS); + API::MatrixWorkspace_sptr unnormWS = create<API::MatrixWorkspace>(*outputWS); double startX = getProperty("StartX"); double endX = getProperty("EndX"); const Mantid::API::Run &run = inputWS->run(); diff --git a/Framework/Muon/src/PhaseQuadMuon.cpp b/Framework/Muon/src/PhaseQuadMuon.cpp index b893c72cb535be74d88a50d38eca61818764c100..714e8b361ac3e8b306cbd5880aa034d56dcbe791 100644 --- a/Framework/Muon/src/PhaseQuadMuon.cpp +++ b/Framework/Muon/src/PhaseQuadMuon.cpp @@ -9,10 +9,15 @@ #include "MantidAPI/Axis.h" #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/MatrixWorkspaceValidator.h" -#include "MantidAPI/WorkspaceFactory.h" +#include "MantidDataObjects/Workspace2D.h" +#include "MantidDataObjects/WorkspaceCreation.h" +#include "MantidHistogramData/Histogram.h" #include "MantidKernel/PhysicalConstants.h" #include "MantidKernel/Unit.h" +using namespace Mantid::DataObjects; +using namespace Mantid::HistogramData; + namespace { const std::array<std::string, 2> phaseNames = {{"phase", "phi"}}; const std::array<std::string, 3> asymmNames = {{"asymmetry", "asymm", "asym"}}; @@ -291,7 +296,7 @@ PhaseQuadMuon::squash(const API::MatrixWorkspace_sptr &ws, const size_t npoints = ws->blocksize(); // Create and populate output workspace API::MatrixWorkspace_sptr ows = - API::WorkspaceFactory::Instance().create(ws, 2, npoints + 1, npoints); + create<API::MatrixWorkspace>(*ws, 2, BinEdges(npoints + 1)); // X ows->setSharedX(0, ws->sharedX(0)); diff --git a/Framework/Muon/src/PlotAsymmetryByLogValue.cpp b/Framework/Muon/src/PlotAsymmetryByLogValue.cpp index c9ba0fe357302f100a096331733bc23276401fd4..802cf1ea84e27e274907b718c657027079751537 100644 --- a/Framework/Muon/src/PlotAsymmetryByLogValue.cpp +++ b/Framework/Muon/src/PlotAsymmetryByLogValue.cpp @@ -8,15 +8,19 @@ #include <vector> #include "MantidAPI/AlgorithmManager.h" +#include "MantidAPI/FileFinder.h" #include "MantidAPI/FileProperty.h" #include "MantidAPI/Progress.h" #include "MantidAPI/Run.h" #include "MantidAPI/ScopedWorkspace.h" #include "MantidAPI/TableRow.h" #include "MantidAPI/TextAxis.h" -#include "MantidAPI/WorkspaceFactory.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidDataObjects/TableWorkspace.h" +#include "MantidDataObjects/Workspace2D.h" +#include "MantidDataObjects/WorkspaceCreation.h" +#include "MantidHistogramData/Histogram.h" +#include "MantidHistogramData/HistogramBuilder.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/ListValidator.h" #include "MantidKernel/MandatoryValidator.h" @@ -24,8 +28,9 @@ #include "MantidKernel/TimeSeriesProperty.h" #include "MantidMuon/PlotAsymmetryByLogValue.h" #include "Poco/File.h" -#include <MantidAPI/FileFinder.h> +using namespace Mantid::DataObjects; +using namespace Mantid::HistogramData; namespace // anonymous { @@ -186,19 +191,16 @@ void PlotAsymmetryByLogValue::exec() { // Create the 2D workspace for the output int nplots = !m_greenY.empty() ? 4 : 1; size_t npoints = m_logValue.size(); - MatrixWorkspace_sptr outWS = WorkspaceFactory::Instance().create( - "Workspace2D", - nplots, // the number of plots - npoints, // the number of data points on a plot - npoints // it's not a histogram + MatrixWorkspace_sptr outWS = create<Workspace2D>( + nplots, // the number of plots + Points(npoints) // the number of data points on a plot ); // Populate output workspace with data populateOutputWorkspace(outWS, nplots); // Assign the result to the output workspace property setProperty("OutputWorkspace", outWS); - outWS = WorkspaceFactory::Instance().create("Workspace2D", nplots + 1, - npoints, npoints); + outWS = create<Workspace2D>(nplots + 1, Points(npoints)); // Populate ws holding current results saveResultsToADS(outWS, nplots + 1); } @@ -588,8 +590,7 @@ Workspace_sptr PlotAsymmetryByLogValue::createCustomGrouping(const std::vector<int> &fwd, const std::vector<int> &bwd) { - ITableWorkspace_sptr group = - WorkspaceFactory::Instance().createTable("TableWorkspace"); + ITableWorkspace_sptr group = boost::make_shared<TableWorkspace>(); group->addColumn("vector_int", "group"); TableRow row = group->appendRow(); row << fwd; @@ -747,10 +748,12 @@ void PlotAsymmetryByLogValue::calcIntAsymmetry(MatrixWorkspace_sptr ws_red, MatrixWorkspace_sptr ws_green, double &Y, double &E) { if (!m_int) { // "Differential asymmetry" - - MatrixWorkspace_sptr tmpWS = WorkspaceFactory::Instance().create( - ws_red, 1, ws_red->x(0).size(), ws_red->y(0).size()); - + HistogramBuilder builder; + builder.setX(ws_red->x(0).size()); + builder.setY(ws_red->y(0).size()); + builder.setDistribution(ws_red->isDistribution()); + MatrixWorkspace_sptr tmpWS = + create<MatrixWorkspace>(*ws_red, 1, builder.build()); for (size_t i = 0; i < tmpWS->y(0).size(); i++) { double FNORM = ws_green->y(0)[i] + ws_red->y(0)[i]; FNORM = FNORM != 0.0 ? 1.0 / FNORM : 1.0;