Skip to content

Commit

Permalink
refs #6352. Update existing conversion algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 16, 2013
1 parent 9c45cd6 commit 6c251b8
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDEventWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ namespace API

virtual bool threadSafe() const;

virtual void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem) = 0;

protected:
/// Marker set to true when a file-backed workspace needs its back-end file updated (by calling SaveMD(UpdateFileBackEnd=1) )
bool m_fileNeedsUpdating;
Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ namespace Mantid
/// Special coordinate systems
enum SpecialCoordinateSystem
{
None = 0,
HKL = 1,
QLab = 2,
QSample = 3
None = 0,
QLab = 1,
QSample = 2,
HKL = 3
};


Expand Down
15 changes: 12 additions & 3 deletions Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ void testExecNoQ()
pAlg->setRethrows(true);
TS_ASSERT_THROWS_NOTHING(pAlg->execute());
checkHistogramsHaveBeenStored("WS3DNoQ");
AnalysisDataService::Instance().remove("WS3DNoQ");

auto outWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>("WS3DNoQ");
TS_ASSERT_EQUALS(Mantid::API::None, outWS->getSpecialCoordinateSystem());

AnalysisDataService::Instance().remove("WS3DNoQ");
}

void testExecModQ()
Expand All @@ -131,8 +134,11 @@ void testExecModQ()
pAlg->setRethrows(true);
TS_ASSERT_THROWS_NOTHING(pAlg->execute());
checkHistogramsHaveBeenStored("WS3DmodQ");
AnalysisDataService::Instance().remove("WS3DmodQ");

auto outWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>("WS3DmodQ");
TS_ASSERT_EQUALS(Mantid::API::None, outWS->getSpecialCoordinateSystem());

AnalysisDataService::Instance().remove("WS3DmodQ");
}

void testExecQ3D()
Expand All @@ -147,11 +153,14 @@ void testExecQ3D()
pAlg->setPropertyValue("MinValues","-10,-10,-10, 0,-10,-10");
pAlg->setPropertyValue("MaxValues"," 10, 10, 10, 20, 40, 20");


pAlg->setRethrows(false);
pAlg->execute();
TSM_ASSERT("Shoud finish succesfully",pAlg->isExecuted());
checkHistogramsHaveBeenStored("WS5DQ3D");

auto outWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>("WS5DQ3D");
TS_ASSERT_EQUALS(Mantid::API::QSample, outWS->getSpecialCoordinateSystem());

AnalysisDataService::Instance().remove("WS5DQ3D");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ namespace MDEvents
// On multiprocessor machine the algorithm should run and utilizes all cores (see Kernel::Threadpool),
// but this can be chenged setting this parameter to 0 (no multithreading) or positive number specifying the requested nymber of threads
int m_NumThreads;
/// Any special coordinate system used.
Mantid::API::SpecialCoordinateSystem m_coordinateSystem;
private:
/** internal function which do one peace of work, which should be performed by one thread
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class ConvToMDEventsWS: public ConvToMDBase

/**function converts particular type of events into MD space and add these events to the workspace itself */
template <class T> size_t convertEventList(size_t workspaceIndex);

};

} // endNamespace MDEvents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class DLLExport MDWSDescription : public Kernel::PropertyManager
static void fillAddProperties(Mantid::API::MatrixWorkspace_const_sptr inWS2D,const std::vector<std::string> &dimProperyNames,std::vector<coord_t> &AddCoord);

static boost::shared_ptr<Geometry::OrientedLattice> getOrientedLattice(Mantid::API::MatrixWorkspace_const_sptr inWS2D);

