Newer
Older
Dickon Champion
committed
#include "IAlgorithm.h"
#include "StatusCode.h"
#include "AlgorithmManager.h"
Dickon Champion
committed
namespace Mantid
Russell Taylor
committed
{
namespace Kernel
Dickon Champion
committed
{
Dickon Champion
committed
AlgorithmManager* AlgorithmManager::m_instance = 0;
AlgorithmManager::AlgorithmManager() : DynamicFactory<IAlgorithm>(),
no_of_alg(0)
Dickon Champion
committed
{
std::cout<<"AlgorithmManager == "<<std::setbase(16)
<<reinterpret_cast<long>(this)
<<std::endl;
Dickon Champion
committed
}
AlgorithmManager::~AlgorithmManager()
{
std::cout<<"AlgorithmManager Delete == "<<std::setbase(16)
<<reinterpret_cast<long>(this)
<<std::endl;
clear();
}
IAlgorithm*
AlgorithmManager::createUnmanaged(const std::string& algName) const
/*!
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
*/
{
return DynamicFactory<IAlgorithm>::create(algName); // Throws on fail:
Dickon Champion
committed
}
IAlgorithm* AlgorithmManager::create(const std::string& algName)
/*!
@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
committed
{
regAlg.push_back(DynamicFactory<IAlgorithm>::create(algName)); // Throws on fail:
StatusCode status = regAlg.back()->initialize();
if (status.isFailure())
Dickon Champion
committed
{
throw std::runtime_error("AglorithmManager:: Unable to initialise algorithm " + algName);
Dickon Champion
committed
}
Dickon Champion
committed
}
AlgorithmManager* AlgorithmManager::Instance()
{
Dickon Champion
committed
return m_instance;
}
void AlgorithmManager::clear()
Dickon Champion
committed
{
int errOut(0);
std::vector<IAlgorithm*>::iterator vc;
for(vc=regAlg.begin();vc!=regAlg.end();vc++)
{
// no test for zero since impossible
StatusCode status = (*vc)->finalize();
errOut+= status.isFailure();
delete (*vc);
Dickon Champion
committed
}
regAlg.clear();
no_of_alg=0;
if (errOut)
throw std::runtime_error("AlgorithmManager:: Unable to finalise algorithm " );
return;
}
Russell Taylor
committed
} // namespace Kernel
} // namespace Mantid