Skip to content

Commit

Permalink
Refs #5855. First cut at algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Reuter committed Sep 12, 2012
1 parent 35fbffe commit 775d101
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/WorkflowAlgorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set ( SRC_FILES
src/DgsPreprocessData.cpp
src/DgsProcessDetectorVanadium.cpp
src/DgsReduction.cpp
src/DgsRemap.cpp
src/EQSANSDarkCurrentSubtraction.cpp
src/EQSANSInstrument.cpp
src/EQSANSLoad.cpp
Expand Down Expand Up @@ -36,6 +37,7 @@ set ( INC_FILES
inc/MantidWorkflowAlgorithms/DgsPreprocessData.h
inc/MantidWorkflowAlgorithms/DgsProcessDetectorVanadium.h
inc/MantidWorkflowAlgorithms/DgsReduction.h
inc/MantidWorkflowAlgorithms/DgsRemap.h
inc/MantidWorkflowAlgorithms/EQSANSDarkCurrentSubtraction.h
inc/MantidWorkflowAlgorithms/EQSANSInstrument.h
inc/MantidWorkflowAlgorithms/EQSANSLoad.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef MANTID_WORKFLOWALGORITHMS_DGSREMAP_H_
#define MANTID_WORKFLOWALGORITHMS_DGSREMAP_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"

namespace Mantid
{
namespace WorkflowAlgorithms
{

/** DgsRemap : TODO: DESCRIPTION
Copyright © 2012 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://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport DgsRemap : public API::Algorithm
{
public:
DgsRemap();
virtual ~DgsRemap();

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

private:
virtual void initDocs();
void init();
void exec();


};


} // namespace WorkflowAlgorithms
} // namespace Mantid

#endif /* MANTID_WORKFLOWALGORITHMS_DGSREMAP_H_ */
105 changes: 105 additions & 0 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/DgsRemap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*WIKI*
This algorithm is responsible for masking and grouping the given input workspace.
*WIKI*/

#include "MantidWorkflowAlgorithms/DgsRemap.h"
#include "MantidDataObjects/GroupingWorkspace.h"

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

namespace Mantid
{
namespace WorkflowAlgorithms
{

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

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

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

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

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

/// Algorithm's category for identification. @see Algorithm::category
const std::string DgsRemap::category() const { return "Workflow\\Inelastic"; }

//----------------------------------------------------------------------------------------------
/// Sets documentation strings for this algorithm
void DgsRemap::initDocs()
{
this->setWikiSummary("Mask and/or group the given workspace.");
this->setOptionalMessage("Mask and/or group the given workspace.");
}

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void DgsRemap::init()
{
this->declareProperty(new WorkspaceProperty<MatrixWorkspace>("InputWorkspace",
"", Direction::Input), "An input workspace to mask and group.");
this->declareProperty(new WorkspaceProperty<MatrixWorkspace>("MaskWorkspace",
"", Direction::Input), "A workspace containing masking information.");
this->declareProperty(new WorkspaceProperty<MatrixWorkspace>("GroupingWorkspace",
"", Direction::Input), "A workspace containing grouping information");
this->declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace",
"", Direction::Output), "The resulting workspace.");
}

//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void DgsRemap::exec()
{
MatrixWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
MatrixWorkspace_sptr maskWS = this->getProperty("MaskWorkspace");
MatrixWorkspace_sptr groupWS = this->getProperty("GroupingWorkspace");
MatrixWorkspace_sptr outputWS = this->getProperty("OutputWorkspace");

if (maskWS)
{
IAlgorithm_sptr mask = this->createSubAlgorithm("MaskDetectors");
mask->setProperty("Workspace", inputWS);
mask->setProperty("MaskedWorkspace", maskWS);
mask->executeAsSubAlg();
}

if (groupWS)
{
int64_t ngroups = 0;
std::vector<int> groupDetIdList;
GroupingWorkspace_sptr gWS = boost::dynamic_pointer_cast<GroupingWorkspace>(groupWS);
gWS->makeDetectorIDToGroupVector(groupDetIdList, ngroups);

IAlgorithm_sptr group = this->createSubAlgorithm("GroupDetectors");
group->setProperty("InputWorkspace", inputWS);
group->setProperty("OutputWorkspace", outputWS);
group->setProperty("DetectorList", groupDetIdList);
group->setProperty("Behaviour", "Average");
group->executeAsSubAlg();
}

this->setProperty("OutputWorkspace", outputWS);
}
} // namespace WorkflowAlgorithms
} // namespace Mantid

0 comments on commit 775d101

Please sign in to comment.