Newer
Older
#ifndef MANTID_API_LOGMANAGER_H_
#define MANTID_API_LOGMANAGER_H_
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/Cache.h"
#include "MantidKernel/PropertyManager.h"
#include "MantidKernel/Statistics.h"
#include "MantidKernel/TimeSplitter.h"
#include <vector>
namespace NeXus {
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
namespace Mantid {
namespace Kernel {
template <typename TYPE> class TimeSeriesProperty;
}
namespace API {
/**
This class contains the information about the log entries
@author Martyn Gigg, Tessella plc
@date 02/10/201
Copyright © 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
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 LogManager {
public:
/// Default constructor
LogManager();
/// Destructor. Doesn't need to be virtual as long as nothing inherits from
/// this class.
virtual ~LogManager();
/// Copy constructor
LogManager(const LogManager ©);
/// Assignment operator
const LogManager &operator=(const LogManager &rhs);
//-------------------------------------------------------------
/// Set the run start and end
void setStartAndEndTime(const Kernel::DateAndTime &start,
const Kernel::DateAndTime &end);
/// Return the run start time
const Kernel::DateAndTime startTime() const;
/// Return the run end time
const Kernel::DateAndTime endTime() const;
//-------------------------------------------------------------
/// Filter the logs by time
virtual void filterByTime(const Kernel::DateAndTime start,
const Kernel::DateAndTime stop);
/// Split the logs based on the given intervals
virtual void splitByTime(Kernel::TimeSplitterType &splitter,
std::vector<LogManager *> outputs) const;
/// Filter the run by the given boolean log
void filterByLog(const Kernel::TimeSeriesProperty<bool> &filter);
/// Return an approximate memory size for the object in bytes
virtual size_t getMemorySize() const;
/// Add data to the object in the form of a property
void addProperty(Kernel::Property *prop, bool overwrite = false);
/// Add a property of given type
template <class TYPE>
void addProperty(const std::string &name, const TYPE &value,
bool overwrite = false);
template <class TYPE>
void addProperty(const std::string &name, const TYPE &value,
const std::string &units, bool overwrite = false);
/// Does the property exist on the object
bool hasProperty(const std::string &name) const;
/// Remove a named property
void removeProperty(const std::string &name, bool delproperty = true);
/**
* Return all of the current properties
* @returns A vector of the current list of properties
*/
inline const std::vector<Kernel::Property *> &getProperties() const {
return m_manager.getProperties();
}
/// Returns a property as a time series property. It will throw if it is not
/// valid
template <typename T>
Kernel::TimeSeriesProperty<T> *
getTimeSeriesProperty(const std::string &name) const;
/// Get the value of a property as the given TYPE. Throws if the type is not
/// correct
template <typename HeldType>
HeldType getPropertyValueAsType(const std::string &name) const;
/// Returns a property as a single double value from its name
double getPropertyAsSingleValue(
const std::string &name,
Kernel::Math::StatisticType statistic = Kernel::Math::Mean) const;
/// Returns the named property as a pointer
Kernel::Property *getProperty(const std::string &name) const;
/**
* Add a log entry
* @param p :: A pointer to the property containing the log entry
*/
void addLogData(Kernel::Property *p) { addProperty(p); }
/**
* Access a single log entry
* @param name :: The name of the log entry to retrieve
* @returns A pointer to a property containing the log entry
*/
Kernel::Property *getLogData(const std::string &name) const {
return getProperty(name);
}
/**
* Access all log entries
* @returns A list of all of the log entries
*/
const std::vector<Kernel::Property *> &getLogData() const {
return getProperties();
}
/**
* Remove a named log entry
* @param name :: The name of the entry to remove
* @param delproperty :: If true, delete the log entry
*/
void removeLogData(const std::string &name, const bool delproperty = true) {
return removeProperty(name, delproperty);
}
/**
* @param name :: The name of the property
* @param statistic :: Defines how to calculate the single value from series
* (default=Mean)
* @return A log as a single value using the given statistic type
*/
double getLogAsSingleValue(
const std::string &name,
Kernel::Math::StatisticType statistic = Kernel::Math::Mean) const {
return getPropertyAsSingleValue(name, statistic);
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
200
201
202
203
204
205
206
/// Empty the values out of all TimeSeriesProperty logs
void clearTimeSeriesLogs();
/// Empty all but the last value out of all TimeSeriesProperty logs
void clearOutdatedTimeSeriesLogValues();
/// Save the run to a NeXus file with a given group name
virtual void saveNexus(::NeXus::File *file, const std::string &group,
bool keepOpen = false) const;
/// Load the run from a NeXus file with a given group name
virtual void loadNexus(::NeXus::File *file, const std::string &group,
bool keepOpen = false);
/// Clear the logs
void clearLogs();
protected:
/// A pointer to a property manager
Kernel::PropertyManager m_manager;
/// Name of the log entry containing the proton charge when retrieved using
/// getProtonCharge
static const char *PROTON_CHARGE_LOG_NAME;
private:
/// Cache type for single value logs
typedef Kernel::Cache<std::pair<std::string, Kernel::Math::StatisticType>,
double> SingleValueCache;
/// Cache for the retrieved single values
mutable SingleValueCache m_singleValueCache;
};
/// shared pointer to the logManager base class
typedef boost::shared_ptr<LogManager> LogManager_sptr;
/// shared pointer to the logManager base class (const version)
typedef boost::shared_ptr<const LogManager> LogManager_const_sptr;
/**
* Add a property of a specified type (Simply creates a Kernel::Property of that
* type
* @param name :: The name of the type
* @param value :: The value of the property
* @param overwrite :: If true, a current value is overwritten. (Default: False)
*/
template <class TYPE>
void LogManager::addProperty(const std::string &name, const TYPE &value,
bool overwrite) {
addProperty(new Kernel::PropertyWithValue<TYPE>(name, value), overwrite);
}
/**
* Add a property of a specified type (Simply creates a Kernel::Property of that
* type)
* and set its units.
* @param name :: The name of the type
* @param value :: The value of the property
* @param units :: a string giving the units of the property.
* @param overwrite :: If true, a current value is overwritten. (Default: False)
*/
template <class TYPE>
void LogManager::addProperty(const std::string &name, const TYPE &value,
const std::string &units, bool overwrite) {
Kernel::Property *newProp = new Kernel::PropertyWithValue<TYPE>(name, value);
newProp->setUnits(units);
addProperty(newProp, overwrite);
}
}
#endif // MANTID_API_LOGMANAGER_H_