diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/FileLoaderRegistry.h b/Code/Mantid/Framework/API/inc/MantidAPI/FileLoaderRegistry.h index b3a06cd6efe11c7bf4a9341a368a7f3f86fea976..cda2b301c059df381d6dcbc948c3886b8e678333 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/FileLoaderRegistry.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/FileLoaderRegistry.h @@ -8,11 +8,20 @@ namespace Mantid { + // Forward declaration + namespace Kernel + { + class Logger; + } namespace API { /** + Keeps a registry of algorithm's that are file loading algorithms to allow them to be searched + to find the correct one to load a particular file. Uses FileLoaderPicker to do the most of the work + A macro, DECLARE_FILELOADER_ALGORITHM is defined in RegisterFileLoader.h. Use this in place of the standard + DECLARE_ALGORITHM macro Copyright © 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory @@ -50,6 +59,8 @@ namespace Mantid private: /// The registered names std::set<std::string> m_names; + /// Reference to a logger + Kernel::Logger & m_log; }; } // namespace API diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h b/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h index c82cfb827acb3b27de0bac079e3696dee7f2afbd..0861cef25a2cbd3a46656cbbe35f850bac3eb2fc 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h @@ -1,5 +1,5 @@ -#ifndef MANTID_KERNEL_FRAMEWORKMANAGER_H_ -#define MANTID_KERNEL_FRAMEWORKMANAGER_H_ +#ifndef MANTID_API_FRAMEWORKMANAGER_H_ +#define MANTID_API_FRAMEWORKMANAGER_H_ //---------------------------------------------------------------------- // Includes @@ -11,6 +11,7 @@ #endif #include "MantidAPI/DllConfig.h" +#include "MantidAPI/FileLoaderRegistry.h" #include "MantidKernel/SingletonHolder.h" #include <boost/shared_ptr.hpp> @@ -89,6 +90,11 @@ namespace Mantid /// Creates an algorithm and runs it, with variadic arguments boost::shared_ptr<IAlgorithm> exec(const std::string& algorithmName, int count, ...); + /// Returns a const version of the main registry of file loader algorithms + inline const FileLoaderRegistry & fileLoaderRegistry() const { return m_fileLoaderRegistry; } + /// Returns a non-const version of the main registry of file loader algorithms + inline FileLoaderRegistry & fileLoaderRegistry() { return m_fileLoaderRegistry; } + /// Returns a shared pointer to the workspace requested Workspace* getWorkspace(const std::string& wsName); @@ -116,9 +122,12 @@ namespace Mantid /// Silence NeXus output void disableNexusOutput(); - Kernel::Logger& g_log; ///< Reference to the logger class + /// The registry of FileLoader algorithms + FileLoaderRegistry m_fileLoaderRegistry; + /// Reference to the logger class + Kernel::Logger& g_log; -#ifdef MPI_BUILD + #ifdef MPI_BUILD /** Member variable that initialises the MPI environment on construction (in the * FrameworkManager constructor) and finalises it on destruction. * The class has no non-static member functions, so is not exposed in the class interface. @@ -137,4 +146,4 @@ namespace Mantid } // namespace Kernel } // namespace Mantid -#endif /*MANTID_KERNEL_FRAMEWORKMANAGER_H_*/ +#endif /*MANTID_API_FRAMEWORKMANAGER_H_*/ diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/RegisterFileLoader.h b/Code/Mantid/Framework/API/inc/MantidAPI/RegisterFileLoader.h new file mode 100644 index 0000000000000000000000000000000000000000..f85c4457b2a837dab11420d09e37b96bab69590d --- /dev/null +++ b/Code/Mantid/Framework/API/inc/MantidAPI/RegisterFileLoader.h @@ -0,0 +1,20 @@ +#ifndef MANTID_API_REGISTERFILELOADER_H_ +#define MANTID_API_REGISTERFILELOADER_H_ + +#include "MantidAPI/AlgorithmFactory.h" +#include "MantidAPI/FrameworkManager.h" + +/** + * DECLARE_FILELOADER_ALGORITHM should be used in place of the standard + * DECLARE_ALGORITHM macro that both registers the algorithm as usual and subscribes it to the + * registry held in the FrameworkManager + */ +#define DECLARE_FILELOADER_ALGORITHM(classname) \ + DECLARE_ALGORITHM(classname) \ + namespace \ + {\ + Mantid::Kernel::RegistrationHelper \ + reg_loader_##classname((Mantid::API::FrameworkManager::Instance().fileLoaderRegistry().subscribe(#classname), 0));\ + } + +#endif /* MANTID_API_REGISTERFILELOADER_H_ */ diff --git a/Code/Mantid/Framework/API/src/FileLoaderRegistry.cpp b/Code/Mantid/Framework/API/src/FileLoaderRegistry.cpp index 229c92c608c0d774db9bbf8c368ef6e908bbb18e..e14f6cae0f9f5cc23e2bd336180037b6ac4c22fa 100644 --- a/Code/Mantid/Framework/API/src/FileLoaderRegistry.cpp +++ b/Code/Mantid/Framework/API/src/FileLoaderRegistry.cpp @@ -1,5 +1,6 @@ #include "MantidAPI/FileLoaderRegistry.h" #include "MantidKernel/Exception.h" +#include "MantidKernel/Logger.h" #include <Poco/File.h> @@ -13,7 +14,7 @@ namespace Mantid /** * Creates an empty registry */ - FileLoaderRegistry::FileLoaderRegistry() + FileLoaderRegistry::FileLoaderRegistry() : m_log(Kernel::Logger::get("FileLoaderRegistry")) { } @@ -29,6 +30,7 @@ namespace Mantid throw std::invalid_argument("FileLoaderRegistry::subscribe - Cannot subscribe '" + name + "'. An entry with that name already exists"); } + m_log.debug() << "Registered '" << name << "' as file loader\n"; } /** @@ -43,6 +45,8 @@ namespace Mantid { throw std::invalid_argument("FileLoaderRegistry::chooserLoader - Cannot open file '" + filename + "'"); } + m_log.debug() << "Attempting to find loader for '" << filename << "'\n"; + throw std::runtime_error("not implemented yet"); } //----------------------------------------------------------------------------------------------