Skip to content

Commit

Permalink
refs #7664. Update ClearUB to provide a DryRun mode.
Browse files Browse the repository at this point in the history
Also add output property indicating the action taken or to be taken.
  • Loading branch information
OwenArnold committed Aug 22, 2013
1 parent be43df0 commit 5fb5775
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Crystal/inc/MantidCrystal/ClearUB.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Crystal
virtual const std::string category() const;

private:
void clearSingleExperimentInfo(Mantid::API::ExperimentInfo * const experimentInfo) const;
bool clearSingleExperimentInfo(Mantid::API::ExperimentInfo * const experimentInfo, const bool dryRun) const;
virtual void initDocs();
void init();
void exec();
Expand Down
192 changes: 112 additions & 80 deletions Code/Mantid/Framework/Crystal/src/ClearUB.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*WIKI*
Clears the OrientedLattice of each ExperimentInfo attached to the intput [[Workspace]]. Works with both single ExperimentInfos and MultipleExperimentInfo instances.
Clears the OrientedLattice of each ExperimentInfo attached to the intput [[Workspace]]. Works with both single ExperimentInfos and MultipleExperimentInfo instances.
*WIKI*/
*WIKI*/

#include "MantidCrystal/ClearUB.h"
#include "MantidAPI/MultipleExperimentInfos.h"
Expand All @@ -12,100 +12,132 @@ using namespace Mantid::API;

namespace Mantid
{
namespace Crystal
{
namespace Crystal
{

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

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

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

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

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


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

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

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

//----------------------------------------------------------------------------------------------
/// Sets documentation strings for this algorithm
void ClearUB::initDocs()
{
this->setWikiSummary("Clears the UB by removing the oriented lattice from the sample.");
this->setOptionalMessage(this->getWikiSummary());
}

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void ClearUB::init()
{
declareProperty(new WorkspaceProperty<Workspace>("Workspace","",Direction::InOut), "Workspace to clear the UB from.");
}

/**
* Clear the Oriented Lattice from a single experiment info.
* @param experimentInfo
*/
void ClearUB::clearSingleExperimentInfo(ExperimentInfo * const experimentInfo) const
{
Sample& sampleObject = experimentInfo->mutableSample();
if(!sampleObject.hasOrientedLattice())
//----------------------------------------------------------------------------------------------
/** Destructor
*/
ClearUB::~ClearUB()
{
this->g_log.information("Workspace has no oriented lattice to clear.");
}
else

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

//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void ClearUB::exec()
{
Workspace_sptr ws = getProperty("Workspace");
ExperimentInfo_sptr experimentInfo = boost::dynamic_pointer_cast<ExperimentInfo>(ws);
if(experimentInfo)
/// Algorithm's version for identification. @see Algorithm::version
int ClearUB::version() const
{
return 1;
}
;

/// Algorithm's category for identification. @see Algorithm::category
const std::string ClearUB::category() const
{
clearSingleExperimentInfo(experimentInfo.get());
return "Crystal";
}
else

//----------------------------------------------------------------------------------------------
/// Sets documentation strings for this algorithm
void ClearUB::initDocs()
{
this->setWikiSummary("Clears the UB by removing the oriented lattice from the sample.");
this->setOptionalMessage(this->getWikiSummary());
}

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void ClearUB::init()
{
declareProperty(new WorkspaceProperty<Workspace>("Workspace", "", Direction::InOut),
"Workspace to clear the UB from.");
declareProperty(new PropertyWithValue<bool>("DryRun", false, Direction::Input),
"Dry run mode, will complete processing without error, and without removing any UB. Use in conjunction with DoesClear output property.");
declareProperty(new PropertyWithValue<bool>("DoesClear", "", Direction::Output),
"Indicates action performed, or predicted to perform if DryRun.");
}

/**
* Clear the Oriented Lattice from a single experiment info.
* @param experimentInfo : Experiment info to clear.
* @param dryRun : Flag to indicate that this is a dry run, and that no clearing should take place.
* @return true only if the UB was cleared.
*/
bool ClearUB::clearSingleExperimentInfo(ExperimentInfo * const experimentInfo,
const bool dryRun) const
{
MultipleExperimentInfos_sptr experimentInfos = boost::dynamic_pointer_cast<MultipleExperimentInfos>(ws);
if(!experimentInfos)
bool doesClear = false;
Sample& sampleObject = experimentInfo->mutableSample();
if (!sampleObject.hasOrientedLattice())
{
throw std::runtime_error("Input workspace is neither of type ExperimentInfo or MultipleExperimentInfo, cannot process.");
this->g_log.notice("Workspace has no oriented lattice to clear.");
}
const uint16_t nInfos = experimentInfos->getNumExperimentInfo();
for(uint16_t i = 0; i < nInfos; ++i)
else
{
ExperimentInfo_sptr info = experimentInfos->getExperimentInfo(i);
clearSingleExperimentInfo(info.get());
// Only actually clear the orientedlattice if this is NOT a dry run.
if (!dryRun)
{
sampleObject.clearOrientedLattice();
}
doesClear = true;
}
return doesClear;
}
}


//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void ClearUB::exec()
{
Workspace_sptr ws = getProperty("Workspace");
const bool dryRun = getProperty("DryRun");
bool doesClear = false;
ExperimentInfo_sptr experimentInfo = boost::dynamic_pointer_cast<ExperimentInfo>(ws);
if (experimentInfo)
{
doesClear = clearSingleExperimentInfo(experimentInfo.get(), dryRun);
}
else
{
MultipleExperimentInfos_sptr experimentInfos = boost::dynamic_pointer_cast<
MultipleExperimentInfos>(ws);
if (!experimentInfos)
{
if (!dryRun)
{
throw std::invalid_argument(
"Input workspace is neither of type ExperimentInfo or MultipleExperimentInfo, cannot process.");
}
}
else
{
const uint16_t nInfos = experimentInfos->getNumExperimentInfo();
for (uint16_t i = 0; i < nInfos; ++i)
{
ExperimentInfo_sptr info = experimentInfos->getExperimentInfo(i);
doesClear = clearSingleExperimentInfo(info.get(), dryRun) || doesClear;
}
}
}
this->setProperty("DoesClear", doesClear);
}

} // namespace Crystal
} // namespace Crystal
} // namespace Mantid

0 comments on commit 5fb5775

Please sign in to comment.