/
AlgorithmHistory.h
163 lines (141 loc) · 6.28 KB
/
AlgorithmHistory.h
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
60
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef MANTID_API_ALGORITHMHISTORY_H_
#define MANTID_API_ALGORITHMHISTORY_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/PropertyHistory.h"
#include "MantidKernel/DateAndTime.h"
#include <nexus/NeXusFile.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <ctime>
#include <vector>
#include <set>
namespace Mantid
{
namespace API
{
class IAlgorithm;
class Algorithm;
class AlgorithmHistory;
typedef boost::shared_ptr<AlgorithmHistory> AlgorithmHistory_sptr;
typedef boost::shared_ptr<const AlgorithmHistory> AlgorithmHistory_const_sptr;
typedef std::set<AlgorithmHistory_sptr,
boost::function<bool(const AlgorithmHistory_const_sptr, const AlgorithmHistory_const_sptr)> > AlgorithmHistories;
/** @class AlgorithmHistory AlgorithmHistory.h API/MAntidAPI/AlgorithmHistory.h
This class stores information about the Command History used by algorithms on a workspace.
@author Dickon Champion, ISIS, RAL
@date 21/01/2008
Copyright © 2007-8 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 AlgorithmHistory
{
public:
/// History container
/// The date-and-time will be stored as the Mantid::Kernel::DateAndTime type
explicit AlgorithmHistory(const Algorithm* const alg,
const Kernel::DateAndTime& start = Kernel::DateAndTime::defaultTime(),
const double& duration = -1.0,std::size_t uexeccount = 0);
virtual ~AlgorithmHistory();
AlgorithmHistory& operator=(const AlgorithmHistory&);
AlgorithmHistory(const AlgorithmHistory&);
AlgorithmHistory(const std::string& name, int vers, const Kernel::DateAndTime& start = Kernel::DateAndTime::defaultTime(),
const double& duration = -1.0, std::size_t uexeccount = 0);
void addExecutionInfo(const Kernel::DateAndTime& start, const double& duration);
void addProperty(const std::string& name,const std::string& value,bool isdefault,
const unsigned int& direction = 99);
/// add a child algorithm history record to this history object
void addChildHistory(AlgorithmHistory_sptr childHist);
// get functions
/// get name of algorithm in history const
const std::string& name() const {return m_name;}
/// get version number of algorithm in history const
const int& version() const {return m_version;}
/// get execution duration
double executionDuration() const { return m_executionDuration;}
/// get execution date
Mantid::Kernel::DateAndTime executionDate() const {return m_executionDate;}
///get the execution count
const std::size_t& execCount() const {return m_execCount;}
/// get parameter list of algorithm in history const
const std::vector<Kernel::PropertyHistory>& getProperties() const {return m_properties;}
/// get the child histories of this history object
const AlgorithmHistories& getChildHistories() const { return m_childHistories; }
/// Retrieve a child algorithm history by index
AlgorithmHistory_const_sptr getChildAlgorithmHistory(const size_t index) const;
/// Add operator[] access
AlgorithmHistory_const_sptr operator[](const size_t index) const;
/// Retrieve the number of child algorithms
size_t childHistorySize() const;
/// print contents of object
void printSelf(std::ostream&,const int indent = 0) const;
/// Less than operator
inline bool operator<(const AlgorithmHistory &other) const
{
return (execCount() < other.execCount()) ;
}
/// Equality operator
inline bool operator==(const AlgorithmHistory &other) const
{
return (execCount() == other.execCount() &&
name() == other.name());
}
///Less than operator for pointers
inline bool compareHistory(const boost::shared_ptr<AlgorithmHistory> lhs,
const boost::shared_ptr<AlgorithmHistory> rhs)
{
return *lhs < *rhs;
}
/// Create a concrete algorithm based on a history record
boost::shared_ptr<IAlgorithm> createAlgorithm() const;
/// Create an child algorithm from a history record at a given index
boost::shared_ptr<IAlgorithm> getChildAlgorithm(const size_t index) const;
/// Write this history object to a nexus file
void saveNexus(::NeXus::File* file, int& algCount) const;
// Allow Algorithm::execute to change the exec count & duration after the algorithm was executed
friend class Algorithm;
// Set the execution count
void setExecCount(std::size_t execCount) { m_execCount = execCount; }
private:
/// The name of the Algorithm
std::string m_name;
/// The version of the algorithm
int m_version;
/// The execution date of the algorithm
Mantid::Kernel::DateAndTime m_executionDate;
/// The execution duration of the algorithm
double m_executionDuration;
/// The PropertyHistory's defined for the algorithm
std::vector<Kernel::PropertyHistory> m_properties;
///count keeps track of execution order of an algorithm
std::size_t m_execCount;
/// set of child algorithm histories for this history record
AlgorithmHistories m_childHistories;
};
struct CompareHistory
{
///Less than operator for pointers
static bool compare(const AlgorithmHistory_const_sptr lhs,
const AlgorithmHistory_const_sptr rhs)
{
return (*lhs) < (*rhs);
}
};
MANTID_API_DLL std::ostream& operator<<(std::ostream&, const AlgorithmHistory&);
} // namespace API
} // namespace Mantid
#endif /*MANTID_API_ALGORITHMHISTORY_H_*/