/// Set the special coordinate system if any.
void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem system);
/// @return the special coordinate system if any.
Mantid::API::SpecialCoordinateSystem getCoordinateSystem() const;
protected: // until MDWSDesctiptionDepricatedExist
/// the variable which describes the number of the dimensions, in the target workspace.
/// Calculated from number of input properties and the operations, performed on input workspace;
Expand All @@ -151,7 +156,9 @@ class DLLExport MDWSDescription : public Kernel::PropertyManager
//********************* internal helpers
/// helper function to resize all vectors, responsible for MD dimensions in one go
void resizeDimDescriptions(unsigned int Dims,size_t nBins=10);

private:
/// Coordinate system.
Mantid::API::SpecialCoordinateSystem m_coordinateSystem;
};

}
Expand Down
6 changes: 4 additions & 2 deletions Code/Mantid/Framework/MDEvents/src/ConvToMDBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ namespace Mantid
}
catch(Kernel::Exception::NotFoundError &){}


// Record any special coordinate system known to the description.
m_coordinateSystem = WSD.getCoordinateSystem();

return n_spectra;
};

/** empty default constructor */
ConvToMDBase::ConvToMDBase():m_NumThreads(-1)
ConvToMDBase::ConvToMDBase():m_NumThreads(-1), m_coordinateSystem(Mantid::API::None)
{ }


Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/ConvToMDEventsWS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ namespace Mantid
if(!m_EventWS)
throw(std::logic_error(" ConvertToMDEventWS should work with defined event workspace"));

// Record any special coordinate system known to the description.
m_coordinateSystem = WSD.getCoordinateSystem();
return numSpec;
}

Expand Down Expand Up @@ -180,8 +182,10 @@ namespace Mantid
m_OutWSWrapper->pWorkspace()->refreshCache();
m_OutWSWrapper->refreshCentroid();
pProgress->report();
}

/// Set the special coordinate system flag on the output workspace.
m_OutWSWrapper->pWorkspace()->setCoordinateSystem(m_coordinateSystem);
}


} // endNamespace MDEvents
Expand Down
5 changes: 4 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/ConvToMDHistoWS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ namespace Mantid
}
m_OutWSWrapper->pWorkspace()->refreshCache();
m_OutWSWrapper->refreshCentroid();
pProgress->report();
pProgress->report();

/// Set the special coordinate system flag on the output workspace.
m_OutWSWrapper->pWorkspace()->setCoordinateSystem(m_coordinateSystem);
}
/**function calculates the size of temporary memory used to keep convertTo MD data before these data should be added to MDEvents
* @param nThreads -- number of threads used to process data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ namespace MDEvents

std::string dimensionNames[3] = {"Q_lab_x", "Q_lab_y", "Q_lab_z"};
std::string dimensionUnits = "Angstroms^-1";
Mantid::API::SpecialCoordinateSystem coordinateSystem = Mantid::API::QLab;
if (OutputDimensions == "Q (sample frame)")
{
// Set the matrix based on goniometer angles
Expand All @@ -410,6 +411,7 @@ namespace MDEvents
dimensionNames[0] = "Q_sample_x";
dimensionNames[1] = "Q_sample_y";
dimensionNames[2] = "Q_sample_z";
coordinateSystem = Mantid::API::QSample;
}
else if (OutputDimensions == "HKL")
{
Expand All @@ -426,6 +428,7 @@ namespace MDEvents
dimensionNames[1] = "K";
dimensionNames[2] = "L";
dimensionUnits = "lattice";
coordinateSystem = Mantid::API::HKL;
}
// Q in the lab frame is the default, so nothing special to do.

Expand Down Expand Up @@ -616,6 +619,8 @@ namespace MDEvents
g_log.information() << std::endl;
}

// Set the special coordinate system.
ws->setCoordinateSystem(coordinateSystem);

// Save the output
setProperty("OutputWorkspace", boost::dynamic_pointer_cast<IMDEventWorkspace>(ws));
Expand Down
18 changes: 17 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/MDWSDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ MDWSDescription::MDWSDescription(unsigned int nDimensions):
m_Wtransf(3,3,true),
m_RotMatrix(9,0),
m_Emode(Kernel::DeltaEMode::Undefined),
m_LorentzCorr(false)
m_LorentzCorr(false),
m_coordinateSystem(Mantid::API::None)
{

this->resizeDimDescriptions(nDimensions);
Expand Down Expand Up @@ -317,6 +318,21 @@ boost::shared_ptr<Geometry::OrientedLattice> MDWSDescription::getOrientedLattice

}

/** Set the special coordinate system if any.
@param coordinate system.
*/
void MDWSDescription::setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem system)
{
m_coordinateSystem = system;
}

