Skip to content

Commit

Permalink
Refs #5035 - Add create info table option to C2E.
Browse files Browse the repository at this point in the history
* Enumerate different group workspace policies in algo.
* Extract another log property in LoadRawHelper.
* Add checkbox to C2E interface.
* Add of necessary parameter to TOSCA param file.
  • Loading branch information
PeterParker committed Apr 28, 2012
1 parent a72f79a commit e43a730
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 46 deletions.
136 changes: 108 additions & 28 deletions Code/Mantid/Framework/Algorithms/src/CreateLogPropertyTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This algorithm takes a list of workspaces and list of property, and produces a T
#include "boost/shared_ptr.hpp"

#include <vector>
#include <map>
#include <assert.h>

namespace Mantid
Expand All @@ -30,37 +31,41 @@ namespace Algorithms
using namespace Kernel;
using namespace API;

// Forward declarations.
namespace
{
std::vector<MatrixWorkspace_sptr> retrieveMatrixWsList(const std::vector<std::string> & wsNames, const std::string & useGroupChildrenPolicy);
enum GroupPolicy
{
ALL, FIRST, NONE
};

// Forward declarations.
std::vector<MatrixWorkspace_sptr> retrieveMatrixWsList(const std::vector<std::string> & wsNames, GroupPolicy groupPolicy);
GroupPolicy getGroupPolicyByName(const std::string & name);
std::set<std::string> getAllGroupPolicyNames();
}

