Skip to content

Commit

Permalink
Made setName private in Workspace and WorkspaceGroup. Re #6199.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed May 23, 2013
1 parent e9fb37e commit 9ef86c6
Show file tree
Hide file tree
Showing 32 changed files with 152 additions and 87 deletions.
13 changes: 11 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/Workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ namespace Kernel

namespace API
{

//----------------------------------------------------------------------
// Forward Declarations
//----------------------------------------------------------------------
class AnalysisDataServiceImpl;
class WorkspaceGroup;

/** Base Workspace Abstract Class.
@author Laurent C Chapon, ISIS, RAL
Expand Down Expand Up @@ -67,8 +74,6 @@ class MANTID_API_DLL Workspace : public Kernel::DataItem

void virtual setTitle(const std::string&);
void setComment(const std::string&);
virtual void setName(const std::string& name,bool force = false);
//virtual const std::string& getTitle() const;
virtual const std::string getTitle() const;
const std::string& getComment() const;
const std::string& getName() const;
Expand All @@ -85,6 +90,8 @@ class MANTID_API_DLL Workspace : public Kernel::DataItem


private:
/// Set name of this workspace. Only ADS can set names.
virtual void setName(const std::string& name,bool force = false);
/// The title of the workspace
std::string m_title;
/// A user-provided comment that is attached to the workspace
Expand All @@ -96,6 +103,8 @@ class MANTID_API_DLL Workspace : public Kernel::DataItem
/// The history of the workspace, algorithm and environment
WorkspaceHistory m_history;

friend class AnalysisDataServiceImpl;
friend class WorkspaceGroup;
};


Expand Down
12 changes: 8 additions & 4 deletions Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Workspace.h"
#include "MantidAPI/AnalysisDataService.h"

#include <Poco/NObserver.h>
#include <Poco/Mutex.h>
Expand All @@ -23,7 +22,10 @@ namespace Kernel

namespace API
{

//----------------------------------------------------------------------
// Forward Declarations
//----------------------------------------------------------------------
class AnalysisDataServiceImpl;
/** Class to hold a set of workspaces.
The workspace group can be an entry in the AnalysisDataService.
Its constituent workspaces should also have individual ADS entries.
Expand Down Expand Up @@ -61,8 +63,6 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
~WorkspaceGroup();
/// Return a string ID of the class
virtual const std::string id() const { return "WorkspaceGroup"; }
/// Set the name
virtual void setName(const std::string &name,bool force = false);
/// The size of the group.
virtual size_t getMemorySize() const;
/// Adds a workspace to the group.
Expand Down Expand Up @@ -111,6 +111,8 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
WorkspaceGroup(const WorkspaceGroup& ref);
/// Private, unimplemented copy assignment operator
const WorkspaceGroup& operator=(const WorkspaceGroup&);
/// Set the name
virtual void setName(const std::string &name,bool force = false);

/// The list of workspace pointers in the group
std::vector<Workspace_sptr> m_workspaces;
Expand All @@ -122,6 +124,8 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
static Kernel::Logger& g_log;
/// Maximum nesting level allowed
static size_t g_maxNestingLevel;

friend class AnalysisDataServiceImpl;
};

/// Shared pointer to a workspace group class
Expand Down
5 changes: 3 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,11 @@ namespace Mantid
if ( ! this->operator()() && isOptional() ) return result;
if ( this->direction() ) // Output or InOut
{
auto ws = this->operator()();
// Check that workspace exists
if ( ! this->operator()() ) throw std::runtime_error("WorkspaceProperty doesn't point to a workspace");
if ( ! ws ) throw std::runtime_error("WorkspaceProperty doesn't point to a workspace");
// Note use of addOrReplace rather than add
API::AnalysisDataService::Instance().addOrReplace(m_workspaceName, this->operator()() );
API::AnalysisDataService::Instance().addOrReplace(m_workspaceName, ws );
result = true;
}
//always clear the internal pointer after storing
Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/API/src/AnalysisDataService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ namespace Mantid
{
verifyName(name);

// if workspace is already in the ADS this is equivalent to rename
if ( ! workspace->name().empty() )
{
rename( workspace->name(), name );
return;
}
//Attach the new name to the workspace
if( workspace ) workspace->setName(name,true);
Kernel::DataService<API::Workspace>::addOrReplace(name, workspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,11 @@ class MultiPeriodGroupAlgorithmTest : public CxxTest::TestSuite
{
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(group->name(), group);
AnalysisDataService::Instance().addOrReplace(name, group);
return group;
}

Expand Down Expand Up @@ -265,4 +260,4 @@ class MultiPeriodGroupAlgorithmTest : public CxxTest::TestSuite
};


#endif /* MANTID_API_MultiPeriodGroupAlgorithmTEST_H_ */
#endif /* MANTID_API_MultiPeriodGroupAlgorithmTEST_H_ */
11 changes: 8 additions & 3 deletions Code/Mantid/Framework/API/test/WorkspaceGroupTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,21 @@ class WorkspaceGroupTest : public CxxTest::TestSuite
{
WorkspaceGroup_sptr group(makeGroup());
Workspace_sptr ws(new WorkspaceTester());
ws->setName("workspace");
AnalysisDataService::Instance().add("workspace", ws);

group->addWorkspace(ws);
group->addWorkspace(makeWorkspace());

group->setName("group");
//group->setName("group");
AnalysisDataService::Instance().add("group",group);
TS_ASSERT_EQUALS(group->name(), "group");
TS_ASSERT_EQUALS(group->getItem(0)->name(), "group_1");
TS_ASSERT_EQUALS(group->getItem(1)->name(), "group_2");
TS_ASSERT_EQUALS(group->getItem(2)->name(), "group_3");
TS_ASSERT_EQUALS(group->getItem(3)->name(), "workspace");
TS_ASSERT_EQUALS(group->getItem(4)->name(), "group_4");

AnalysisDataService::Instance().clear();
}

void test_addWorkspace_increases_group_size_by_1()
Expand Down Expand Up @@ -464,7 +468,8 @@ class WorkspaceGroupTest : public CxxTest::TestSuite
void test_areNamesSimilar()
{
WorkspaceGroup_sptr group(new WorkspaceGroup());
group->setName("name");
//group->setName("name");
AnalysisDataService::Instance().addOrReplace("name", group);
TSM_ASSERT( "Empty group is not similar", !group->areNamesSimilar() );

boost::shared_ptr<WorkspaceTester> ws(new WorkspaceTester());
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Algorithms/src/DetectorDiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ namespace Mantid
// Perform FindDetectorsOutsideLimits and MedianDetectorTest on the
// detector vanadium
maskWS = this->doDetVanTest(inputWS, numFailed);
maskWS->setName(maskName);
//maskWS->setName(maskName);

// DetectorEfficiencyVariation (only if two workspaces are specified)
if (input2WS)
Expand Down Expand Up @@ -352,7 +352,7 @@ namespace Mantid
extract->setProperty("DetectorList", detList);
extract->executeAsChildAlg();
maskWS = extract->getProperty("OutputWorkspace");
maskWS->setName(maskName);
//maskWS->setName(maskName);

this->setProperty("OutputWorkspace", maskWS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ namespace Algorithms

// 1. Initialize:use dummy numbers for arguments, for event workspace it doesn't matter
outputWS = DataObjects::EventWorkspace_sptr(new DataObjects::EventWorkspace());
outputWS->setName("FilteredWorkspace");
//outputWS->setName("FilteredWorkspace");
outputWS->initialize(1,1,1);

// 2. Set the units
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ConvertToMatrixWorkspaceTest : public CxxTest::TestSuite

void testExec_2D_to_2D()
{
AnalysisDataService::Instance().clear();
if ( !cloner.isInitialized() ) cloner.initialize();

Mantid::DataHandling::LoadRaw3 loader;
Expand Down
13 changes: 10 additions & 3 deletions Code/Mantid/Framework/Algorithms/test/CorrectToFileTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class CorrectToFileTest : public CxxTest::TestSuite
static void destroySuite( CorrectToFileTest *suite ) { delete suite; }

CorrectToFileTest() : inputFile("DIRECT.041")
{}
{

}

void testInit()
{
Expand Down Expand Up @@ -63,6 +65,7 @@ class CorrectToFileTest : public CxxTest::TestSuite

void testExecEvent()
{
AnalysisDataService::Instance().clear();
//Need a workspace to correct
MatrixWorkspace_sptr testInput =
WorkspaceCreationHelper::CreateEventWorkspace(10, 102, 100, 1.5);
Expand All @@ -89,7 +92,9 @@ class CorrectToFileTest : public CxxTest::TestSuite
}

void testSpectraDivide()
{ //Need a workspace to correct
{
AnalysisDataService::Instance().clear();
//Need a workspace to correct
MatrixWorkspace_sptr testInput =
WorkspaceCreationHelper::Create2DWorkspaceBinned(102, 32, 1.5);

Expand All @@ -114,7 +119,9 @@ class CorrectToFileTest : public CxxTest::TestSuite


void testSpectraMultip()
{ //Need a workspace to correct
{
AnalysisDataService::Instance().clear();
//Need a workspace to correct
MatrixWorkspace_sptr testInput =
WorkspaceCreationHelper::Create2DWorkspaceBinned(102, 32, 1.5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class ExportTimeSeriesLogTest : public CxxTest::TestSuite
// 1. Empty workspace
DataObjects::EventWorkspace_sptr eventws =
WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(2, 2, true);
eventws->setName("TestWorkspace");
//eventws->setName("TestWorkspace");

// 2. Run star time
int64_t runstarttime_ns = 3000000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ class FilterEventsHighFrequencyTest : public CxxTest::TestSuite

load.setProperty("Workspace", iws);
load.setProperty("InstrumentName", "VULCAN");
load.setChild(true);

load.execute();

Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Algorithms/test/FilterEventsTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FilterEventsTest : public CxxTest::TestSuite
size_t numpulses = 5;

DataObjects::EventWorkspace_sptr eventws = createEventWorkspace(runstart_i64, pulsedt, tofdt, numpulses);
eventws->setName("Test01");
//eventws->setName("Test01");

TS_ASSERT_EQUALS(eventws->getNumberEvents(), 500);

Expand Down
14 changes: 14 additions & 0 deletions Code/Mantid/Framework/Algorithms/test/FindPeaksTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@
#include "MantidDataHandling/LoadNexusProcessed.h"
#include "MantidDataHandling/LoadInstrument.h"
#include "MantidCurveFitting/GaussianLinearBG1D.h"
#include "MantidAPI/AnalysisDataService.h"

using Mantid::Algorithms::FindPeaks;

class FindPeaksTest : public CxxTest::TestSuite
{
public:
static FindPeaksTest *createSuite() { return new FindPeaksTest(); }
static void destroySuite(FindPeaksTest *suite) { delete suite; }

FindPeaksTest()
{
Mantid::API::AnalysisDataService::Instance().clear();
}

~FindPeaksTest()
{
Mantid::API::AnalysisDataService::Instance().clear();
}

void testTheBasics()
{
FindPeaks finder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class GenerateEventsFilterTest : public CxxTest::TestSuite
// 1. Empty workspace
DataObjects::EventWorkspace_sptr eventws =
WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(2, 2, true);
eventws->setName("TestWorkspace");
//eventws->setName("TestWorkspace");

// 2. Run star time
int64_t runstarttime_ns = 3000000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class GetTimeSeriesLogInformationTest : public CxxTest::TestSuite
// 1. Empty workspace
DataObjects::EventWorkspace_sptr eventws =
WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(2, 2, true);
eventws->setName("TestWorkspace");
//eventws->setName("TestWorkspace");

// 2. Run star time
int64_t runstarttime_ns = 3000000000;
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Algorithms/test/IQTransformTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class IQTransformTest : public CxxTest::TestSuite

IQTransformTest()
{
Mantid::API::AnalysisDataService::Instance().clear();
iq.setChild(true); // This means the ADS is not involved anywhere in this test

inWS_hist = WorkspaceCreationHelper::Create2DWorkspaceBinned(1,2);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Algorithms/test/InvertMaskTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InvertMaskTest : public CxxTest::TestSuite
// 1. Create Mask Workspaces
Mantid::Geometry::Instrument_sptr inst1 = ComponentCreationHelper::createTestInstrumentCylindrical(5);
Mantid::DataObjects::MaskWorkspace_sptr ws1(new Mantid::DataObjects::MaskWorkspace(inst1));
ws1->setName("OriginalMask");
//ws1->setName("OriginalMask");
AnalysisDataService::Instance().addOrReplace("OriginalMask", ws1);

std::cout << "Input MaskWorkspace Size = " << ws1->getNumberHistograms() << std::endl;
Expand Down

0 comments on commit 9ef86c6

Please sign in to comment.