Skip to content

Commit

Permalink
refs #6393. Working algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 24, 2013
1 parent 4484576 commit 381ddfc
Show file tree
Hide file tree
Showing 13 changed files with 963 additions and 497 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ set ( INC_FILES
inc/MantidAPI/SampleEnvironment.h
inc/MantidAPI/SingleValueParameter.h
inc/MantidAPI/SingleValueParameterParser.h
inc/MantidAPI/SpecialCoordinateSystem.h
inc/MantidAPI/SpectraAxis.h
inc/MantidAPI/SpectraDetectorMap.h
inc/MantidAPI/TableRow.h
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDHistoWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ namespace API
virtual size_t getLinearIndex(size_t index1, size_t index2, size_t index3, size_t index4) const = 0;

virtual double & operator [](const size_t & index) = 0;

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

/// Shared pointer to the IMDWorkspace base class
Expand Down
11 changes: 1 addition & 10 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "MantidAPI/MDGeometry.h"
#include "MantidGeometry/MDGeometry/MDImplicitFunction.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidAPI/SpecialCoordinateSystem.h"

namespace Mantid
{
Expand All @@ -36,16 +37,6 @@ namespace Mantid
NumEventsNormalization = 2
};


/// Special coordinate systems
enum SpecialCoordinateSystem
{
None = 0,
QLab = 1,
QSample = 2,
HKL = 3
};


/** Basic MD Workspace Abstract Class.
*
Expand Down
17 changes: 16 additions & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/IPeaksWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//----------------------------------------------------------------------
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/ExperimentInfo.h"
#include "MantidAPI/SpecialCoordinateSystem.h"

namespace Mantid
{
Expand Down Expand Up @@ -121,7 +122,21 @@ namespace API
* @returns A shared pointer to a TableWorkspace containing the information
*/
virtual API::ITableWorkspace_sptr createDetectorTable() const = 0;
};

//---------------------------------------------------------------------------------------------
/**
* Set the special coordinate system.
* @param coordinateSystem : Special Q3D coordinate system to use.
*/
virtual void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem) = 0;

//---------------------------------------------------------------------------------------------
/**
* Get the special coordinate system.
* @returns special Q3D coordinate system to use being used by this PeaksWorkspace object. Probably the one the workspace was generated with.
*/
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const = 0;
};


/// Typedef for a shared pointer to a peaks workspace.
Expand Down
19 changes: 19 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/SpecialCoordinateSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef MANTID_MDALGORITHMS_SpecialCoordinateSystem_H_
#define MANTID_MDALGORITHMS_SpecialCoordinateSystem_H_

namespace Mantid
{
namespace API
{
/**
* Special coordinate systems for Q3D.
*/
enum SpecialCoordinateSystem
{
None = 0, QLab = 1, QSample = 2, HKL = 3
};

}
}