/**
* Initialize the algorithm's properties.
* Initialise the algorithm's properties.
*/
void CreateLogPropertyTable::init()
{
// Input workspaces
declareProperty(new ArrayProperty<std::string>("InputWorkspaces", boost::make_shared<MandatoryValidator<std::vector<std::string>>>()),
"Name of the Input Workspaces from which to get log properties.");

// Output workspace
declareProperty(new WorkspaceProperty<ITableWorkspace> ("OutputWorkspace", "", Direction::Output),
"Name of the output ITableWorkspace.");

// Which log properties to use
declareProperty(new ArrayProperty<std::string>("LogPropertyNames", boost::make_shared<MandatoryValidator<std::vector<std::string>>>()),
"The names of the log properties to place in table.");

// How to handle workspace groups
const std::string groupOptionsArray[3] = {"All", "First", "None"};
std::vector<std::string> groupOptions;
groupOptions.assign(groupOptionsArray, groupOptionsArray + 3);

declareProperty("GroupChildren", "First", boost::make_shared<StringListValidator>(groupOptions),
"The policy by which to handle GroupWorkspaces. \"All\" will include all children, \"First\" will include "
const std::set<std::string> groupPolicies = getAllGroupPolicyNames();
declareProperty("GroupPolicy", "First", boost::make_shared<StringListValidator>(groupPolicies),
"The policy by which to handle GroupWorkspaces. \"All\" will include all children in the table, \"First\" will include "
"the first child, and \"None\" will not include any.");

// Output workspace
declareProperty(new WorkspaceProperty<ITableWorkspace> ("OutputWorkspace", "", Direction::Output),
"Name of the output ITableWorkspace.");
}

/**
Expand All @@ -70,12 +75,13 @@ namespace Algorithms
{
std::vector<std::string> wsNames = this->getProperty("InputWorkspaces");

// Retrieve a list of MatrixWorkspace pointers, using the given "GroupChildren" policy.
const std::string useGroupChildrenPolicy = this->getPropertyValue("GroupChildren");
std::vector<MatrixWorkspace_sptr> matrixWsList = retrieveMatrixWsList(wsNames, useGroupChildrenPolicy);
// Retrieve a list of MatrixWorkspace pointers, using the given "GroupPolicy".
const std::string groupPolicyName = this->getPropertyValue("GroupPolicy");
const GroupPolicy groupPolicy = getGroupPolicyByName(groupPolicyName);
const std::vector<MatrixWorkspace_sptr> matrixWsList = retrieveMatrixWsList(wsNames, groupPolicy);

// Get the names of the properties that will be stored.
std::vector<std::string> propNames = this->getProperty("LogPropertyNames");
const std::vector<std::string> propNames = this->getProperty("LogPropertyNames");

// Make sure all workspaces contain the properties.
for( auto matrixWs = matrixWsList.begin(); matrixWs != matrixWsList.end(); ++matrixWs )
Expand All @@ -99,6 +105,11 @@ namespace Algorithms
// One row for each workspace.
for( size_t i = 0; i < matrixWsList.size(); ++i )
outputTable->appendRow();

// Change all "plot designation" fields to "None". (This basically means that column headings
// appear as, for example, "inst_abrv" instead of "inst_abrv [X]" or similar.)
for( size_t i = 0; i < outputTable->columnCount(); ++i )
outputTable->getColumn(i)->setPlotType(0);

// Populate output table with the requested run properties.
for( size_t i = 0; i < outputTable->rowCount(); ++i )
Expand Down Expand Up @@ -132,17 +143,18 @@ namespace Algorithms
/**
* Given a list of workspace names, will retrieve pointers to the corresponding workspaces in the ADS.
* Only MatrixWorkspaces or the children of groups of MatrixWorkspaces are retrieved. GroupWorkspaces
* are handled via the "useGroupChildrenPolicy":
* are dealt with according to m_groupPolicy:
*
* "All" - Retrieve pointers to all the children of a group.
* "First" - Only retrieve a pointer to the first child of a group.
* "None" - No pointers are retreived.
*
* @param wsNames :: the list of workspaces to retrieve pointers to.
* @param useGroupChildrenPolicy :: the policy by which to deal with group workspaces.
* @param wsNames :: the list of workspaces to retrieve pointers to.
* @param groupPolicy :: the policy by which to deal with group workspaces.
*
* @return the retrieved MatrixWorkspace pointers
*/
std::vector<MatrixWorkspace_sptr> retrieveMatrixWsList(const std::vector<std::string> & wsNames, const std::string & useGroupChildrenPolicy)
std::vector<MatrixWorkspace_sptr> retrieveMatrixWsList(const std::vector<std::string> & wsNames, GroupPolicy groupPolicy)
{
std::vector<MatrixWorkspace_sptr> matrixWsList;

Expand All @@ -152,33 +164,43 @@ namespace Algorithms
WorkspaceGroup_sptr wsGroup = boost::shared_dynamic_cast<WorkspaceGroup>( AnalysisDataService::Instance().retrieve(*wsName) );
MatrixWorkspace_sptr matrixWs = boost::shared_dynamic_cast<MatrixWorkspace>( AnalysisDataService::Instance().retrieve(*wsName) );

// Handle any workspace groups.
if( wsGroup )
{
std::vector<std::string> childNames = wsGroup->getNames();
const std::vector<std::string> childNames = wsGroup->getNames();

// If there are no child workspaces in the group (is this possible?), just ignore it.
if( childNames.size() < 1 )
break;

// Retrieve pointers to all the child workspaces.
std::vector<MatrixWorkspace_sptr> childWsList;

for( auto childName = childNames.begin(); childName != childNames.end(); ++childName )
{
childWsList.push_back(AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(*childName));
}

if( useGroupChildrenPolicy == "All" )
// Deal with child workspaces according to policy.
switch( groupPolicy )
{
case ALL:
{
// Append all the children to the list.
for( auto childWs = childWsList.begin(); childWs != childWsList.end(); ++childWs)
matrixWsList.push_back(*childWs);

else if ( useGroupChildrenPolicy == "First" )
break;
}
case FIRST:
// Append only the first child to the list.
matrixWsList.push_back(childWsList[0]);
break;
case NONE:
// Add nothing to the list.
break;
default:
// We should never reach here.
assert(false);
}
}
// Append any MatrixWorkspaces.
else if( matrixWs )
{
matrixWsList.push_back(matrixWs);
Expand All @@ -187,6 +209,64 @@ namespace Algorithms

return matrixWsList;
}

/**
* Returns a constant reference to a static map, which maps group policy
* names to actual GroupPolicy enum members.
*
* @returns map of group policy names to GroupPolicy enum members.
*/
const std::map<std::string, GroupPolicy> & getGroupPolicyMap()
{
static std::map<std::string, GroupPolicy> map;

// Populate the map if empty.
if( map.empty() )
{
map.insert(std::make_pair("All", ALL));
map.insert(std::make_pair("First", FIRST));
map.insert(std::make_pair("None", NONE));
}

return map;
}

/**
* Given a group policy name, will return the corresponding GroupPolicy enum member.
*
* @param name :: name of group policy.
*
* @returns the corresponding GroupPolicy enum member.
*/
GroupPolicy getGroupPolicyByName(const std::string & name)
{
const std::map<std::string, GroupPolicy> & map = getGroupPolicyMap();

// If we can find a policy with the given name, return it.
auto policy = map.find(name);
if( policy != map.end() )
return policy->second;

// Else return ALL as default. Assert since we should never reach here.
assert(false);
return ALL;
}

/**
* Returns a set of all group policy names.
*
* @returns a set of all group policy names.
*/
std::set<std::string> getAllGroupPolicyNames()
{
const std::map<std::string, GroupPolicy> & map = getGroupPolicyMap();
std::set<std::string> groupPolicyNames;

for( auto policy = map.begin(); policy != map.end(); ++policy )
groupPolicyNames.insert(policy->first);

return groupPolicyNames;
}
}

} // namespace Algorithms
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ namespace Mantid

