20#include "boost/shared_ptr.hpp"
31using namespace Kernel;
35enum GroupPolicy { ALL, FIRST, NONE };
38std::vector<MatrixWorkspace_sptr> retrieveMatrixWsList(
const std::vector<std::string> &wsNames,
39 GroupPolicy groupPolicy);
40GroupPolicy getGroupPolicyByName(
const std::string &name);
41std::set<std::string> getAllGroupPolicyNames();
43std::set<std::string> getAllStatisticTypeNames();
53 "Name of the Input Workspaces from which to get log properties.");
57 "Name of the output ITableWorkspace.");
62 "The names of the log properties to place in table.");
65 const std::set<std::string> statisticNames = getAllStatisticTypeNames();
66 declareProperty(
"TimeSeriesStatistic",
"Mean", std::make_shared<StringListValidator>(statisticNames),
67 "The statistic to use when adding a time series log.");
70 const std::set<std::string> groupPolicies = getAllGroupPolicyNames();
71 declareProperty(
"GroupPolicy",
"First", std::make_shared<StringListValidator>(groupPolicies),
72 "The policy by which to handle GroupWorkspaces. \"All\" "
73 "will include all children in the table, \"First\" will "
75 "the first child, and \"None\" will not include any.");
82 std::vector<std::string> wsNames = this->
getProperty(
"InputWorkspaces");
86 const GroupPolicy groupPolicy = getGroupPolicyByName(groupPolicyName);
87 const std::vector<MatrixWorkspace_sptr> matrixWsList = retrieveMatrixWsList(wsNames, groupPolicy);
90 const std::vector<std::string> propNames = this->
getProperty(
"LogPropertyNames");
93 for (
const auto &matrixWs : matrixWsList) {
94 const Run &run = matrixWs->run();
95 const std::string wsName = matrixWs->getName();
98 auto it = std::find_if(propNames.cbegin(), propNames.cend(),
99 [&run](
const auto &propName) { return !run.hasProperty(propName); });
100 if (it != propNames.cend())
101 throw std::runtime_error(
"\"" + wsName +
"\" does not have a run property of \"" + (*it) +
"\".");
105 auto outputTable = std::make_shared<DataObjects::TableWorkspace>();
107 for (
const auto &propName : propNames)
108 outputTable->addColumn(
"str", propName);
110 for (
size_t i = 0; i < matrixWsList.size(); ++i)
111 outputTable->appendRow();
115 for (
size_t i = 0; i < outputTable->columnCount(); ++i)
116 outputTable->getColumn(i)->setPlotType(i == 0 ? 1 : 2);
118 const std::string timeSeriesStatName = this->
getPropertyValue(
"TimeSeriesStatistic");
121 for (
size_t i = 0; i < outputTable->rowCount(); ++i) {
122 TableRow row = outputTable->getRow(i);
125 for (
const auto &propName : propNames) {
126 Property *prop = matrixWs->run().getProperty(propName);
127 std::stringstream propValue;
129 if (prop->
type().find(
"TimeValue") != std::string::npos) {
130 propValue << matrixWs->run().getLogAsSingleValue(propName, timeSeriesStat);
132 propValue << prop->
value();
135 row << propValue.str();
159std::vector<MatrixWorkspace_sptr> retrieveMatrixWsList(
const std::vector<std::string> &wsNames,
160 GroupPolicy groupPolicy) {
161 std::vector<MatrixWorkspace_sptr> matrixWsList;
165 for (
const auto &wsName : wsNames) {
167 WorkspaceGroup_sptr wsGroup = std::dynamic_pointer_cast<WorkspaceGroup>(ADS.retrieve(wsName));
168 MatrixWorkspace_sptr matrixWs = std::dynamic_pointer_cast<MatrixWorkspace>(ADS.retrieve(wsName));
171 const std::vector<std::string> childNames = wsGroup->getNames();
175 if (childNames.empty())
179 std::vector<MatrixWorkspace_sptr> childWsList;
180 childWsList.reserve(childNames.size());
182 std::transform(childNames.begin(), childNames.end(), std::back_inserter(childWsList),
183 [&ADS](
const auto &childName) { return ADS.retrieveWS<MatrixWorkspace>(childName); });
186 switch (groupPolicy) {
189 std::move(childWsList.cbegin(), childWsList.cend(), std::back_inserter(matrixWsList));
194 matrixWsList.emplace_back(childWsList[0]);
203 }
else if (matrixWs) {
204 matrixWsList.emplace_back(matrixWs);
217const std::map<std::string, GroupPolicy> &getGroupPolicyMap() {
218 static std::map<std::string, GroupPolicy> map;
222 map.emplace(
"All", ALL);
223 map.emplace(
"First", FIRST);
224 map.emplace(
"None", NONE);
238GroupPolicy getGroupPolicyByName(
const std::string &name) {
239 const std::map<std::string, GroupPolicy> &map = getGroupPolicyMap();
242 auto policy = map.find(name);
243 if (policy != map.end())
244 return policy->second;
256std::set<std::string> getAllGroupPolicyNames() {
257 const std::map<std::string, GroupPolicy> &map = getGroupPolicyMap();
258 std::set<std::string> groupPolicyNames;
260 for (
const auto &policy : map)
261 groupPolicyNames.insert(policy.first);
263 return groupPolicyNames;
272const std::map<std::string, Math::StatisticType> &getStatisticTypeMap() {
273 static std::map<std::string, Math::StatisticType> map;
277 map.emplace(
"FirstValue", Math::StatisticType::FirstValue);
278 map.emplace(
"LastValue", Math::StatisticType::LastValue);
279 map.emplace(
"Minimum", Math::StatisticType::Minimum);
280 map.emplace(
"Maximum", Math::StatisticType::Maximum);
281 map.emplace(
"Mean", Math::StatisticType::Mean);
282 map.emplace(
"Median", Math::StatisticType::Median);
295 const std::map<std::string, Math::StatisticType> &map = getStatisticTypeMap();
298 auto policy = map.find(name);
299 if (policy != map.end())
300 return policy->second;
303 return Math::StatisticType::Mean;
311std::set<std::string> getAllStatisticTypeNames() {
312 const std::map<std::string, Math::StatisticType> &map = getStatisticTypeMap();
313 std::set<std::string> statisticTypeNames;
315 for (
const auto &policy : map)
316 statisticTypeNames.insert(policy.first);
318 return statisticTypeNames;
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
This class stores information regarding an experimental run as a series of log entries.
TableRow represents a row in a TableWorkspace.
A property class for workspaces.
void init() override
Initialise the properties.
void exec() override
Run the algorithm.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
Validator to check that a property is not left empty.
Base class for properties.
const std::string type() const
Returns the type of the property as a string.
virtual std::string value() const =0
Returns the value of the property as a string.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
StatisticType
Maps a "statistic" to a number.
@ Output
An output workspace.