Skip to content

Commit

Permalink
Refs #8494. Initial logic.
Browse files Browse the repository at this point in the history
No grouping, DTC or any other corrections applied yet.
  • Loading branch information
arturbekasov committed Dec 12, 2013
1 parent f8b4181 commit 3c9d43f
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 5 deletions.
Expand Up @@ -8,6 +8,8 @@ namespace Mantid
{
namespace WorkflowAlgorithms
{
using namespace Kernel;
using namespace API;

/** MuonLoad : loads Muon workspace ready for analysis.
Expand Down Expand Up @@ -46,7 +48,11 @@ namespace WorkflowAlgorithms
void init();
void exec();

/// Returns a workspace for the first period as specified using FirstPeriod property.
MatrixWorkspace_sptr getFirstPeriodWS(WorkspaceGroup_sptr ws);

/// Returns a workspace for the second period as specified using SecondPeriod property.
MatrixWorkspace_sptr getSecondPeriodWS(WorkspaceGroup_sptr ws);
};


Expand Down
113 changes: 108 additions & 5 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/MuonLoad.cpp
Expand Up @@ -65,7 +65,7 @@ namespace WorkflowAlgorithms
declareProperty(new FileProperty("Filename", "", FileProperty::Load, ".nxs"),
"The name of the Nexus file to load" );

declareProperty("FirstPeriod", EMPTY_INT(), "Group index of the first period workspace to use");
declareProperty("FirstPeriod", 0, "Group index of the first period workspace to use");
declareProperty("SecondPeriod", EMPTY_INT(), "Group index of the first period workspace to use");

std::vector<std::string> allowedOperations;
Expand All @@ -78,8 +78,9 @@ namespace WorkflowAlgorithms
declareProperty(new FileProperty("CustomDeadTimeFile", "", FileProperty::OptionalLoad, ".nxs"),
"Nexus file with custom dead time table. See LoadMuonNexus for format expected.");

declareProperty(new WorkspaceProperty<TableWorkspace>("DetectorGroupingTable","",Direction::Input),
"Table with detector grouping information. See LoadMuonNexus for format expected.");
declareProperty(new WorkspaceProperty<TableWorkspace>("DetectorGroupingTable","",Direction::Input,
PropertyMode::Optional), "Table with detector grouping information."
" See LoadMuonNexus for format expected.");

declareProperty("TimeZero", EMPTY_DBL(), "Value used for Time Zero correction.");
declareProperty(new ArrayProperty<double>("RebinParams"),
Expand All @@ -96,7 +97,7 @@ namespace WorkflowAlgorithms

declareProperty("PairFirstIndex", EMPTY_INT(), "Workspace index of the first pair group");
declareProperty("PairSecondIndex", EMPTY_INT(), "Workspace index of the second pair group");
declareProperty("PairAlpha", 1.0, "Alpha value of the pair");
declareProperty("Alpha", 1.0, "Alpha value of the pair");

declareProperty("GroupIndex", EMPTY_INT(), "Workspace index of the group");

Expand All @@ -110,10 +111,112 @@ namespace WorkflowAlgorithms
*/
void MuonLoad::exec()
{
// TODO Auto-generated execute stub
const std::string filename = getProperty("Filename");

// Load the file
IAlgorithm_sptr load = createChildAlgorithm("LoadMuonNexus");
load->setProperty("Filename", filename);
load->execute();

Workspace_sptr loadedWS = load->getProperty("OutputWorkspace");

MatrixWorkspace_sptr firstPeriodWS, secondPeriodWS;

// Deal with single-period workspace
if ( auto ws = boost::dynamic_pointer_cast<MatrixWorkspace>(loadedWS) )
{
if ( static_cast<int>( getProperty("FirstPeriod") ) != 0 )
throw std::invalid_argument("Single period data but first period is not 0.");

if ( static_cast<int>( getProperty("SecondPeriod") ) != EMPTY_INT() )
throw std::invalid_argument("Single period data but second period specified");

firstPeriodWS = ws;
}
// Deal with multi-period workspace
else if ( auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(loadedWS) )
{
firstPeriodWS = getFirstPeriodWS(group);
secondPeriodWS = getSecondPeriodWS(group);
}
// Unexpected workspace type
else
{
throw std::runtime_error("Loaded workspace is of invalid type");
}

IAlgorithm_sptr calcAssym = createChildAlgorithm("MuonCalculateAsymmetry");

// Set period workspaces
calcAssym->setProperty("FirstPeriodWorkspace", firstPeriodWS);
calcAssym->setProperty("SecondPeriodWorkspace", secondPeriodWS);

// Copy similar properties over
calcAssym->setProperty("PeriodOperation",
static_cast<std::string>( getProperty("PeriodOperation") ) );
calcAssym->setProperty("OutputType",
static_cast<std::string>( getProperty("OutputType") ) );
calcAssym->setProperty("PairFirstIndex",
static_cast<int>( getProperty("PairFirstIndex") ) );
calcAssym->setProperty("PairSecondIndex",
static_cast<int>( getProperty("PairSecondIndex") ) );
calcAssym->setProperty("Alpha",
static_cast<double>( getProperty("Alpha") ) );
calcAssym->setProperty("GroupIndex",
static_cast<int>( getProperty("GroupIndex") ) );

calcAssym->execute();

MatrixWorkspace_sptr outWS = calcAssym->getProperty("OutputWorkspace");
setProperty("OutputWorkspace", outWS);
}

/**
* Returns a workspace for the first period as specified using FirstPeriod property.
* @param group :: Loaded group of workspaces to use
* @return Workspace for the period
*/
MatrixWorkspace_sptr MuonLoad::getFirstPeriodWS(WorkspaceGroup_sptr group)
{
int firstPeriod = getProperty("FirstPeriod");

MatrixWorkspace_sptr resultWS;

if ( firstPeriod < 0 || firstPeriod >= static_cast<int>( group->size() ) )
throw std::invalid_argument("Workspace doesn't contain specified first period");

resultWS = boost::dynamic_pointer_cast<MatrixWorkspace>( group->getItem(firstPeriod) );

if ( ! resultWS )
throw std::invalid_argument("First period workspace is not a MatrixWorkspace");

return resultWS;
}

/**
* Returns a workspace for the second period as specified using SecondPeriod property.
* @param group :: Loaded group of workspaces to use
* @return Workspace for the period
*/
MatrixWorkspace_sptr MuonLoad::getSecondPeriodWS(WorkspaceGroup_sptr group)
{
int secondPeriod = getProperty("SecondPeriod");

MatrixWorkspace_sptr resultWS;

if ( secondPeriod != EMPTY_INT() )
{
if ( secondPeriod < 0 || secondPeriod >= static_cast<int>( group->size() ) )
throw std::invalid_argument("Workspace doesn't contain specified second period");

resultWS = boost::dynamic_pointer_cast<MatrixWorkspace>( group->getItem(secondPeriod) );

if ( ! resultWS )
throw std::invalid_argument("Second period workspace is not a MatrixWorkspace");
}

return resultWS;
}

} // namespace WorkflowAlgorithms
} // namespace Mantid

0 comments on commit 3c9d43f

Please sign in to comment.