From 39c0446adb204224f3965dbeef7645d0aea54ffa Mon Sep 17 00:00:00 2001 From: Pete Peterson <petersonpf@ornl.gov> Date: Fri, 26 Jun 2015 10:20:51 -0400 Subject: [PATCH] Adding methods to get properties while consulting PropertyManager property --- .../inc/MantidAPI/DataProcessorAlgorithm.h | 7 ++- .../API/src/DataProcessorAlgorithm.cpp | 45 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/DataProcessorAlgorithm.h b/Code/Mantid/Framework/API/inc/MantidAPI/DataProcessorAlgorithm.h index 104b2c57773..2cc4b78212e 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/DataProcessorAlgorithm.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/DataProcessorAlgorithm.h @@ -43,6 +43,8 @@ class DLLExport DataProcessorAlgorithm : public Algorithm { public: DataProcessorAlgorithm(); virtual ~DataProcessorAlgorithm(); + virtual std::string getPropertyValue(const std::string &name) const; + virtual TypedValue getProperty(const std::string &name) const; protected: virtual boost::shared_ptr<Algorithm> createChildAlgorithm( @@ -53,6 +55,7 @@ protected: void setLoadAlgFileProp(const std::string &filePropName); void setAccumAlg(const std::string &alg); void setPropManagerPropName(const std::string &propName); + void mapPropertyName(const std::string &nameInProp, const std::string &nameInPropManager); ITableWorkspace_sptr determineChunk(); void loadChunk(); Workspace_sptr load(const std::string &inputData, @@ -60,7 +63,7 @@ protected: std::vector<std::string> splitInput(const std::string &input); void forwardProperties(); boost::shared_ptr<Kernel::PropertyManager> - getProcessProperties(const std::string &propertyManager=std::string()); + getProcessProperties(const std::string &propertyManager=std::string()) const; /// MPI option. If false, we will use one job event if MPI is available bool m_useMPI; Workspace_sptr assemble(const std::string &partialWSName, @@ -130,6 +133,8 @@ private: /// The name of the parameter that names the property manager. The default /// value is "ReductionProperties". std::string m_propertyManagerPropertyName; + /// Map property names to names in supplied properties manager + std::map<std::string, std::string> m_nameToPMName; }; } // namespace API diff --git a/Code/Mantid/Framework/API/src/DataProcessorAlgorithm.cpp b/Code/Mantid/Framework/API/src/DataProcessorAlgorithm.cpp index 01fa7c5742b..68f2dd1a47e 100644 --- a/Code/Mantid/Framework/API/src/DataProcessorAlgorithm.cpp +++ b/Code/Mantid/Framework/API/src/DataProcessorAlgorithm.cpp @@ -96,6 +96,49 @@ void DataProcessorAlgorithm::setPropManagerPropName(const std::string &propName) m_propertyManagerPropertyName = propName; } +void DataProcessorAlgorithm::mapPropertyName(const std::string &nameInProp, + const std::string &nameInPropManager) { + m_nameToPMName[nameInProp] = nameInPropManager; +} + +std::string DataProcessorAlgorithm::getPropertyValue(const std::string &name) const { + // explicitely specifying a property wins + if (!isDefault(name)) { + return Algorithm::getPropertyValue(name); + } + + // return it if it is in the held property manager + auto mapping = m_nameToPMName.find(name); + if (mapping != m_nameToPMName.end()) { + auto pm = this->getProcessProperties(); + if (pm->existsProperty(mapping->second)) { + return pm->getPropertyValue(mapping->second); + } + } + + // let the parent class version win + return Algorithm::getPropertyValue(name); +} + +PropertyManagerOwner::TypedValue DataProcessorAlgorithm::getProperty(const std::string &name) const { + // explicitely specifying a property wins + if (!isDefault(name)) { + return Algorithm::getProperty(name); + } + + // return it if it is in the held property manager + auto mapping = m_nameToPMName.find(name); + if (mapping != m_nameToPMName.end()) { + auto pm = this->getProcessProperties(); + if (pm->existsProperty(mapping->second)) { + return pm->getProperty(mapping->second); + } + } + + // let the parent class version win + return Algorithm::getProperty(name); +} + ITableWorkspace_sptr DataProcessorAlgorithm::determineChunk() { throw std::runtime_error( "DataProcessorAlgorithm::determineChunk is not implemented"); @@ -248,7 +291,7 @@ Workspace_sptr DataProcessorAlgorithm::load(const std::string &inputData, * @param propertyManager :: Name of the property manager to retrieve. */ boost::shared_ptr<PropertyManager> DataProcessorAlgorithm::getProcessProperties( - const std::string &propertyManager) { + const std::string &propertyManager) const { std::string propertyManagerName(propertyManager); if (propertyManager.empty() && (!m_propertyManagerPropertyName.empty())) { propertyManagerName = this->getPropertyValue(m_propertyManagerPropertyName); -- GitLab