-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4484576
commit 381ddfc
Showing
13 changed files
with
963 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Code/Mantid/Framework/API/inc/MantidAPI/SpecialCoordinateSystem.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Code/Mantid/Framework/Crystal/inc/MantidCrystal/SetSpecialCoordinates.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 © 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
164
Code/Mantid/Framework/Crystal/src/SetSpecialCoordinates.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.