Newer
Older
Russell Taylor
committed
#ifndef MANTID_KERNEL_ALGORITHM_H_
#define MANTID_KERNEL_ALGORITHM_H_
Russell Taylor
committed
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "System.h"
Russell Taylor
committed
#include "IAlgorithm.h"
Dickon Champion
committed
#include "AlgorithmManager.h"
#include "Logger.h"
Russell Taylor
committed
#include <vector>
//#include <ext/hash_map>
#include <map>
Russell Taylor
committed
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION "unknown"
#endif
namespace Mantid
{
Russell Taylor
committed
namespace Kernel
{
//----------------------------------------------------------------------
//----------------------------------------------------------------------
Russell Taylor
committed
/** @class Algorithm Algorithm.h Kernel/Algorithm.h
Base class from which all concrete algorithm classes should be derived.
In order for a concrete algorithm class to do anything
useful the methods init(), exec() and final() should be overridden.
Russell Taylor
committed
Further text from Gaudi file.......
The base class provides utility methods for accessing
standard services (event data service etc.); for declaring
properties which may be configured by the job options
service; and for creating sub algorithms.
The only base class functionality which may be used in the
constructor of a concrete algorithm is the declaration of
member variables as properties. All other functionality,
i.e. the use of services and the creation of sub-algorithms,
may be used only in initialise() and afterwards (see the
Gaudi user guide).
@author Russell Taylor, Tessella Support Services plc
@author Based on the Gaudi class of the same name (see http://proj-gaudi.web.cern.ch/proj-gaudi/)
@date 12/09/2007
Copyright © 2007 STFC Rutherford Appleton Laboratories
Russell Taylor
committed
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://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
Russell Taylor
committed
*/
class DLLExport Algorithm : virtual public IAlgorithm
Russell Taylor
committed
{
virtual const std::string& name() const;
Russell Taylor
committed
// IAlgorithm methods
virtual const std::string& version() const;
StatusCode initialize();
StatusCode execute();
StatusCode finalize();
virtual bool isInitialized() const; // Protected in Gaudi version
virtual bool isExecuted() const;
virtual bool isFinalized() const;
StatusCode createSubAlgorithm( const std::string& type, const std::string& name,
Algorithm*& pSubAlg );
Russell Taylor
committed
/// List of sub-algorithms (const version). Returns a pointer to a vector of (sub) Algorithms
const std::vector<Algorithm*>& subAlgorithms() const { return m_subAlgms; }
/// List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms
std::vector<Algorithm*>& subAlgorithms() { return m_subAlgms; }
// IProperty methods
// virtual StatusCode setProperty( const Property& p );
virtual StatusCode setProperty( const std::string& );
virtual StatusCode setProperty( const std::string& n, const std::string& v );
// virtual StatusCode getProperty(Property* p) const;
// virtual const Property& getProperty( const std::string& name) const;
virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
// virtual const std::vector<Property*>& getProperties( ) const;
Russell Taylor
committed
protected:
// Equivalents of Gaudi's initialize, execute & finalize methods
Russell Taylor
committed
/// Virtual method - must be overridden by concrete algorithm
virtual StatusCode init () = 0;
/// Virtual method - must be overridden by concrete algorithm
virtual StatusCode exec () = 0;
/// Virtual method - must be overridden by concrete algorithm
virtual StatusCode final() = 0;
Russell Taylor
committed
void setInitialized();
void setExecuted( bool state );
void setFinalized();
Russell Taylor
committed
/// Workspace containing input data. Its name should be set via a property called "InputWorkspace"
Workspace* m_inputWorkspace;
/// Workspace containing the output of the algorithm. Created by the concrete algorithm.
Workspace* m_outputWorkspace;
Russell Taylor
committed
private:
/// Private Copy constructor: NO COPY ALLOWED
Algorithm( const Algorithm& a );
Russell Taylor
committed
/// Private asignment operator: NO ASSIGNMENT ALLOWED
Algorithm& operator=( const Algorithm& rhs );
Russell Taylor
committed
std::string m_name; ///< Algorithm's name for identification
std::string m_version; ///< Algorithm's version
std::vector<Algorithm *> m_subAlgms; ///< Sub algorithms
/// Static refenence to the logger class
static Logger& g_log;
Russell Taylor
committed
bool m_isInitialized; ///< Algorithm has been initialized flag
bool m_isExecuted; ///< Algorithm is executed flag
bool m_isFinalized; ///< Algorithm has been finalized flag
/** Name of workspace in which result should be placed.
* Its name should be set via a property called "OutputWorkspace".
* Only the concrete algorithm can actually create the output workspace.
*/
std::string m_outputWorkspaceName;
Russell Taylor
committed
/// Temporary way of storing properties for algorithms, in the current absence of a Property class.
// N.B. hash_map is not in the standard stl, hence the wierd namespace.
// __gnu_cxx::hash_map< std::string, std::string > m_properties;
Russell Taylor
committed
};
Russell Taylor
committed
} // namespace Kernel
} // namespace Mantid
Russell Taylor
committed
Russell Taylor
committed
#endif /*MANTID_KERNEL_ALGORITHM_H_*/