Skip to content
Snippets Groups Projects
AlgorithmManager.cpp 2.51 KiB
Newer Older
Matt Clarke's avatar
Matt Clarke committed
#include <iomanip>
#include <iostream>
#include <vector>
#include "MantidAPI/AlgorithmManager.h"
Nick Draper's avatar
Nick Draper committed
#include "MantidAPI/Algorithm.h"
#include "MantidKernel/Exception.h"
using namespace Mantid::Kernel;

  namespace API
  {

    /// Private Constructor for singleton class
    AlgorithmManagerImpl::AlgorithmManagerImpl(): g_log(Kernel::Logger::get("AlgorithmManager")), no_of_alg(0)
		std::cerr << "Algorithm Manager created." << std::endl;
		g_log.debug() << "Algorithm Manager created." << std::endl;
    /** Private destructor
    *  Prevents client from calling 'delete' on the pointer handed 
    *  out by Instance
    */
    AlgorithmManagerImpl::~AlgorithmManagerImpl()
		std::cerr << "Algorithm Manager destroyed." << std::endl;
//		g_log.debug() << "Algorithm Manager destroyed." << std::endl;
    /** Creates an instance of an algorithm, but does not own that instance
    * 
    *  @param  algName The name of the algorithm required
    *  @return A pointer to the created algorithm
    *  @throw  NotFoundError Thrown if algorithm requested is not registered
    */
Dickon Champion's avatar
Dickon Champion committed
    Algorithm_sptr AlgorithmManagerImpl::createUnmanaged(const std::string& algName,const int& version) const
Dickon Champion's avatar
Dickon Champion committed
      return AlgorithmFactory::Instance().create(algName,version);                // Throws on fail:
    }

    /** Creates an instance of an algorithm
    *
    *  @param  algName The name of the algorithm required
    *  @return A pointer to the created algorithm
    *  @throw  NotFoundError Thrown if algorithm requested is not registered
    *  @throw  std::runtime_error Thrown if properties string is ill-formed
    */
Dickon Champion's avatar
Dickon Champion committed
    Algorithm_sptr AlgorithmManagerImpl::create(const std::string& algName, const int& version)
Dickon Champion's avatar
Dickon Champion committed
        regAlg.push_back(AlgorithmFactory::Instance().create(algName,version));      // Throws on fail:	   
        regAlg.back()->initialize();
      }
      catch(std::runtime_error& ex)
      {
        g_log.error()<<"AlgorithmManager:: Unable to create algorithm "<< algName <<ex.what() << std::endl;  
        throw std::runtime_error("AlgorithmManager:: Unable to create algorithm " + algName); 
      }
      no_of_alg++;		
      return regAlg.back();
    }

    /// deletes all registered algorithms
Nick Draper's avatar
Nick Draper committed
      std::vector<Algorithm_sptr>::iterator vc;