Skip to content

Commit

Permalink
Merge branch 'feature/7263_improve_load_selection_performance' into d…
Browse files Browse the repository at this point in the history
…evelop

Refs #7263
Conflicts:
	Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILL.h
	Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
	Code/Mantid/Framework/DataHandling/src/LoadILL.cpp
	Code/Mantid/Framework/DataHandling/src/LoadSassena.cpp
  • Loading branch information
martyngigg committed Jul 5, 2013
1 parent a7f638b commit 134bd76
Show file tree
Hide file tree
Showing 111 changed files with 3,095 additions and 2,950 deletions.
16 changes: 12 additions & 4 deletions Code/Mantid/Build/move_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
def move_one(subproject, classname, newproject, newclassname, oldfilename, newfilename, args):
"""Move one file """

# Do an SVN move
cmd = "git mv " + oldfilename + " " + newfilename
# Move the file
cmd = "mv " + oldfilename + " " + newfilename
if not args.no_vcs:
cmd = "git " + cmd
print "Running:", cmd
os.system(cmd)
retval = os.system(cmd)
if retval != 0:
raise RuntimeError("Error executing cmd '%s'" % cmd)

f = open(newfilename, 'r')
text = f.read()
Expand Down Expand Up @@ -102,6 +106,9 @@ def move_all(subproject, classname, newproject, newclassname, args):
parser.add_argument('--force', dest='force', action='store_const',
const=True, default=False,
help='Force overwriting existing files. Use with caution!')
parser.add_argument('--no-vcs', dest='no_vcs', action='store_const',const=True,
default=False,
help='Can be used to move a class that is not yet under version control. Default: False')
parser.add_argument('--no-header', dest='header', action='store_const',
const=False, default=True,
help="Don't move the header file")
Expand All @@ -120,14 +127,15 @@ def move_all(subproject, classname, newproject, newclassname, args):
parser.add_argument('--project', dest='project',
default="Framework",
help='The project in which this goes. Default: Framework. Can be MantidQt, Vates')


args = parser.parse_args()
subproject = args.subproject
newproject = args.newproject
classname = args.classname
newclassname = args.newclassname
overwrite = args.force