#endif
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Crystal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set ( SRC_FILES
src/SelectCellOfType.cpp
src/SelectCellWithForm.cpp
src/SetGoniometer.cpp
src/SetSpecialCoordinates.cpp
src/SetUB.cpp
src/ShowPossibleCells.cpp
src/SortHKL.cpp
Expand Down Expand Up @@ -77,6 +78,7 @@ set ( INC_FILES
inc/MantidCrystal/SelectCellOfType.h
inc/MantidCrystal/SelectCellWithForm.h
inc/MantidCrystal/SetGoniometer.h
inc/MantidCrystal/SetSpecialCoordinates.h
inc/MantidCrystal/SetUB.h
inc/MantidCrystal/ShowPossibleCells.h
inc/MantidCrystal/SortHKL.h
Expand Down Expand Up @@ -118,6 +120,7 @@ set ( TEST_FILES
SelectCellOfTypeTest.h
SelectCellWithFormTest.h
SetGoniometerTest.h
SetSpecialCoordinatesTest.h
SetUBTest.h
ShowPossibleCellsTest.h
SortHKLTest.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef MANTID_CRYSTAL_SETSPECIALCOORDINATES_H_
#define MANTID_CRYSTAL_SETSPECIALCOORDINATES_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IMDWorkspace.h"
#include <vector>
#include <string>

namespace Mantid
{
namespace Crystal
{

/** SetSpecialCoordinates :
*
Set the special coordinates on an IMDWorspace or peaksworkspace. Also print out any existing special coordinates.
Copyright &copy; 2013 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 SetSpecialCoordinates : public API::Algorithm
{
public:
SetSpecialCoordinates();
virtual ~SetSpecialCoordinates();

virtual const std::string name() const;
virtual int version() const;
virtual const std::string category() const;

private:
virtual void initDocs();
void init();
void exec();
std::vector<std::string> m_specialCoordinatesNames;
typedef std::map<std::string, Mantid::API::SpecialCoordinateSystem> SpecialCoordinatesNameMap;
SpecialCoordinatesNameMap m_specialCoordinatesMap;
static const std::string QLabOption();
static const std::string QSampleOption();
static const std::string HKLOption();
bool writeCoordinatesToMDEventWorkspace(Mantid::API::Workspace_sptr inWS, Mantid::API::SpecialCoordinateSystem coordinateSystem);
bool writeCoordinatesToMDHistoWorkspace(Mantid::API::Workspace_sptr inWS, Mantid::API::SpecialCoordinateSystem coordinateSystem);
bool writeCoordinatesToPeaksWorkspace(Mantid::API::Workspace_sptr inWS, Mantid::API::SpecialCoordinateSystem coordinateSystem);
};


} // namespace Crystal
} // namespace Mantid

#endif /* MANTID_CRYSTAL_SETSPECIALCOORDINATES_H_ */
164 changes: 164 additions & 0 deletions Code/Mantid/Framework/Crystal/src/SetSpecialCoordinates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*WIKI*
TODO: Enter a full wiki-markup description of your algorithm here. You can then use the Build/wiki_maker.py script to generate your full wiki page.
*WIKI*/

#include "MantidCrystal/SetSpecialCoordinates.h"
#include "MantidAPI/WorkspaceValidators.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidAPI/IMDHistoWorkspace.h"
#include "MantidKernel/ListValidator.h"
#include <boost/make_shared.hpp>

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

namespace Mantid
{
namespace Crystal
{

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(SetSpecialCoordinates)

const std::string SetSpecialCoordinates::QLabOption()
{
static const std::string ret("Q (lab frame)");
return ret;
}

const std::string SetSpecialCoordinates::QSampleOption()
{
static const std::string ret("Q (sample frame)");
return ret;
}

const std::string SetSpecialCoordinates::HKLOption()
{
static const std::string ret("HKL");
return ret;
}

//----------------------------------------------------------------------------------------------
/** Constructor
*/
SetSpecialCoordinates::SetSpecialCoordinates()
{
m_specialCoordinatesNames.push_back(SetSpecialCoordinates::QLabOption());
m_specialCoordinatesNames.push_back(SetSpecialCoordinates::QSampleOption());
m_specialCoordinatesNames.push_back(SetSpecialCoordinates::HKLOption());

m_specialCoordinatesMap.insert(
std::make_pair(SetSpecialCoordinates::QLabOption(), Mantid::API::QLab));
m_specialCoordinatesMap.insert(
std::make_pair(SetSpecialCoordinates::QSampleOption(), Mantid::API::QSample));
m_specialCoordinatesMap.insert(std::make_pair(SetSpecialCoordinates::HKLOption(), Mantid::API::HKL));
}

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


//----------------------------------------------------------------------------------------------
/// Algorithm's name for identification. @see Algorithm::name
const std::string SetSpecialCoordinates::name() const { return "SetSpecialCoordinates";};

/// Algorithm's version for identification. @see Algorithm::version
int SetSpecialCoordinates::version() const { return 1;};

/// Algorithm's category for identification. @see Algorithm::category
const std::string SetSpecialCoordinates::category() const { return "Crystal";}

//----------------------------------------------------------------------------------------------
/// Sets documentation strings for this algorithm
void SetSpecialCoordinates::initDocs()
{
this->setWikiSummary("Set or overwrite any Q3D special coordinates.");
this->setOptionalMessage("Set or overwrite any Q3D special coordinates.");
}

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void SetSpecialCoordinates::init()
{
declareProperty(new WorkspaceProperty<Workspace>("InputWorkspace", "", Direction::InOut),
"An input/output workspace. The new log will be added to it.");

declareProperty("SpecialCoordinates", "Q (lab frame)",
boost::make_shared<StringListValidator>(m_specialCoordinatesNames),
"What will be the dimensions of the output workspace?\n"
" Q (lab frame): Wave-vector change of the lattice in the lab frame.\n"
" Q (sample frame): Wave-vector change of the lattice in the frame of the sample (taking out goniometer rotation).\n"
" HKL: Use the sample's UB matrix to convert to crystal's HKL indices.");
}

bool SetSpecialCoordinates::writeCoordinatesToMDEventWorkspace(Workspace_sptr inWS, SpecialCoordinateSystem coordinateSystem)
{
bool written = false;
if (auto mdEventWS = boost::dynamic_pointer_cast<IMDEventWorkspace>(inWS))
{
mdEventWS->setCoordinateSystem(coordinateSystem);
written = true;
}
return written;
}

bool SetSpecialCoordinates::writeCoordinatesToMDHistoWorkspace(Workspace_sptr inWS,
SpecialCoordinateSystem coordinateSystem)
{
bool written = false;
if (auto mdHistoWS = boost::dynamic_pointer_cast<IMDHistoWorkspace>(inWS))
{
mdHistoWS->setCoordinateSystem(coordinateSystem);
written = true;
}
return written;
}

bool SetSpecialCoordinates::writeCoordinatesToPeaksWorkspace(Workspace_sptr inWS,
SpecialCoordinateSystem coordinateSystem)
{
bool written = false;
if (auto peaksWS = boost::dynamic_pointer_cast<IPeaksWorkspace>(inWS))
{
peaksWS->setCoordinateSystem(coordinateSystem);
written = true;
}
return written;
}

//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void SetSpecialCoordinates::exec()
{

Workspace_sptr inputWS = getProperty("InputWorkspace");

std::string requestedCoordinateSystem = getProperty("SpecialCoordinates");

SpecialCoordinateSystem coordinatesToUse = this->m_specialCoordinatesMap.find(requestedCoordinateSystem)->second;

// Try to write the coordinates to the various allowed types of workspace.
if(!writeCoordinatesToMDEventWorkspace(inputWS, coordinatesToUse))
{
if(!writeCoordinatesToMDHistoWorkspace(inputWS, coordinatesToUse))
{
if(!writeCoordinatesToPeaksWorkspace(inputWS, coordinatesToUse))
{
throw std::invalid_argument("A workspace of this type cannot be processed/");
}
}
}
}



} // namespace Crystal
} // namespace Mantid

0 comments on commit 381ddfc

Please sign in to comment.