Newer
Older
Russell Taylor
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef ALGORITHM_H_
#define ALGORITHM_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "IAlgorithm.h"
#include "MsgStream.h"
#include <vector>
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION "unknown"
#endif
namespace Mantid
{
/** @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 initialize(), execute() and finalize()
should be overridden.
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 ???RAL???
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>
*/
class Algorithm : virtual public IAlgorithm
Russell Taylor
committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{
public:
/** Constructor
* @param name The algorithm object's name
* @param svcloc A pointer to a service location service (RJT: not yet)
*/
Algorithm( const std::string& name, //ISvcLocator *svcloc,
const std::string& version=PACKAGE_VERSION );
/// Virtual destructor
virtual ~Algorithm();
/** The identifying name of the algorithm object. This is the name of a
* particular instantiation of an algorithm object as opposed to the name
* of the algorithm itself, e.g. "LinearTrackFit" may be the name of a
* concrete algorithm class,
* whereas "ApproxTrackFit" and "BestTrackFit" may be two instantiations
* of the class configured to find tracks with different fit criteria.
*/
virtual const std::string& name() const;
// IAlgorithm methods
virtual const std::string& version() const;
/** Initialization method invoked by the framework. This method is responsible
* for any bookkeeping of initialization required by the framework itself.
* It will in turn invoke the initialize() method of the derived algorithm,
* and of any sub-algorithms which it creates.
*/
virtual StatusCode initialize();
/** The actions to be performed by the algorithm on an event. This method is
* invoked once per event for top level algorithms by the application
* manager.
* This method invokes execute() method.
* For sub-algorithms either the sysExecute() method or execute() method
* must be EXPLICITLY invoked by the parent algorithm.
*/
virtual StatusCode execute();
/** System finalization. This method invokes the finalize() method of a
* concrete algorithm and the finalize() methods of all of that algorithm's
* sub algorithms.
*/
virtual StatusCode finalize();
/// Has the Algorithm already been initialized?
// Protected in Gaudi version
virtual bool isInitialized() const;
/// Has this algorithm been executed since the last reset?
virtual bool isExecuted() const;
/// Has the Algorithm already been finalized?
// Protected in Gaudi version
virtual bool isFinalized() const;
/** Create a sub algorithm.
* A call to this method creates a child algorithm object.
* Note that the returned pointer is to Algorithm
* (as opposed to IAlgorithm), and thus the methods of IProperty
* are also available for the direct setting of the sub-algorithm's
* properties. Using this mechanism instead of creating daughter
* algorithms directly via the new operator is prefered since then
* the framework may take care of all of the necessary book-keeping.
* @param type The concrete algorithm class of the sub algorithm
* @param name The name to be given to the sub algorithm
* @param pSubAlg Set to point to the newly created algorithm object
*/
// Need Algorithm manager/factory before this can be implemented.
StatusCode createSubAlgorithm( const std::string& type,
const std::string& name, Algorithm*& pSubAlg );
/// List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms
std::vector<Algorithm*>* subAlgorithms() const;
/// Implementation of IProperty::setProperty
// virtual StatusCode setProperty( const Property& p );
/// Implementation of IProperty::setProperty
virtual StatusCode setProperty( const std::string& s );
/// Implementation of IProperty::setProperty
virtual StatusCode setProperty( const std::string& n, const std::string& v);
/// Implementation of IProperty::getProperty
// virtual StatusCode getProperty(Property* p) const;
/// Implementation of IProperty::getProperty
// virtual const Property& getProperty( const std::string& name) const;
/// Implementation of IProperty::getProperty
virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
/// Implementation of IProperty::getProperties
// virtual const std::vector<Property*>& getProperties( ) const;
Russell Taylor
committed
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
protected:
// Equivalents of Gaudi's initialize, execute & finalize methods
// Can these be made pure virtual???
/// the default (empty) implementation of the init() method
virtual StatusCode init () { return StatusCode::SUCCESS ; }
/// the default (empty) implementation of the exec() method
virtual StatusCode exec () { return StatusCode::SUCCESS ; }
/// the default (empty) implementation of the final() method
virtual StatusCode final() { return StatusCode::SUCCESS ; }
/// Set the Algorithm initialized state
void setInitialized();
/// Set the executed flag to the specified state
// Public in Gaudi - don't know why and will leave here unless we find a reason otherwise
// Also don't know reason for different return type and argument.
void setExecuted( bool state );
/// Set the Algorithm finalized state
void setFinalized();
private:
/// Private Copy constructor: NO COPY ALLOWED
Algorithm(const Algorithm& a);
/// Private asignment operator: NO ASSIGNMENT ALLOWED
Algorithm& operator=(const Algorithm& rhs);
std::string m_name; ///< Algorithm's name for identification
std::string m_version; ///< Algorithm's version
std::vector<Algorithm *>* m_subAlgms; ///< Sub algorithms
bool m_isInitialized; ///< Algorithm has been initialized flag
bool m_isExecuted; ///< Algorithm is executed flag
bool m_isFinalized; ///< Algorithm has been finalized flag
// Dummy method so that I don't have to change code before our Message Service exists.
int msgSvc() {return 0;}
};
}
#endif /*ALGORITHM_H_*/