Skip to content

Commit

Permalink
refs #10131. Worker class put in place.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Aug 18, 2014
1 parent 1ef3adb commit 2433568
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 51 deletions.
31 changes: 17 additions & 14 deletions Code/Mantid/Framework/API/CMakeLists.txt
Expand Up @@ -10,7 +10,7 @@ set ( SRC_FILES
src/AnalysisDataService.cpp
src/ArchiveSearchFactory.cpp
src/Axis.cpp
src/BinEdgeAxis.cpp
src/BinEdgeAxis.cpp
src/BoxController.cpp
src/CatalogFactory.cpp
src/CatalogManager.cpp
Expand Down Expand Up @@ -42,9 +42,9 @@ set ( SRC_FILES
src/FunctionProperty.cpp
src/FunctionValues.cpp
src/GridDomain.cpp
src/GridDomain1D.cpp
src/HistoryItem.cpp
src/HistoryView.cpp
src/GridDomain1D.cpp
src/HistoryItem.cpp
src/HistoryView.cpp
src/IDomainCreator.cpp
src/IEventList.cpp
src/IEventWorkspace.cpp
Expand Down Expand Up @@ -85,6 +85,7 @@ set ( SRC_FILES
src/ModeratorModel.cpp
src/MultiDomainFunction.cpp
src/MultiPeriodGroupAlgorithm.cpp
src/MultiPeriodGroupWorker.cpp
src/MultipleExperimentInfos.cpp
src/MultipleFileProperty.cpp
src/NullCoordTransform.cpp
Expand All @@ -105,7 +106,7 @@ set ( SRC_FILES
src/Sample.cpp
src/SampleEnvironment.cpp
src/ScopedWorkspace.cpp
src/ScriptBuilder.cpp
src/ScriptBuilder.cpp
src/ScriptRepository.cpp
src/ScriptRepositoryFactory.cpp
src/SpectraAxis.cpp
Expand Down Expand Up @@ -143,7 +144,7 @@ set ( INC_FILES
inc/MantidAPI/AnalysisDataService.h
inc/MantidAPI/ArchiveSearchFactory.h
inc/MantidAPI/Axis.h
inc/MantidAPI/BinEdgeAxis.h
inc/MantidAPI/BinEdgeAxis.h
inc/MantidAPI/BoxController.h
inc/MantidAPI/CatalogFactory.h
inc/MantidAPI/CatalogManager.h
Expand Down Expand Up @@ -180,9 +181,9 @@ set ( INC_FILES
inc/MantidAPI/FunctionProperty.h
inc/MantidAPI/FunctionValues.h
inc/MantidAPI/GridDomain.h
inc/MantidAPI/GridDomain1D.h
inc/MantidAPI/GridDomain1D.h
inc/MantidAPI/HistoryItem.h
inc/MantidAPI/HistoryView.h
inc/MantidAPI/HistoryView.h
inc/MantidAPI/IAlgorithm.h
inc/MantidAPI/IArchiveSearch.h
inc/MantidAPI/IBackgroundFunction.h
Expand Down Expand Up @@ -242,6 +243,7 @@ set ( INC_FILES
inc/MantidAPI/ModeratorModel.h
inc/MantidAPI/MultiDomainFunction.h
inc/MantidAPI/MultiPeriodGroupAlgorithm.h
inc/MantidAPI/MultiPeriodGroupWorker.h
inc/MantidAPI/MultipleExperimentInfos.h
inc/MantidAPI/MultipleFileProperty.h
inc/MantidAPI/NullCoordTransform.h
Expand All @@ -263,7 +265,7 @@ set ( INC_FILES
inc/MantidAPI/Sample.h
inc/MantidAPI/SampleEnvironment.h
inc/MantidAPI/ScopedWorkspace.h
inc/MantidAPI/ScriptBuilder.h
inc/MantidAPI/ScriptBuilder.h
inc/MantidAPI/ScriptRepository.h
inc/MantidAPI/ScriptRepositoryFactory.h
inc/MantidAPI/SingleValueParameter.h
Expand Down Expand Up @@ -296,7 +298,7 @@ set ( TEST_FILES
AlgorithmTest.h
AnalysisDataServiceTest.h
AsynchronousTest.h
BinEdgeAxisTest.h
BinEdgeAxisTest.h
BoxControllerTest.h
CompositeFunctionTest.h
CoordTransformTest.h
Expand All @@ -316,8 +318,8 @@ set ( TEST_FILES
FunctionPropertyTest.h
FunctionTest.h
FunctionValuesTest.h
HistoryItemTest.h
HistoryViewTest.h
HistoryItemTest.h
HistoryViewTest.h
IEventListTest.h
IFunction1DSpectrumTest.h
IFunction1DTest.h
Expand All @@ -338,6 +340,7 @@ set ( TEST_FILES
ModeratorModelTest.h
MultiDomainFunctionTest.h
MultiPeriodGroupAlgorithmTest.h
MultiPeriodGroupWorkerTest.h
MultipleExperimentInfosTest.h
MultipleFilePropertyTest.h
NumericAxisTest.h
Expand All @@ -353,17 +356,17 @@ set ( TEST_FILES
RunTest.h
SampleEnvironmentTest.h
SampleTest.h
ScriptBuilderTest.h
ScopedWorkspaceTest.h
ScriptBuilderTest.h
SpectraAxisTest.h
SpectrumDetectorMappingTest.h
TextAxisTest.h
VectorParameterParserTest.h
VectorParameterTest.h
WorkspaceFactoryTest.h
WorkspaceGroupTest.h
WorkspaceHistoryTest.h
WorkspaceHistoryIOTest.h
WorkspaceHistoryTest.h
WorkspaceOpOverloadsTest.h
WorkspacePropertyTest.h
)
Expand Down
61 changes: 61 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/MultiPeriodGroupWorker.h
@@ -0,0 +1,61 @@
#ifndef MANTID_API_MULTIPERIODGROUPWORKER_H_
#define MANTID_API_MULTIPERIODGROUPWORKER_H_

#include "MantidKernel/System.h"
#include "MantidAPI/IAlgorithm.h"
#include <string>

namespace Mantid
{
namespace API
{

/** MultiPeriodGroupWorker : Multiperiod group logic relating to determining a valid multiperiod group, and processing a
* multiperiod group, as well as combining and returning the output.
Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport MultiPeriodGroupWorker
{
public:
MultiPeriodGroupWorker();
MultiPeriodGroupWorker(const std::string& workspacePropertyName);
virtual ~MultiPeriodGroupWorker();
/// Getter for the input workspace property name
std::string getInputWorkspacePropertyName() const;
/// Flag to indicate use of a custom workspace property
bool useCustomWorkspaceProperty() const;
/// Check groups
bool checkGroups(IAlgorithm_sptr alg) const;

private:
MultiPeriodGroupWorker(const MultiPeriodGroupWorker&);
MultiPeriodGroupWorker& operator=(const MultiPeriodGroupWorker&);

/// Workspace property name
std::string m_workspacePropertyName;

};

} // namespace API
} // namespace Mantid

#endif /* MANTID_API_MULTIPERIODGROUPWORKER_H_ */
44 changes: 44 additions & 0 deletions Code/Mantid/Framework/API/src/MultiPeriodGroupWorker.cpp
@@ -0,0 +1,44 @@
#include "MantidAPI/MultiPeriodGroupWorker.h"

namespace Mantid
{
namespace API
{


//----------------------------------------------------------------------------------------------
/** Constructor
*/
MultiPeriodGroupWorker::MultiPeriodGroupWorker()
{
}

/**
* Constructor
* @param workspacePropertyName : Property name to treat as source of multiperiod workspaces.
*/
MultiPeriodGroupWorker::MultiPeriodGroupWorker(const std::string& workspacePropertyName) : m_workspacePropertyName(workspacePropertyName)
{
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
MultiPeriodGroupWorker::~MultiPeriodGroupWorker()
{
}


bool MultiPeriodGroupWorker::checkGroups(IAlgorithm_sptr alg) const
{
return false;
}

bool MultiPeriodGroupWorker::useCustomWorkspaceProperty() const
{
return !this->m_workspacePropertyName.empty();
}


} // namespace API
} // namespace Mantid
41 changes: 4 additions & 37 deletions Code/Mantid/Framework/API/test/MultiPeriodGroupAlgorithmTest.h
Expand Up @@ -2,6 +2,7 @@
#define MANTID_API_MultiPeriodGroupAlgorithmTEST_H_

#include <cxxtest/TestSuite.h>
#include "MultiPeriodGroupTestBase.h"
#include "MantidAPI/MultiPeriodGroupAlgorithm.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidTestHelpers/FakeObjects.h"
Expand All @@ -19,7 +20,7 @@ class TestAlgorithmA : public MultiPeriodGroupAlgorithm
virtual const std::string name() const {return "TestAlgorithmA";}
virtual int version() const {return 1;}
virtual const std::string summary() const { return "Test summary"; }
virtual void init()
virtual void init()
{
declareProperty(new ArrayProperty<std::string>("MyInputWorkspaces"));
declareProperty(new WorkspaceProperty<>("OutputWorkspace","",Direction::Output), "");
Expand Down Expand Up @@ -54,7 +55,7 @@ class TestAlgorithmB : public MultiPeriodGroupAlgorithm
virtual const std::string name() const {return "TestAlgorithmB";}
virtual int version() const {return 1;}
virtual const std::string summary() const { return "Test summary"; }
virtual void init()
virtual void init()
{
declareProperty(new WorkspaceProperty<>("PropertyA", "ws1", Direction::Input));
declareProperty(new WorkspaceProperty<>("PropertyB", "ws2", Direction::Input));
Expand Down Expand Up @@ -92,42 +93,8 @@ DECLARE_ALGORITHM( TestAlgorithmB)
// End class dec


class MultiPeriodGroupAlgorithmTest : public CxxTest::TestSuite
class MultiPeriodGroupAlgorithmTest : public CxxTest::TestSuite, public MultiPeriodGroupTestBase
{
private:

// Helper method to add multiperiod logs to make a workspacegroup look like a real multiperiod workspace group.
void add_periods_logs(WorkspaceGroup_sptr ws)
{
int nperiods = static_cast<int>(ws->size());
for(size_t i = 0; i < ws->size(); ++i)
{
MatrixWorkspace_sptr currentWS = boost::dynamic_pointer_cast<MatrixWorkspace>(ws->getItem(i));
PropertyWithValue<int>* nperiodsProp = new PropertyWithValue<int>("nperiods", nperiods);
currentWS->mutableRun().addLogData(nperiodsProp);
PropertyWithValue<int>* currentPeriodsProp = new PropertyWithValue<int>("current_period", static_cast<int>(i+1));
currentWS->mutableRun().addLogData(currentPeriodsProp);
}
}
/// Helper to fabricate a workspace group consisting of equal sized matrixworkspaces.
WorkspaceGroup_sptr create_good_multiperiod_workspace_group(const std::string name)
{
MatrixWorkspace_sptr a = MatrixWorkspace_sptr(new WorkspaceTester);
MatrixWorkspace_sptr b = MatrixWorkspace_sptr(new WorkspaceTester);
//a->setName(name + "_1");
//b->setName(name + "_2");
WorkspaceGroup_sptr group = boost::make_shared<WorkspaceGroup>();
//group->setName(name);
group->addWorkspace(a);
group->addWorkspace(b);
add_periods_logs(group);
// AnalysisDataService::Instance().addOrReplace(a->name(), a);
// AnalysisDataService::Instance().addOrReplace(b->name(), b);
AnalysisDataService::Instance().addOrReplace(name+"_1", a);
AnalysisDataService::Instance().addOrReplace(name+"_2", b);
AnalysisDataService::Instance().addOrReplace(name, group);
return group;
}

public:

Expand Down
61 changes: 61 additions & 0 deletions Code/Mantid/Framework/API/test/MultiPeriodGroupTestBase.h
@@ -0,0 +1,61 @@
/*
* MultiPeriodGroupTestBase.h
*
* Created on: 18 Aug 2014
* Author: spu92482
*/

#ifndef MANTID_API_MULTIPERIODGROUPTESTBASE_H_
#define MANTID_API_MULTIPERIODGROUPTESTBASE_H_

#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/PropertyWithValue.h"
#include "MantidTestHelpers/FakeObjects.h"


using namespace Mantid::API;
using namespace Mantid::Kernel;

class MultiPeriodGroupTestBase
{

protected:

// Helper method to add multiperiod logs to make a workspacegroup look like a real multiperiod workspace group.
void add_periods_logs(WorkspaceGroup_sptr ws)
{
int nperiods = static_cast<int>(ws->size());
for (size_t i = 0; i < ws->size(); ++i)
{
MatrixWorkspace_sptr currentWS = boost::dynamic_pointer_cast<MatrixWorkspace>(ws->getItem(i));
PropertyWithValue<int>* nperiodsProp = new PropertyWithValue<int>("nperiods", nperiods);
currentWS->mutableRun().addLogData(nperiodsProp);
PropertyWithValue<int>* currentPeriodsProp = new PropertyWithValue<int>("current_period",
static_cast<int>(i + 1));
currentWS->mutableRun().addLogData(currentPeriodsProp);
}
}

/// Helper to fabricate a workspace group consisting of equal sized matrixworkspaces.
WorkspaceGroup_sptr create_good_multiperiod_workspace_group(const std::string name)
{
MatrixWorkspace_sptr a = MatrixWorkspace_sptr(new WorkspaceTester);
MatrixWorkspace_sptr b = MatrixWorkspace_sptr(new WorkspaceTester);

WorkspaceGroup_sptr group = boost::make_shared<WorkspaceGroup>();
//group->setName(name);
group->addWorkspace(a);
group->addWorkspace(b);
add_periods_logs(group);

AnalysisDataService::Instance().addOrReplace(name + "_1", a);
AnalysisDataService::Instance().addOrReplace(name + "_2", b);
AnalysisDataService::Instance().addOrReplace(name, group);
return group;
}

};

#endif /* MANTID_API_MULTIPERIODGROUPTESTBASE_H_ */

0 comments on commit 2433568

Please sign in to comment.