Mantid
|
SampleLogsBehaviour : This class holds information relating to the behaviour of the sample log merging. More...
#include <SampleLogsBehaviour.h>
Classes | |
struct | ParameterName |
struct | SampleLogBehaviour |
struct | SampleLogNames |
Public Types | |
enum class | MergeLogType { Sum , TimeSeries , List , Warn , Fail } |
Public Member Functions | |
void | mergeSampleLogs (const API::MatrixWorkspace_sptr &addeeWS, const API::MatrixWorkspace_sptr &outWS) |
Create and update sample logs according to instrument parameters. More... | |
void | readdSampleLogToWorkspace (const API::MatrixWorkspace_sptr &addeeWS) |
When doing a time series merge we need to remove, then add back the sample log in the addee workspace to supress a warning about it not being a TimeSeriesProperty. More... | |
void | removeSampleLogsFromWorkspace (const API::MatrixWorkspace_sptr &addeeWS) |
When doing a time series merge we need to remove, then add back the sample log in the addee workspace to supress a warning about it not being a TimeSeriesProperty. More... | |
void | resetSampleLogs (const API::MatrixWorkspace_sptr &ws) |
Resets the sample logs in the workspace to the values in the map. More... | |
SampleLogsBehaviour (const API::MatrixWorkspace_sptr &ws, Kernel::Logger &logger, const SampleLogNames &logEntries={}, ParameterName parName={}) | |
Create and initialise an object that is responsbile for keeping track of the merge types, and performing the merge or warning/error for sample logs when calling MergeRuns. More... | |
void | setUpdatedSampleLogs (const API::MatrixWorkspace_sptr &outWS) |
Set the values in the map to be the same as those in the output workspace. More... | |
Public Attributes | |
struct Mantid::Algorithms::SampleLogsBehaviour::ParameterName | parameterNames |
Static Public Attributes | |
static const std::string | FAIL_DOC |
static const std::string | FAIL_PROP = "SampleLogsFail" |
static const std::string | FAIL_TOL_DOC |
static const std::string | FAIL_TOL_PROP = "SampleLogsFailTolerances" |
static const std::string | LIST_DOC |
static const std::string | LIST_PROP = "SampleLogsList" |
static const std::string | SUM_DOC |
static const std::string | SUM_PROP = "SampleLogsSum" |
static const std::string | TIME_SERIES_DOC |
static const std::string | TIME_SERIES_PROP = "SampleLogsTimeSeries" |
static const std::string | WARN_DOC |
static const std::string | WARN_PROP = "SampleLogsWarn" |
static const std::string | WARN_TOL_DOC |
static const std::string | WARN_TOL_PROP = "SampleLogsWarnTolerances" |
Private Types | |
using | SampleLogsKey = std::pair< std::string, MergeLogType > |
using | SampleLogsMap = std::map< SampleLogsKey, SampleLogBehaviour > |
Private Member Functions | |
std::shared_ptr< Kernel::Property > | addPropertyForList (const std::string &item, const std::string &value, API::MatrixWorkspace &ws) |
Adds a property to the workspace provided for a List merge type. More... | |
std::shared_ptr< Kernel::Property > | addPropertyForTimeSeries (const std::string &item, const double value, API::MatrixWorkspace &ws) |
Adds a property to the workspace provided for a TimeSeries merge type. More... | |
void | checkErrorProperty (const API::MatrixWorkspace &addeeWS, Kernel::Property *addeeWSProperty, const SampleLogBehaviour &behaviour, const double addeeWSNumber, const double outWSNumber, const std::string &name) |
Performs the check to see if an error should be generated because logs are different. More... | |
void | checkWarnProperty (const API::MatrixWorkspace &addeeWS, Kernel::Property *addeeWSProperty, const SampleLogBehaviour &behaviour, const double addeeWSNumber, const double outWSNumber, const std::string &name) |
Performs the check to see if a warning should be generated because logs are different. More... | |
void | createSampleLogsMapsFromInstrumentParams (SampleLogsMap &instrumentMap, API::MatrixWorkspace &ws) |
Extracts all of the settings from the instrument parameters, and adds them to a map of sample log behaviours. More... | |
std::vector< double > | createTolerancesVector (const size_t numberNames, const std::vector< std::string > &tolerances) |
Creates a vector of tolerances with the same size as the number of sample logs for the merge type. More... | |
bool | isWithinTolerance (const SampleLogBehaviour &behaviour, const double addeeWSNumber, const double outWSNumber) |
Check if a sample log value in the addee workspace is numeric and within tolerances. More... | |
bool | setNumericValue (const std::string &item, const API::MatrixWorkspace &ws, double &value) |
Tries to set the numeric value of a property. More... | |
void | setSampleMap (SampleLogsMap &map, const MergeLogType &, const std::string ¶ms, API::MatrixWorkspace &ws, const std::string ¶msTolerances="", bool skipIfInPrimaryMap=false) |
This method updates the map with the sample log behaviour, and adds the new property to the workspace if required. More... | |
bool | stringPropertiesMatch (const SampleLogBehaviour &behaviour, const Kernel::Property *addeeWSProperty) |
Check if a sample log value in the addee workspace matches one in the first workspace. More... | |
void | updateListProperty (const API::MatrixWorkspace &addeeWS, API::MatrixWorkspace &outWS, const std::string &name) |
Perform the update for a list property, appending a new value to the existing string. More... | |
void | updateSumProperty (double addeeWSNumber, double outWSNumber, API::MatrixWorkspace &outWS, const std::string &name) |
Perform the update for a sum property, adding a new value to the existing one. More... | |
void | updateTimeSeriesProperty (const API::MatrixWorkspace &addeeWS, const API::MatrixWorkspace &outWS, const std::string &name) |
Perform the update for a time series property, adding a new value to the existing time series property. More... | |
Private Attributes | |
std::vector< std::shared_ptr< Kernel::Property > > | m_addeeLogMap |
Kernel::Logger & | m_logger |
SampleLogsMap | m_logMap |
SampleLogsBehaviour : This class holds information relating to the behaviour of the sample log merging.
It holds a map of all the sample log parameters to merge, how to merge them, and the associated tolerances. Algorithms which already define paramter names for the instrument parameter file are ConjoinXRuns and MergeRuns. Please use different names for new algorithms.
Definition at line 24 of file SampleLogsBehaviour.h.
|
private |
Definition at line 85 of file SampleLogsBehaviour.h.
|
private |
Definition at line 86 of file SampleLogsBehaviour.h.
|
strong |
Enumerator | |
---|---|
Sum | |
TimeSeries | |
List | |
Warn | |
Fail |
Definition at line 26 of file SampleLogsBehaviour.h.
Mantid::Algorithms::SampleLogsBehaviour::SampleLogsBehaviour | ( | const API::MatrixWorkspace_sptr & | ws, |
Kernel::Logger & | logger, | ||
const SampleLogNames & | logEntries = {} , |
||
ParameterName | parName = {} |
||
) |
Create and initialise an object that is responsbile for keeping track of the merge types, and performing the merge or warning/error for sample logs when calling MergeRuns.
ws | the base workspace that the other workspaces are merged into |
logger | the logger from the parent algorithm |
logEntries | the sample log names to merge given by the user which override names given by IPF parameters |
parName | the parameter names which specify the sample log sames to merge given be the IPF |
Definition at line 80 of file SampleLogsBehaviour.cpp.
References createSampleLogsMapsFromInstrumentParams(), Fail, List, m_logMap, Mantid::Algorithms::SampleLogsBehaviour::SampleLogNames::sampleLogsFail, Mantid::Algorithms::SampleLogsBehaviour::SampleLogNames::sampleLogsFailTolerances, Mantid::Algorithms::SampleLogsBehaviour::SampleLogNames::sampleLogsList, Mantid::Algorithms::SampleLogsBehaviour::SampleLogNames::sampleLogsSum, Mantid::Algorithms::SampleLogsBehaviour::SampleLogNames::sampleLogsTimeSeries, Mantid::Algorithms::SampleLogsBehaviour::SampleLogNames::sampleLogsWarn, Mantid::Algorithms::SampleLogsBehaviour::SampleLogNames::sampleLogsWarnTolerances, setSampleMap(), Sum, TimeSeries, and Warn.
|
private |
Adds a property to the workspace provided for a List merge type.
item | the name of the sample log to merge as a list |
value | the string value of the sample log in the first workspace |
ws | the first workspace in the merge |
Definition at line 327 of file SampleLogsBehaviour.cpp.
References Mantid::API::LogManager::addProperty(), Mantid::Kernel::Property::clone(), Mantid::API::ExperimentInfo::getLog(), Mantid::API::ExperimentInfo::mutableRun(), Mantid::Kernel::Property::setUnits(), Mantid::Kernel::Property::units(), and value.
Referenced by setSampleMap().
|
private |
Adds a property to the workspace provided for a TimeSeries merge type.
item | the name of the sample log to merge as a time series |
value | the numeric value of the sample log in the first workspace |
ws | the first workspace in the merge |
Definition at line 296 of file SampleLogsBehaviour.cpp.
References Mantid::API::LogManager::addProperty(), Mantid::Kernel::Property::clone(), Mantid::API::ExperimentInfo::getLog(), Mantid::API::LogManager::getTimeSeriesProperty(), Mantid::API::ExperimentInfo::mutableRun(), Mantid::API::ExperimentInfo::run(), Mantid::Kernel::Property::setUnits(), Mantid::API::LogManager::startTime(), Mantid::Kernel::Property::units(), and value.
Referenced by setSampleMap().
|
private |
Performs the check to see if an error should be generated because logs are different.
Performs a numeric comparison if a tolerance is set and the log is a number, else performs a string comparison.
addeeWS | the workspace being merged |
addeeWSProperty | the property value of the workspace being merged |
behaviour | the merge behaviour struct, containing information about the merge |
addeeWSNumericValue | a double for the addeeWS value (0 if it is not numeric) |
outWSNumericValue | a double for the outWS value (0 if it is not numeric) |
name | the name of the sample log to check |
Definition at line 510 of file SampleLogsBehaviour.cpp.
References Mantid::API::Workspace::getName(), isWithinTolerance(), Mantid::Algorithms::SampleLogsBehaviour::SampleLogBehaviour::property, stringPropertiesMatch(), and Mantid::Kernel::Property::value().
Referenced by mergeSampleLogs().
|
private |
Performs the check to see if a warning should be generated because logs are different.
Performs a numeric comparison if a tolerance is set and the log is a number, else performs a string comparison.
addeeWS | the workspace being merged |
addeeWSProperty | the property value of the workspace being merged |
behaviour | the merge behaviour struct, containing information about the merge |
addeeWSNumericValue | a double for the addeeWS value (0 if it is not numeric) |
outWSNumericValue | a double for the outWS value (0 if it is not numeric) |
name | the name of the sample log to check |
Definition at line 484 of file SampleLogsBehaviour.cpp.
References Mantid::API::Workspace::getName(), isWithinTolerance(), m_logger, Mantid::Algorithms::SampleLogsBehaviour::SampleLogBehaviour::property, stringPropertiesMatch(), Mantid::Kernel::Property::value(), and Mantid::Kernel::Logger::warning().
Referenced by mergeSampleLogs().
|
private |
Extracts all of the settings from the instrument parameters, and adds them to a map of sample log behaviours.
map | the map to add the merge behaviours to |
ws | the workspace with the instrument and initial map |
Definition at line 104 of file SampleLogsBehaviour.cpp.
References Fail, Mantid::Algorithms::SampleLogsBehaviour::ParameterName::FAIL_MERGE, Mantid::Algorithms::SampleLogsBehaviour::ParameterName::FAIL_MERGE_TOLERANCES, Mantid::API::ExperimentInfo::getInstrument(), List, Mantid::Algorithms::SampleLogsBehaviour::ParameterName::LIST_MERGE, parameterNames, setSampleMap(), Sum, Mantid::Algorithms::SampleLogsBehaviour::ParameterName::SUM_MERGE, Mantid::Algorithms::SampleLogsBehaviour::ParameterName::TIME_SERIES_MERGE, TimeSeries, Warn, Mantid::Algorithms::SampleLogsBehaviour::ParameterName::WARN_MERGE, and Mantid::Algorithms::SampleLogsBehaviour::ParameterName::WARN_MERGE_TOLERANCES.
Referenced by SampleLogsBehaviour().
|
private |
Creates a vector of tolerances with the same size as the number of sample logs for the merge type.
If the number of names and tolerances is the same the vector is filled with the tolerances for each name. If no tolerances were specified all tolerances are set to -1, and if one tolerance is given all tolerances are set to that value.
numberNames | the number of sample log names |
tolerances | a vector containing strings with the tolerances |
Definition at line 237 of file SampleLogsBehaviour.cpp.
References std::to_string(), and value.
Referenced by setSampleMap().
|
private |
Check if a sample log value in the addee workspace is numeric and within tolerances.
behaviour | the SampleLogBehaviour item to check |
addeeWSNumericValue | the value in the workspace being added |
outWSNumericValue | the value in the first workspace |
Definition at line 531 of file SampleLogsBehaviour.cpp.
References Mantid::Algorithms::SampleLogsBehaviour::SampleLogBehaviour::isNumeric, and Mantid::Algorithms::SampleLogsBehaviour::SampleLogBehaviour::tolerance.
Referenced by checkErrorProperty(), and checkWarnProperty().
void Mantid::Algorithms::SampleLogsBehaviour::mergeSampleLogs | ( | const API::MatrixWorkspace_sptr & | addeeWS, |
const API::MatrixWorkspace_sptr & | outWS | ||
) |
Create and update sample logs according to instrument parameters.
Updates the sample logs according to the requested behaviour.
addeeWS | the workspace being merged |
outWS | the workspace the others are merged into |
Definition at line 370 of file SampleLogsBehaviour.cpp.
References checkErrorProperty(), checkWarnProperty(), Fail, List, m_logMap, Sum, TimeSeries, Mantid::Kernel::Property::units(), updateListProperty(), updateSumProperty(), updateTimeSeriesProperty(), and Warn.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), and Mantid::Algorithms::MergeRuns::execHistogram().
void Mantid::Algorithms::SampleLogsBehaviour::readdSampleLogToWorkspace | ( | const API::MatrixWorkspace_sptr & | addeeWS | ) |
When doing a time series merge we need to remove, then add back the sample log in the addee workspace to supress a warning about it not being a TimeSeriesProperty.
Here we add back the original property, as the original workspace should remain unchanged.
addeeWS | the workspace being merged |
Definition at line 592 of file SampleLogsBehaviour.cpp.
References m_addeeLogMap.
Referenced by Mantid::Algorithms::MergeRuns::execHistogram().
void Mantid::Algorithms::SampleLogsBehaviour::removeSampleLogsFromWorkspace | ( | const API::MatrixWorkspace_sptr & | addeeWS | ) |
When doing a time series merge we need to remove, then add back the sample log in the addee workspace to supress a warning about it not being a TimeSeriesProperty.
Here we remove the original property.
addeeWS | the workspace being merged |
Definition at line 577 of file SampleLogsBehaviour.cpp.
References m_addeeLogMap.
Referenced by Mantid::Algorithms::MergeRuns::execHistogram().
void Mantid::Algorithms::SampleLogsBehaviour::resetSampleLogs | ( | const API::MatrixWorkspace_sptr & | ws | ) |
Resets the sample logs in the workspace to the values in the map.
ws | the merged workspace to reset the sample logs for |
Definition at line 605 of file SampleLogsBehaviour.cpp.
References List, m_logMap, Sum, and TimeSeries.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), and Mantid::Algorithms::MergeRuns::execHistogram().
|
private |
Tries to set the numeric value of a property.
item | the name of the sample log |
ws | the first workspace in the merge |
value | the value of the sample log (if it could be set) |
Definition at line 351 of file SampleLogsBehaviour.cpp.
References Mantid::API::ExperimentInfo::getLogAsSingleValue(), and value.
Referenced by setSampleMap().
|
private |
This method updates the map with the sample log behaviour, and adds the new property to the workspace if required.
if skipIfInPrimaryMap is true sample logs in the primary map are ignored. Throws std::invalid_argument if a sample log is not found.
map | the map to add the merge behaviours to |
mergeType | an enum for the type of merge to perform |
params | a string containing a comma separated list of the sample logs to merge for this behaviour |
ws | the base workspace that the other workspaces are merged into |
paramsTolerances | a string containing a comma spearated list of the tolerances for this merge behaviour (optional) |
skipIfInPrimaryMap | whether to skip if in the member variable map (optional, default false) |
Definition at line 140 of file SampleLogsBehaviour.cpp.
References addPropertyForList(), addPropertyForTimeSeries(), Mantid::Kernel::StringTokenizer::asVector(), Mantid::Kernel::StringTokenizer::begin(), Mantid::Kernel::Property::clone(), createTolerancesVector(), Mantid::Kernel::StringTokenizer::end(), Mantid::Kernel::Logger::error(), Mantid::API::ExperimentInfo::getLog(), List, m_logger, m_logMap, setNumericValue(), Sum, TimeSeries, Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY, Mantid::Kernel::StringTokenizer::TOK_TRIM, tolerance, and value.
Referenced by createSampleLogsMapsFromInstrumentParams(), and SampleLogsBehaviour().
void Mantid::Algorithms::SampleLogsBehaviour::setUpdatedSampleLogs | ( | const API::MatrixWorkspace_sptr & | outWS | ) |
Set the values in the map to be the same as those in the output workspace.
outWS | the merged workspace |
Definition at line 557 of file SampleLogsBehaviour.cpp.
References Mantid::Kernel::Property::clone(), Fail, m_logMap, and Warn.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), and Mantid::Algorithms::MergeRuns::execHistogram().
|
private |
Check if a sample log value in the addee workspace matches one in the first workspace.
behaviour | the SampleLogBehaviour item to check |
addeeWSProperty | a pointer to the property in the workspace being added |
Definition at line 548 of file SampleLogsBehaviour.cpp.
References Mantid::Algorithms::SampleLogsBehaviour::SampleLogBehaviour::property, and Mantid::Kernel::Property::value().
Referenced by checkErrorProperty(), and checkWarnProperty().
|
private |
Perform the update for a list property, appending a new value to the existing string.
If the list log entry is in the addeeWS the list log entry is merged instead.
addeeWS | the workspace being merged |
outWS | the workspace the others are merged into |
name | the name of the property |
Definition at line 462 of file SampleLogsBehaviour.cpp.
References Mantid::API::LogManager::addProperty(), Mantid::API::ExperimentInfo::getLog(), Mantid::API::LogManager::getProperty(), Mantid::API::ExperimentInfo::mutableRun(), Mantid::API::ExperimentInfo::run(), and Mantid::Kernel::Property::value().
Referenced by mergeSampleLogs().
|
private |
Perform the update for a sum property, adding a new value to the existing one.
Skipped if the time series log entry is in the addeeWS.
addeeWSNumericValue | the sample log value from the workspace being merged |
outWSNumericValue | the sample log value for the merged workspace |
outWS | the workspace the others are merged into |
name | the name of the property |
Definition at line 423 of file SampleLogsBehaviour.cpp.
References Mantid::API::LogManager::addProperty(), and Mantid::API::ExperimentInfo::mutableRun().
Referenced by mergeSampleLogs().
|
private |
Perform the update for a time series property, adding a new value to the existing time series property.
addeeWS | the workspace being merged |
outWS | the workspace the others are merged into |
name | the name of the property |
Definition at line 436 of file SampleLogsBehaviour.cpp.
References Mantid::Kernel::Property::clone(), Mantid::API::LogManager::getLogAsSingleValue(), Mantid::API::LogManager::getProperty(), Mantid::API::LogManager::getTimeSeriesProperty(), m_addeeLogMap, Mantid::API::ExperimentInfo::run(), Mantid::API::LogManager::startTime(), and value.
Referenced by mergeSampleLogs().
|
static |
Definition at line 49 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 48 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), Mantid::Algorithms::MergeRuns::execHistogram(), Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 51 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 50 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), Mantid::Algorithms::MergeRuns::execHistogram(), Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 43 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 42 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), Mantid::Algorithms::MergeRuns::execHistogram(), Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
private |
Definition at line 88 of file SampleLogsBehaviour.h.
Referenced by readdSampleLogToWorkspace(), removeSampleLogsFromWorkspace(), and updateTimeSeriesProperty().
|
private |
Definition at line 83 of file SampleLogsBehaviour.h.
Referenced by checkWarnProperty(), and setSampleMap().
|
private |
Definition at line 87 of file SampleLogsBehaviour.h.
Referenced by mergeSampleLogs(), resetSampleLogs(), SampleLogsBehaviour(), setSampleMap(), and setUpdatedSampleLogs().
struct Mantid::Algorithms::SampleLogsBehaviour::ParameterName Mantid::Algorithms::SampleLogsBehaviour::parameterNames |
Referenced by createSampleLogsMapsFromInstrumentParams().
|
static |
Definition at line 53 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 52 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), Mantid::Algorithms::MergeRuns::execHistogram(), Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 41 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 40 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), Mantid::Algorithms::MergeRuns::execHistogram(), Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 45 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 44 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), Mantid::Algorithms::MergeRuns::execHistogram(), Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 47 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().
|
static |
Definition at line 46 of file SampleLogsBehaviour.h.
Referenced by Mantid::Algorithms::ConjoinXRuns::exec(), Mantid::Algorithms::MergeRuns::execHistogram(), Mantid::Algorithms::ConjoinXRuns::init(), and Mantid::Algorithms::MergeRuns::init().