/// @return the special coordinate system if any.
Mantid::API::SpecialCoordinateSystem MDWSDescription::getCoordinateSystem() const
{
return m_coordinateSystem;
}



} //end namespace MDEvents
} //end namespace Mantid
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDWSTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,23 @@ void MDWSTransform::setQ3DDimensionsNames(MDEvents::MDWSDescription &TargWSDescr
dimNames[0]="Q_lab_x";
dimNames[1]="Q_lab_y";
dimNames[2]="Q_lab_z";
TargWSDescription.setCoordinateSystem(Mantid::API::QLab);
break;
}
case(CnvrtToMD::SampleFrame):
{
dimNames[0]="Q_sample_x";
dimNames[1]="Q_sample_y";
dimNames[2]="Q_sqmple_z";
TargWSDescription.setCoordinateSystem(Mantid::API::QSample);
break;
}
case(CnvrtToMD::HKLFrame):
{
dimNames[0]="H";
dimNames[1]="K";
dimNames[2]="L";
TargWSDescription.setCoordinateSystem(Mantid::API::HKL);
break;
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ConvertToDiffractionMDWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT(ws);
if (!ws) return;
TS_ASSERT_EQUALS( ws->getDimension(0)->getName(), "Q_lab_x");
TS_ASSERT_EQUALS( ws->getSpecialCoordinateSystem(), Mantid::API::QLab);

// But you can't add to an existing one of the wrong dimensions type, if you choose Append
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", 8,
Expand Down Expand Up @@ -81,10 +82,22 @@ class ConvertToDiffractionMDWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT(ws);
if (!ws) return;
TS_ASSERT_EQUALS( ws->getDimension(0)->getName(), "H");
}

TS_ASSERT_EQUALS( ws->getSpecialCoordinateSystem(), Mantid::API::HKL);

AnalysisDataService::Instance().remove("testOutMD");
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", 6,
"InputWorkspace", "testInEW",
"OutputWorkspace", "testOutMD",
"OutputDimensions", "Q (sample frame)"
);
TS_ASSERT( alg->isExecuted() );

TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>("testOutMD") );
TS_ASSERT(ws);
if (!ws) return;
TS_ASSERT_EQUALS( ws->getDimension(0)->getName(), "Q_sample_x");
TS_ASSERT_EQUALS( ws->getSpecialCoordinateSystem(), Mantid::API::QSample);
}

void do_test_MINITOPAZ(EventType type, size_t numTimesToAdd = 1,
bool OneEventPerBin=false, bool MakeWorkspace2D = false)
Expand Down
17 changes: 16 additions & 1 deletion Code/Mantid/Framework/MDEvents/test/MDWSDescriptionTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,23 @@ class MDWSDescriptionTest : public CxxTest::TestSuite
//}

}


void test_defaultCoordinateSystem()
{
MDWSDescription description;
TS_ASSERT_EQUALS(Mantid::API::None, description.getCoordinateSystem());
}

void test_setCoordinateSystem()
{
using namespace Mantid::API;
const SpecialCoordinateSystem expectedResult = QSample;

MDWSDescription description;
description.setCoordinateSystem(expectedResult);
TS_ASSERT_EQUALS(expectedResult, description.getCoordinateSystem());
}

MDWSDescriptionTest()
{
ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(4,10,true);
Expand Down

0 comments on commit 6c251b8

Please sign in to comment.