Skip to content

Commit

Permalink
Move FileRegistry to singleton Refs #7263
Browse files Browse the repository at this point in the history
It appears that we can't start the FrameworkManager during static
initialization or the destruction of the FrameworkManager instance gets
instance gets confused.
  • Loading branch information
martyngigg committed Jul 3, 2013
1 parent b3236b5 commit db8d95c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 145 deletions.
1 change: 0 additions & 1 deletion Code/Mantid/Framework/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ set ( TEST_FILES
ExpressionTest.h
FermiChopperModelTest.h
FileFinderTest.h
FileLoaderRegistryTest.h
FilePropertyTest.h
FrameworkManagerTest.h
FuncMinimizerFactoryTest.h
Expand Down
25 changes: 20 additions & 5 deletions Code/Mantid/Framework/API/inc/MantidAPI/FileLoaderRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "MantidAPI/DllConfig.h"
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidKernel/SingletonHolder.h"

#include <set>
#include <string>
Expand All @@ -20,7 +21,7 @@ namespace Mantid

/**
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
to find the correct one to load a particular file.
A macro, DECLARE_FILELOADER_ALGORITHM is defined in RegisterFileLoader.h. Use this in place of the standard
DECLARE_ALGORITHM macro
Expand All @@ -45,17 +46,14 @@ namespace Mantid
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL FileLoaderRegistry
class MANTID_API_DLL FileLoaderRegistryImpl
{
public:

/// Defines types of possible file
enum LoaderFormat { NonHDF, HDF };

public:
/// Default constructor
FileLoaderRegistry();

/// @returns the number of entries in the registry
inline size_t size() const { return m_totalSize; }

Expand All @@ -81,6 +79,14 @@ namespace Mantid
const std::string chooseLoader(const std::string &filename) const;

private:
/// Friend so that CreateUsingNew
friend struct Mantid::Kernel::CreateUsingNew<FileLoaderRegistryImpl>;

/// Default constructor (for singleton)
FileLoaderRegistryImpl();
/// Destructor
~FileLoaderRegistryImpl();

/// The list of names. The index pointed to by LoaderFormat defines a set for that format
std::vector<std::set<std::string> > m_names;
/// Total number of names registered
Expand All @@ -90,6 +96,15 @@ namespace Mantid
Kernel::Logger & m_log;
};

///Forward declaration of a specialisation of SingletonHolder for FileLoaderRegistryImpl (needed for dllexport/dllimport) and a typedef for it.
#ifdef _WIN32
// this breaks new namespace declaration rules; need to find a better fix
template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<FileLoaderRegistryImpl>;
#endif /* _WIN32 */

/// Type for the actual singleton instance
typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<FileLoaderRegistryImpl> FileLoaderRegistry;

} // namespace API
} // namespace Mantid

Expand Down
7 changes: 0 additions & 7 deletions Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ 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);

Expand Down Expand Up @@ -122,8 +117,6 @@ namespace Mantid
/// Silence NeXus output
void disableNexusOutput();

/// The registry of FileLoader algorithms
FileLoaderRegistry m_fileLoaderRegistry;
/// Reference to the logger class
Kernel::Logger& g_log;

Expand Down
7 changes: 3 additions & 4 deletions Code/Mantid/Framework/API/inc/MantidAPI/RegisterFileLoader.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef MANTID_API_REGISTERFILELOADER_H_
#define MANTID_API_REGISTERFILELOADER_H_

#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/FileLoaderRegistry.h"

/**
* DECLARE_FILELOADER_ALGORITHM should be used in place of the standard
Expand All @@ -16,7 +15,7 @@
{\
Mantid::Kernel::RegistrationHelper \
reg_loader_##classname((Mantid::API::\
FrameworkManager::Instance().fileLoaderRegistry().subscribe<classname>(Mantid::API::FileLoaderRegistry::NonHDF), 0));\
FileLoaderRegistry::Instance().subscribe<classname>(Mantid::API::FileLoaderRegistryImpl::NonHDF), 0));\
}

/**
Expand All @@ -31,7 +30,7 @@
{\
Mantid::Kernel::RegistrationHelper \
reg_hdf_loader_##classname((Mantid::API::\
FrameworkManager::Instance().fileLoaderRegistry().subscribe<classname>(Mantid::API::FileLoaderRegistry::HDF), 0)); \
FileLoaderRegistry::Instance().subscribe<classname>(Mantid::API::FileLoaderRegistryImpl::HDF), 0)); \
}


Expand Down
24 changes: 15 additions & 9 deletions Code/Mantid/Framework/API/src/FileLoaderRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ namespace Mantid
//----------------------------------------------------------------------------------------------
// Public members
//----------------------------------------------------------------------------------------------
/**
* Creates an empty registry
*/
FileLoaderRegistry::FileLoaderRegistry() :
m_names(2, std::set<std::string>()), m_totalSize(0),
m_log(Kernel::Logger::get("FileLoaderRegistry"))
{
}

/**
* Queries each registered algorithm and asks it how confident it is that it can
Expand All @@ -89,7 +81,7 @@ namespace Mantid
* @return A string containing the name of an algorithm to load the file
* @throws Exception::NotFoundError if an algorithm cannot be found
*/
const std::string FileLoaderRegistry::chooseLoader(const std::string &filename) const
const std::string FileLoaderRegistryImpl::chooseLoader(const std::string &filename) const
{
using Kernel::FileDescriptor;
using Kernel::HDFDescriptor;
Expand Down Expand Up @@ -122,6 +114,20 @@ namespace Mantid
//----------------------------------------------------------------------------------------------
// Private members
//----------------------------------------------------------------------------------------------
/**
* Creates an empty registry
*/
FileLoaderRegistryImpl::FileLoaderRegistryImpl() :
m_names(2, std::set<std::string>()), m_totalSize(0),
m_log(Kernel::Logger::get("FileLoaderRegistry"))
{
}

/**
*/
FileLoaderRegistryImpl::~FileLoaderRegistryImpl()
{
}

} // namespace API
} // namespace Mantid
3 changes: 1 addition & 2 deletions Code/Mantid/Framework/API/src/FrameworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ namespace API


/// Default constructor
FrameworkManagerImpl::FrameworkManagerImpl()
: m_fileLoaderRegistry(), g_log(Kernel::Logger::get("FrameworkManager"))
FrameworkManagerImpl::FrameworkManagerImpl() : g_log(Kernel::Logger::get("FrameworkManager"))
#ifdef MPI_BUILD
, m_mpi_environment()
#endif
Expand Down
117 changes: 0 additions & 117 deletions Code/Mantid/Framework/API/test/FileLoaderRegistryTest.h

This file was deleted.

0 comments on commit db8d95c

Please sign in to comment.