diff --git a/Framework/API/src/FrameworkManager.cpp b/Framework/API/src/FrameworkManager.cpp index 26848f7a02f11dd2d857687cd9aa7b1fe5c5b0f9..588496fd1d567c84bf03d0952920a16be79f09ac 100644 --- a/Framework/API/src/FrameworkManager.cpp +++ b/Framework/API/src/FrameworkManager.cpp @@ -309,42 +309,8 @@ FrameworkManagerImpl::createAlgorithm(const std::string &algName, IAlgorithm *alg = AlgorithmManager::Instance() .create(algName, version) .get(); // createAlgorithm(algName); - - ::Json::Value propertyJson; - // Split up comma-separated properties - typedef boost::tokenizer<boost::char_separator<char>> tokenizer; - - boost::char_separator<char> sep(";"); - tokenizer propPairs(propertiesArray, sep); - int index = 0; - // Iterate over the properties - for (tokenizer::iterator it = propPairs.begin(); it != propPairs.end(); - ++it) { - // Pair of the type " - std::string pair = *it; - - size_t n = pair.find('='); - if (n != std::string::npos) { - // Normal "PropertyName=value" string. - std::string propName = ""; - std::string value = ""; - - // Extract the value string - if (n < pair.size() - 1) { - propName = pair.substr(0, n); - value = pair.substr(n + 1, pair.size() - n - 1); - } else { - // String is "PropertyName=" - propName = pair.substr(0, n); - value = ""; - } - // Set it - propertyJson[propName] = value; - } - index++; - } - ::Json::FastWriter writer; - alg->setProperties(writer.write(propertyJson)); + alg->setPropertiesWithSimpleString(propertiesArray); + return alg; } diff --git a/Framework/API/test/AlgorithmPropertyTest.h b/Framework/API/test/AlgorithmPropertyTest.h index 9d60a2b1cf91eac964a79c32e371cd85156dd2f9..c71dc4bad6365f32b9b8cce7f3cefa3f74a82ffc 100644 --- a/Framework/API/test/AlgorithmPropertyTest.h +++ b/Framework/API/test/AlgorithmPropertyTest.h @@ -96,7 +96,7 @@ public: void test_An_Invalid_String_Returns_An_Appropriate_Error() { AlgorithmProperty testProp("CalculateStep"); - TS_ASSERT_EQUALS(testProp.setValue("ComplexSum()"), + TS_ASSERT_EQUALS(testProp.setValue("{\"name\":\"ComplexSum\"}"), "Algorithm not registered ComplexSum"); } diff --git a/Framework/Kernel/inc/MantidKernel/IPropertyManager.h b/Framework/Kernel/inc/MantidKernel/IPropertyManager.h index 63da9c9dfe3dad368e31b0a15ad7a36d93a86a15..d95afcfed62b448cc7115cb8979dbd0ebed48889 100644 --- a/Framework/Kernel/inc/MantidKernel/IPropertyManager.h +++ b/Framework/Kernel/inc/MantidKernel/IPropertyManager.h @@ -70,6 +70,17 @@ public: virtual void removeProperty(const std::string &name, const bool delproperty = true) = 0; + /** Sets all the declared properties from a string. + @param propertiesString :: A list of name = value pairs separated by a + semicolon + @param ignoreProperties :: A set of names of any properties NOT to set + from the propertiesArray + */ + virtual void + setPropertiesWithSimpleString(const std::string &propertiesString, + const std::set<std::string> & + ignoreProperties = std::set<std::string>()) = 0; + /** Sets all the declared properties from a string. @param propertiesJson :: A string of name = value pairs formatted as a json name value pair collection diff --git a/Framework/Kernel/inc/MantidKernel/PropertyManager.h b/Framework/Kernel/inc/MantidKernel/PropertyManager.h index 52778dc9466546a3ffabc28469d12b94094322b2..4df872b37487ad33506803d2c254b5aef45a8eaf 100644 --- a/Framework/Kernel/inc/MantidKernel/PropertyManager.h +++ b/Framework/Kernel/inc/MantidKernel/PropertyManager.h @@ -80,6 +80,9 @@ public: void setProperties( const ::Json::Value &jsonValue, const std::set<std::string> &ignoreProperties = std::set<std::string>()); + void setPropertiesWithSimpleString( + const std::string &propertiesString, + const std::set<std::string> &ignoreProperties = std::set<std::string>()); void setPropertyValue(const std::string &name, const std::string &value); void setPropertyOrdinal(const int &index, const std::string &value); diff --git a/Framework/Kernel/inc/MantidKernel/PropertyManagerOwner.h b/Framework/Kernel/inc/MantidKernel/PropertyManagerOwner.h index 3849c00dae013e2f73a4ff0470904fdcf1bd450f..b1a63444c9c78693173d1d22e81f3ceb8ee31a52 100644 --- a/Framework/Kernel/inc/MantidKernel/PropertyManagerOwner.h +++ b/Framework/Kernel/inc/MantidKernel/PropertyManagerOwner.h @@ -69,6 +69,11 @@ public: const ::Json::Value &jsonValue, const std::set<std::string> &ignoreProperties = std::set<std::string>()); + //sets all the declared properties using a simple string format + void setPropertiesWithSimpleString( + const std::string &propertiesString, + const std::set<std::string> &ignoreProperties = std::set<std::string>()); + void setPropertyValue(const std::string &name, const std::string &value); void setPropertyOrdinal(const int &index, const std::string &value); diff --git a/Framework/Kernel/src/PropertyManager.cpp b/Framework/Kernel/src/PropertyManager.cpp index 62a9f1b90e358c00cafd16086aa8bbc52457ca2f..666c7c2f27dcfd5b088267f50b30889d12c7a6b6 100644 --- a/Framework/Kernel/src/PropertyManager.cpp +++ b/Framework/Kernel/src/PropertyManager.cpp @@ -263,6 +263,51 @@ void PropertyManager::setProperties( } } +/** Sets all the declared properties from a string. + @param propertiesString :: A list of name = value pairs separated by a + semicolon + @param ignoreProperties :: A set of names of any properties NOT to set + from the propertiesArray +*/ +void PropertyManager::setPropertiesWithSimpleString( + const std::string &propertiesString, + const std::set<std::string> &ignoreProperties) { + ::Json::Value propertyJson; + // Split up comma-separated properties + typedef boost::tokenizer<boost::char_separator<char>> tokenizer; + + boost::char_separator<char> sep(";"); + tokenizer propPairs(propertiesString, sep); + int index = 0; + // Iterate over the properties + for (tokenizer::iterator it = propPairs.begin(); it != propPairs.end(); + ++it) { + // Pair of the type " + std::string pair = *it; + + size_t n = pair.find('='); + if (n != std::string::npos) { + // Normal "PropertyName=value" string. + std::string propName = ""; + std::string value = ""; + + // Extract the value string + if (n < pair.size() - 1) { + propName = pair.substr(0, n); + value = pair.substr(n + 1, pair.size() - n - 1); + } else { + // String is "PropertyName=" + propName = pair.substr(0, n); + value = ""; + } + // Set it + propertyJson[propName] = value; + } + index++; + } + setProperties(propertyJson, ignoreProperties); +} + //----------------------------------------------------------------------------------------------- /** Set the value of a property by string * N.B. bool properties must be set using 1/0 rather than true/false diff --git a/Framework/Kernel/src/PropertyManagerOwner.cpp b/Framework/Kernel/src/PropertyManagerOwner.cpp index bcc461b70652027768a6b6c2f7cc62a0acf71dae..e7ff0b08bfe0cd0ccb21077d231e55ba765690a6 100644 --- a/Framework/Kernel/src/PropertyManagerOwner.cpp +++ b/Framework/Kernel/src/PropertyManagerOwner.cpp @@ -68,6 +68,19 @@ void PropertyManagerOwner::setProperties( m_properties->setProperties(jsonValue, ignoreProperties); } +/** Sets all the declared properties from a string. + @param propertiesString :: A list of name = value pairs separated by a + semicolon + @param ignoreProperties :: A set of names of any properties NOT to set + from the propertiesArray +*/ +void PropertyManagerOwner::setPropertiesWithSimpleString( + const std::string &propertiesString, + const std::set<std::string> &ignoreProperties) { + m_properties->setPropertiesWithSimpleString(propertiesString, + ignoreProperties); +} + /** Set the value of a property by string * N.B. bool properties must be set using 1/0 rather than true/false * @param name :: The name of the property (case insensitive) diff --git a/Framework/LiveData/src/LiveDataAlgorithm.cpp b/Framework/LiveData/src/LiveDataAlgorithm.cpp index 6c5e338578566266d5f5ec57fac7bebba79a78e1..5a3390e0770d772d468476abed15da338b80dd4a 100644 --- a/Framework/LiveData/src/LiveDataAlgorithm.cpp +++ b/Framework/LiveData/src/LiveDataAlgorithm.cpp @@ -252,7 +252,7 @@ IAlgorithm_sptr LiveDataAlgorithm::makeAlgorithm(bool postProcessing) { ignoreProps.insert("OutputWorkspace"); // ...and pass it the properties - alg->setProperties(props, ignoreProps); + alg->setPropertiesWithSimpleString(props, ignoreProps); // Warn if someone put both values. if (!script.empty()) diff --git a/Framework/LiveData/test/LiveDataAlgorithmTest.h b/Framework/LiveData/test/LiveDataAlgorithmTest.h index 9f43790162b8f1a47eb2ffa2e3a33e6d43995e5f..0e2b7344b381ddaa4b09cdbadf40dab822f75423 100644 --- a/Framework/LiveData/test/LiveDataAlgorithmTest.h +++ b/Framework/LiveData/test/LiveDataAlgorithmTest.h @@ -122,7 +122,7 @@ public: TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue(prefix + "ProcessingAlgorithm", "Rebin")); TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( - prefix + "ProcessingProperties", "{\"Params\":\"0,100,1000\"}")); + prefix + "ProcessingProperties", "Params=0,100,1000")); procAlg = alg.makeAlgorithm(post > 0); TSM_ASSERT("Non-NULL algorithm pointer", procAlg); diff --git a/Framework/LiveData/test/StartLiveDataTest.h b/Framework/LiveData/test/StartLiveDataTest.h index 88d8af3bc52e5cda0b09fa24fbf1965124e84f43..023343ebd11be6149873e508b8dd7c9c1df932bf 100644 --- a/Framework/LiveData/test/StartLiveDataTest.h +++ b/Framework/LiveData/test/StartLiveDataTest.h @@ -84,7 +84,7 @@ public: // Declare all algorithms, e.g. Rebin FrameworkManager::Instance(); EventWorkspace_sptr ws; - ws = doExecEvent("Replace", 0, "Rebin", "{\"Params\":\"40e3, 1e3, 60e3\"}"); + ws = doExecEvent("Replace", 0, "Rebin", "Params=40e3, 1e3, 60e3"); TS_ASSERT_EQUALS(ws->getNumberHistograms(), 2); TS_ASSERT_EQUALS(ws->getNumberEvents(), 200); // Check that rebin was called @@ -120,7 +120,7 @@ public: FrameworkManager::Instance(); AlgorithmManager::Instance().clear(); EventWorkspace_sptr ws; - ws = doExecEvent("Replace", 1, "Rebin", "{\"Params\":\"40e3, 1e3, 60e3\"}"); + ws = doExecEvent("Replace", 1, "Rebin", "Params=40e3, 1e3, 60e3"); TS_ASSERT_EQUALS(ws->getNumberHistograms(), 2); TS_ASSERT_EQUALS(ws->getNumberEvents(), 200);