# Make sure the subfolders end with a /
if args.source_subfolder != "":
if args.source_subfolder[-1:] != "/":
Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set ( SRC_FILES
src/Expression.cpp
src/FermiChopperModel.cpp
src/FileFinder.cpp
src/FileLoaderRegistry.cpp
src/FileProperty.cpp
src/FrameworkManager.cpp
src/FuncMinimizerFactory.cpp
Expand All @@ -38,7 +39,6 @@ set ( SRC_FILES
src/FunctionValues.cpp
src/GridDomain.cpp
src/GridDomain1D.cpp
src/IDataFileChecker.cpp
src/IDomainCreator.cpp
src/IEventList.cpp
src/IEventWorkspace.cpp
Expand Down Expand Up @@ -68,7 +68,6 @@ set ( SRC_FILES
src/JointDomain.cpp
src/LinearScale.cpp
src/LiveListenerFactory.cpp
src/LoadAlgorithmFactory.cpp
src/LocatedDataRef.cpp
src/LocatedDataValue.cpp
src/LogManager.cpp
Expand Down Expand Up @@ -152,6 +151,7 @@ set ( INC_FILES
inc/MantidAPI/Expression.h
inc/MantidAPI/FermiChopperModel.h
inc/MantidAPI/FileFinder.h
inc/MantidAPI/FileLoaderRegistry.h
inc/MantidAPI/FileProperty.h
inc/MantidAPI/FrameworkManager.h
inc/MantidAPI/FuncMinimizerFactory.h
Expand All @@ -170,18 +170,19 @@ set ( INC_FILES
inc/MantidAPI/ICatalog.h
inc/MantidAPI/IConstraint.h
inc/MantidAPI/ICostFunction.h
inc/MantidAPI/IDataFileChecker.h
inc/MantidAPI/IDataItem.h
inc/MantidAPI/IDomainCreator.h
inc/MantidAPI/IEventList.h
inc/MantidAPI/IEventWorkspace.h
inc/MantidAPI/IFileLoader.h
inc/MantidAPI/IFuncMinimizer.h
inc/MantidAPI/IFunction.h
inc/MantidAPI/IFunction1D.h
inc/MantidAPI/IFunctionMD.h
inc/MantidAPI/IFunctionMW.h
inc/MantidAPI/IFunctionValues.h
inc/MantidAPI/IFunctionWithLocation.h
inc/MantidAPI/IHDFFileLoader.h
inc/MantidAPI/ILiveListener.h
inc/MantidAPI/ILocatedData.h
inc/MantidAPI/IMDEventWorkspace.h
Expand Down Expand Up @@ -212,7 +213,6 @@ set ( INC_FILES
inc/MantidAPI/JointDomain.h
inc/MantidAPI/LinearScale.h
inc/MantidAPI/LiveListenerFactory.h
inc/MantidAPI/LoadAlgorithmFactory.h
inc/MantidAPI/LocatedDataRef.h
inc/MantidAPI/LocatedDataValue.h
inc/MantidAPI/LogManager.h
Expand Down
20 changes: 13 additions & 7 deletions Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//----------------------------------------------------------------------
#include <vector>
#include <set>
#include <sstream>
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/DynamicFactory.h"
#include "MantidKernel/SingletonHolder.h"
Expand Down Expand Up @@ -67,20 +68,21 @@ class MANTID_API_DLL AlgorithmFactoryImpl : public Kernel::DynamicFactory<Algori

/// algorithm factory specific function to subscribe algorithms, calls the dynamic factory subscribe function internally
template <class C>
void subscribe()
std::pair<std::string,int> subscribe()
{
Kernel::Instantiator<C, Algorithm>* newI = new Kernel::Instantiator<C, Algorithm>;
this->subscribe(newI);
return this->subscribe(newI);
}

/**
* Subscribes an algorithm using a custom instantiator. This
* object takes ownership of the instantiator
* @param instantiator - A pointer to a custom instantiator
* @param replaceExisting - Defines what happens if an algorithm of the same name/verson already exists, see SubscribeAction
* @param replaceExisting - Defines what happens if an algorithm of the same name/version already exists, see SubscribeAction
* @returns The classname that was registered
*/
template<class T>
void subscribe(Kernel::AbstractInstantiator<T> *instantiator, const SubscribeAction replaceExisting = ErrorIfExists)
std::pair<std::string,int> subscribe(Kernel::AbstractInstantiator<T> *instantiator, const SubscribeAction replaceExisting = ErrorIfExists)
{
boost::shared_ptr<IAlgorithm> tempAlg = instantiator-> createInstance();
const int version = extractAlgVersion(tempAlg);
Expand All @@ -97,16 +99,20 @@ class MANTID_API_DLL AlgorithmFactoryImpl : public Kernel::DynamicFactory<Algori
{
if(version == it->second && replaceExisting == ErrorIfExists)
{
g_log.fatal() << "Cannot register algorithm " << className << " twice with the same version\n";
return;
std::ostringstream os;
os << "Cannot register algorithm " << className << " twice with the same version\n";
throw std::runtime_error(os.str());
}
if(version > it->second)
{
m_vmap[className]=version;
}
}
}
Kernel::DynamicFactory<Algorithm>::subscribe(key, instantiator, replaceExisting);
}
else
throw std::invalid_argument("Cannot register empty algorithm name");
return std::make_pair(className,version);
}
/// Unsubscribe the given algorithm
void unsubscribe(const std::string & algorithmName, const int version);
Expand Down
146 changes: 146 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/FileLoaderRegistry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#ifndef MANTID_API_FILELOADERREGISTRY_H_
#define MANTID_API_FILELOADERREGISTRY_H_

#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/IFileLoader.h"
#include "MantidAPI/IHDFFileLoader.h"
#include "MantidKernel/SingletonHolder.h"

#include <boost/type_traits/is_base_of.hpp>

#include <map>
#include <string>
#include <vector>

namespace Mantid
{
// Forward declaration
namespace Kernel
{
class Logger;
}
namespace API
{
// Forward declaration
class IAlgorithm;

/**
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.
A macro, DECLARE_FILELOADER_ALGORITHM is defined in RegisterFileLoader.h. Use this in place of the standard
DECLARE_ALGORITHM macro
Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL FileLoaderRegistryImpl
{
public:

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

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

/**
* Registers a loader whose format is one of the known formats given in LoaderFormat. It
* also passes this registration on to the AlgorithmFactory so that it can be created.
* The template type should be the class being registered. The name is taken from the string
* returned by the name() method on the object.
* @param format The type of loader being subscribed, see LoaderFormat
* @throws std::invalid_argument if an entry with this name already exists
*/
template<typename Type>
void subscribe(LoaderFormat format)
{
SubscriptionValidator<Type>::check(format);
const auto nameVersion = AlgorithmFactory::Instance().subscribe<Type>();
// If the factory didn't throw then the name is valid
m_names[format].insert(nameVersion);
m_totalSize += 1;
m_log.debug() << "Registered '" << nameVersion.first << "' version '" << nameVersion.second << "' as file loader\n";
}

/// Returns the name of an Algorithm that can load the given filename
const boost::shared_ptr<IAlgorithm> chooseLoader(const std::string &filename) const;
/// Checks whether the given algorithm can load the file
bool canLoad(const std::string & algorithmName,const std::string & filename) const;

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

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

/// Helper for subscribe to check base class
template <typename T>
struct SubscriptionValidator
{
static void check(LoaderFormat format)
{
switch(format)
{
case HDF:
if(!boost::is_base_of<IHDFFileLoader,T>::value)
{
throw std::runtime_error(std::string("FileLoaderRegistryImpl::subscribe - Class '") + typeid(T).name() +
"' registered as HDF loader but it does not inherit from Mantid::API::IHDFFileLoader");
}
break;
case NonHDF:
if(!boost::is_base_of<IFileLoader,T>::value)
{
throw std::runtime_error(std::string("FileLoaderRegistryImpl::subscribe - Class '") + typeid(T).name() +
"' registered as Non-HDF loader but it does not inherit from Mantid::API::IFileLoader");
}
break;
default: throw std::runtime_error("Invalid LoaderFormat given");
}
}
};

/// The list of names. The index pointed to by LoaderFormat defines a set for that format
std::vector<std::multimap<std::string,int> > m_names;
/// Total number of names registered
size_t m_totalSize;

/// Reference to a logger
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

#endif /* MANTID_API_FILELOADERREGISTRY_H_ */
12 changes: 7 additions & 5 deletions Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +11,7 @@
#endif

#include "MantidAPI/DllConfig.h"
#include "MantidAPI/FileLoaderRegistry.h"
#include "MantidKernel/SingletonHolder.h"
#include <boost/shared_ptr.hpp>

Expand Down Expand Up @@ -116,9 +117,10 @@ namespace Mantid
/// Silence NeXus output
void disableNexusOutput();

Kernel::Logger& g_log; ///< Reference to the logger class
/// 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.
Expand All @@ -137,4 +139,4 @@ namespace Mantid
} // namespace Kernel
} // namespace Mantid

#endif /*MANTID_KERNEL_FRAMEWORKMANAGER_H_*/
#endif /*MANTID_API_FRAMEWORKMANAGER_H_*/

0 comments on commit 134bd76

Please sign in to comment.