From 8f87459c97095cf2d7cd3875609d95cceb53e60f Mon Sep 17 00:00:00 2001 From: Nick Draper <nick.draper@stfc.ac.uk> Date: Tue, 29 Jan 2008 16:45:39 +0000 Subject: [PATCH] re #34 Improveed handling if properties file missing. Changed VS build to use dynamic loading --- Code/Mantid/API/src/AlgorithmHistory.cpp | 2 +- Code/Mantid/API/src/FrameworkManager.cpp | 8 +++++--- .../Kernel/inc/MantidKernel/ConfigService.h | 4 ++++ Code/Mantid/Kernel/src/ConfigService.cpp | 17 ++++++++++++++-- Code/Mantid/Main/Benchmark.cpp | 20 +++++++++---------- Code/Mantid/Main/Benchmark.h | 3 +-- Code/Mantid/Main/Main.cpp | 5 ++--- Code/Mantid/Main/Main.vcproj | 6 +++--- Code/Mantid/debug/Mantid.properties | 17 ++++++++++++++++ Code/Mantid/release/Mantid.properties | 17 ++++++++++++++++ 10 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 Code/Mantid/debug/Mantid.properties create mode 100644 Code/Mantid/release/Mantid.properties diff --git a/Code/Mantid/API/src/AlgorithmHistory.cpp b/Code/Mantid/API/src/AlgorithmHistory.cpp index f8b6d1bf8d3..f68de523ffa 100644 --- a/Code/Mantid/API/src/AlgorithmHistory.cpp +++ b/Code/Mantid/API/src/AlgorithmHistory.cpp @@ -2,7 +2,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidAPI/AlgorithmHistory.h" - +#include "boost/date_time/posix_time/posix_time.hpp" namespace Mantid { diff --git a/Code/Mantid/API/src/FrameworkManager.cpp b/Code/Mantid/API/src/FrameworkManager.cpp index 67b424c8429..0c59fa94520 100644 --- a/Code/Mantid/API/src/FrameworkManager.cpp +++ b/Code/Mantid/API/src/FrameworkManager.cpp @@ -52,10 +52,12 @@ void FrameworkManager::initialize() workFactory = WorkspaceFactory::Instance(); data = AnalysisDataService::Instance(); - config->loadConfig("Mantid.properties"); std::string pluginDir = config->getString("plugins.directory"); - libManager = Mantid::Kernel::LibraryManager::Instance(); - libManager->OpenAllLibraries(pluginDir, false); + if (pluginDir.length() > 0) + { + libManager = Mantid::Kernel::LibraryManager::Instance(); + libManager->OpenAllLibraries(pluginDir, false); + } return; } diff --git a/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h b/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h index 5a2448ef68e..01f4c42da2e 100644 --- a/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h +++ b/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h @@ -5,6 +5,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidKernel/System.h" +#include "MantidKernel/Logger.h" #include <iostream> #include <iomanip> #include <string> @@ -151,6 +152,9 @@ namespace Kernel /// Pointer to the factory instance static ConfigService* m_instance; + /// static reference to the logger class + static Logger& g_log; + }; } // namespace Kernel diff --git a/Code/Mantid/Kernel/src/ConfigService.cpp b/Code/Mantid/Kernel/src/ConfigService.cpp index 81d3b32a64e..9188cdae354 100644 --- a/Code/Mantid/Kernel/src/ConfigService.cpp +++ b/Code/Mantid/Kernel/src/ConfigService.cpp @@ -17,6 +17,9 @@ namespace Kernel // Initialise the instance pointer to zero ConfigService* ConfigService::m_instance=0; + // Get a reference to the logger + Logger& ConfigService::g_log = Logger::get("ConfigService"); + /** A static method which retrieves the single instance of the ConfigService * * @returns A pointer to the instance @@ -102,11 +105,21 @@ namespace Kernel * returns the value as a string. * * @param keyName The case sensitive name of the property that you need the value of. - * @returns The string value of the property + * @returns The string value of the property, or an empty string if the key cannot be found */ std::string ConfigService::getString(const std::string& keyName) { - return m_pConf->getString(keyName); + std::string retVal; + try + { + retVal = m_pConf->getString(keyName); + } + catch(Poco::NotFoundException& ex) + { + g_log.warning()<<"Unable to find " << keyName << " in the properties file"; + retVal = ""; + } + return retVal; } /** Searches for a string within the currently loaded configuaration values and diff --git a/Code/Mantid/Main/Benchmark.cpp b/Code/Mantid/Main/Benchmark.cpp index ce926d4fc25..a66b741030f 100644 --- a/Code/Mantid/Main/Benchmark.cpp +++ b/Code/Mantid/Main/Benchmark.cpp @@ -1,13 +1,12 @@ #include <iostream> #include <iomanip> #include <ctime> -#include "Benchmark.h" +#include "Benchmark.h" +#include "MantidAPI\IAlgorithm.h" using namespace Mantid::Kernel; using namespace Mantid::DataObjects; -using namespace Mantid::API; -using namespace Mantid::Algorithms; - +using namespace Mantid::API; Workspace1D_sptr Benchmark::Create1DWorkspaceFib(int size) { @@ -89,15 +88,16 @@ void Benchmark::RunPlusTest(int detectorCount, int timeBinCount) ADS->add("test_in11", work_in3); ADS->add("test_in12", work_in4); - Plus plus_alg; + + IAlgorithm* alg = FrameworkManager::Instance()->createAlgorithm("Plus"); - plus_alg.initialize(); - plus_alg.setPropertyValue("InputWorkspace_1","test_in11"); - plus_alg.setPropertyValue("InputWorkspace_2","test_in12"); - plus_alg.setPropertyValue("OutputWorkspace","test_out1"); + //alg.initialize(); + alg->setPropertyValue("InputWorkspace_1","test_in11"); + alg->setPropertyValue("InputWorkspace_2","test_in12"); + alg->setPropertyValue("OutputWorkspace","test_out1"); clock_t start = clock(); - plus_alg.execute(); + alg->execute(); clock_t end = clock(); Workspace_sptr work_out1 = ADS->retrieve("test_out1"); diff --git a/Code/Mantid/Main/Benchmark.h b/Code/Mantid/Main/Benchmark.h index 84cccd76b67..ec8d561be1b 100644 --- a/Code/Mantid/Main/Benchmark.h +++ b/Code/Mantid/Main/Benchmark.h @@ -5,8 +5,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidAPI/AnalysisDataService.h" -#include "MantidAlgorithms/Plus.h" -#include "MantidAlgorithms/Multiply.h" +#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/Workspace.h" #include "MantidAPI/Algorithm.h" #include "MantidDataObjects/Workspace1D.h" diff --git a/Code/Mantid/Main/Main.cpp b/Code/Mantid/Main/Main.cpp index afc57c87749..69c2f878f37 100644 --- a/Code/Mantid/Main/Main.cpp +++ b/Code/Mantid/Main/Main.cpp @@ -8,8 +8,7 @@ using namespace Mantid::Kernel; using namespace Mantid::DataObjects; -using namespace Mantid::API; -using namespace Mantid::Algorithms; +using namespace Mantid::API; @@ -17,7 +16,7 @@ int main() { FrameworkManager* fm = FrameworkManager::Instance(); - //fm->initialize(); + fm->initialize(); Benchmark b; b.RunPlusTest(); diff --git a/Code/Mantid/Main/Main.vcproj b/Code/Mantid/Main/Main.vcproj index dc85f37f276..3f95527b92a 100644 --- a/Code/Mantid/Main/Main.vcproj +++ b/Code/Mantid/Main/Main.vcproj @@ -54,7 +54,7 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="$(SolutionName)API.lib $(SolutionName)Kernel.lib $(SolutionName)Algorithms.lib $(SolutionName)Geometry.lib $(SolutionName)DataHandling.lib $(SolutionName)DataObjects.lib" + AdditionalDependencies="$(SolutionName)API.lib $(SolutionName)Kernel.lib $(SolutionName)Geometry.lib" OutputFile="$(OutDir)\$(SolutionName)$(ProjectName).exe" AdditionalLibraryDirectories="..\..\Third_Party\lib\win32;..\Debug" GenerateDebugInformation="true" @@ -122,9 +122,9 @@ /> <Tool Name="VCLinkerTool" - AdditionalDependencies="$(SolutionName)API.lib $(SolutionName)Kernel.lib $(SolutionName)Algorithms.lib $(SolutionName)Geometry.lib $(SolutionName)DataHandling.lib $(SolutionName)DataObjects.lib" + AdditionalDependencies="$(SolutionName)API.lib $(SolutionName)Kernel.lib $(SolutionName)Geometry.lib $(SolutionName)DataObjects.lib" OutputFile="$(OutDir)\$(SolutionName)$(ProjectName).exe" - AdditionalLibraryDirectories="..\Release" + AdditionalLibraryDirectories="..\Release;..\..\Third_Party\lib\win32" /> <Tool Name="VCALinkTool" diff --git a/Code/Mantid/debug/Mantid.properties b/Code/Mantid/debug/Mantid.properties new file mode 100644 index 00000000000..1c07cde4030 --- /dev/null +++ b/Code/Mantid/debug/Mantid.properties @@ -0,0 +1,17 @@ +#framework configuration +plugins.directory = . + +#logging configuration +logging.loggers.root.level = debug +logging.loggers.root.channel.class = SplitterChannel +logging.loggers.root.channel.channel1 = consoleChannel +logging.loggers.root.channel.channel2 = fileChannel +logging.channels.consoleChannel.class = ConsoleChannel +logging.channels.consoleChannel.formatter = f1 +logging.channels.fileChannel.class = FileChannel +logging.channels.fileChannel.path = mantid.log +logging.channels.fileChannel.formatter.class = PatternFormatter +logging.channels.fileChannel.formatter.pattern = %Y-%m-%d %H:%M:%S,%i [%I] %p %s - %t +logging.formatters.f1.class = PatternFormatter +logging.formatters.f1.pattern = %s-[%p] %t +logging.formatters.f1.times = UTC; diff --git a/Code/Mantid/release/Mantid.properties b/Code/Mantid/release/Mantid.properties new file mode 100644 index 00000000000..1c07cde4030 --- /dev/null +++ b/Code/Mantid/release/Mantid.properties @@ -0,0 +1,17 @@ +#framework configuration +plugins.directory = . + +#logging configuration +logging.loggers.root.level = debug +logging.loggers.root.channel.class = SplitterChannel +logging.loggers.root.channel.channel1 = consoleChannel +logging.loggers.root.channel.channel2 = fileChannel +logging.channels.consoleChannel.class = ConsoleChannel +logging.channels.consoleChannel.formatter = f1 +logging.channels.fileChannel.class = FileChannel +logging.channels.fileChannel.path = mantid.log +logging.channels.fileChannel.formatter.class = PatternFormatter +logging.channels.fileChannel.formatter.pattern = %Y-%m-%d %H:%M:%S,%i [%I] %p %s - %t +logging.formatters.f1.class = PatternFormatter +logging.formatters.f1.pattern = %s-[%p] %t +logging.formatters.f1.times = UTC; -- GitLab