runDetails.addProperty("user_name", std::string(localISISRaw->hdr.hd_user, 20));
runDetails.addProperty("inst_abrv", std::string(localISISRaw->hdr.inst_abrv, 3));
runDetails.addProperty("hd_dur", std::string(localISISRaw->hdr.hd_dur, 8));

// Data details on run not the workspace
runDetails.addProperty("nspectra", static_cast<int>(localISISRaw->t_nsp1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1579,30 +1579,44 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
<widget class="QLabel" name="ind_lbPlotOutput">
<widget class="QCheckBox" name="ckCreateInfoTable">
<property name="text">
<string>Plot Output:</string>
<string>Create Info Table</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="ind_cbPlotOutput">
<layout class="QHBoxLayout" name="horizontalLayout_23">
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Spectra</string>
</property>
<widget class="QLabel" name="ind_lbPlotOutput">
<property name="text">
<string>Plot Output:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<property name="text">
<string>Contour</string>
</property>
<widget class="QComboBox" name="ind_cbPlotOutput">
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Spectra</string>
</property>
</item>
<item>
<property name="text">
<string>Contour</string>
</property>
</item>
</widget>
</item>
</widget>
</layout>
</item>
</layout>
</item>
Expand All @@ -1611,7 +1625,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QCheckBox" name="ckRenameWorkspace">
<property name="text">
<string>Rename workspace</string>
<string>Rename Workspace</string>
</property>
<property name="checked">
<bool>true</bool>
Expand Down
8 changes: 6 additions & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,12 @@ void Indirect::runConvertToEnergy()

if( m_uiForm.ckCm1Units->isChecked() )
{
pyInput +=
"reducer.set_save_to_cm_1(True)\n";
pyInput += "reducer.set_save_to_cm_1(True)\n";
}

if ( m_uiForm.ckCreateInfoTable->isChecked() )
{
pyInput += "reducer.create_info_table()\n";
}

pyInput += "reducer.set_save_formats([" + savePyCode() + "])\n";
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/instrument/TOSCA_Parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
</parameter>

<!-- Reduction workflow parameters under this line -->
<parameter name="Workflow.InfoTable" type="string">
<value val="inst_abrv, run_number, user_name, run_title, hd_dur" />
</parameter>
<parameter name="Workflow.MonitorArea" >
<value val="5.391011e-5" />
</parameter>
Expand Down
28 changes: 28 additions & 0 deletions Code/Mantid/scripts/Inelastic/msg_reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os.path

from mantidsimple import *
from mantid.kernel import config
import MantidFramework
import reduction.reducer as reducer
import inelastic_indirect_reduction_steps as steps

Expand All @@ -23,6 +25,7 @@ class MSGReducer(reducer.Reducer):
_rebin_string = None
_fold_multiple_frames = True
_save_formats = []
_info_table_props = None

def __init__(self):
super(MSGReducer, self).__init__()
Expand All @@ -42,10 +45,35 @@ def pre_process(self):
self._multiple_frames = loadData.is_multiple_frames()
self._masking_detectors = loadData.get_mask_list()

if( self._info_table_props is not None ):
wsNames = loadData.get_ws_list().keys()
wsNameList = ", ".join(wsNames)
propsList = ", ".join(self._info_table_props)
CreateLogPropertyTable(
OutputWorkspace="RunInfo",
InputWorkspaces=wsNameList,
LogPropertyNames=propsList,
GroupPolicy="First")

if ( self._sum ):
self._data_files = loadData.get_ws_list()

self._setup_steps()

def create_info_table(self):
"""Sets the names of properties retrieve from the log when creating
an info table.
"""

inst_name = config.getInstrument().name()
inst = MantidFramework.mtd["__empty_" + inst_name].getInstrument()
props = inst.getStringParameter('Workflow.InfoTable')

if props:
self._info_table_props = props
else:
mtd.sendErrorMessage("Instrument does not have Workflow.InfoTable " +
"defined in its parameter file. Unable to create info table for runs.")

def set_detector_range(self, start, end):
"""Sets the start and end detector points for the reduction process.
Expand Down

0 comments on commit e43a730

Please sign in to comment.