8#include "MantidKernel/DllConfig.h"
16using Mantid::Types::Core::DateAndTime;
29template <
typename TYPE>
38template <
typename HeldType>
42 m_filterIntervals(), m_filterApplied(false) {
44 this->filterWith(&filterProp);
47template <
typename HeldType>
49 const std::vector<Types::Core::DateAndTime> ×,
50 const std::vector<HeldType> &values)
52 m_filterIntervals(), m_filterApplied(false) {}
54template <
typename HeldType>
57 m_filterIntervals(), m_filterApplied(false) {}
65template <
typename HeldType>
69 m_filterIntervals(), m_filterApplied(false) {
71 this->filterWith(&filterProp);
81template <
typename HeldType>
84 m_filter(
std::make_unique<
TimeROI>(*prop.m_filter.get())), m_filterMap(prop.m_filterMap),
85 m_filterIntervals(prop.m_filterIntervals), m_filterApplied(prop.m_filterApplied) {}
98template <
typename TYPE>
101 if (this->m_filter->useAll()) {
105 const auto internalRoi = this->intersectFilterWithOther(roi);
119template <
typename TYPE>
121 if (m_filter->useAll()) {
124 const auto internalRoi = this->intersectFilterWithOther(roi);
144 if (this->m_values.empty()) {
145 const std::string
error(
"nthInterval(): FilteredTimeSeriesProperty '" + this->
name() +
"' is empty");
147 throw std::runtime_error(
error);
152 if (m_filter->useAll()) {
158 if (n < 0 || n >=
static_cast<int>(this->m_filterIntervals.size())) {
159 const std::string
error(
"nthInterval(): FilteredTimeSeriesProperty '" + this->
name() +
"' interval " +
162 throw std::runtime_error(
error);
164 deltaT = this->m_filterIntervals[std::size_t(
n)];
171 const auto interval = this->nthInterval(
n);
172 return interval.start();
183 if (this->m_values.empty()) {
184 const std::string
error(
"nthValue(): FilteredTimeSeriesProperty '" + this->
name() +
"' is empty");
186 throw std::runtime_error(
error);
190 if (m_filter->useAll()) {
197 if (m_filterMap.empty()) {
199 value = this->m_values.back().value();
202 const size_t n_index = std::min<size_t>(
static_cast<size_t>(
n), m_filterMap.size() - 1);
203 value = this->m_values[m_filterMap[n_index]].value();
228 if ((!filter) || (filter->
size() == 0)) {
232 this->clearFilterCache();
235 DateAndTime endTime = this->getFakeEndTime();
239 filterModified->
addValue(endTime,
false);
241 m_filter->replaceROI(filterModified);
243 m_filter->replaceROI(filter);
255 this->clearFilterCache();
256 m_filter->replaceROI(filter);
272 this->clearFilterCache();
276 m_filterApplied =
false;
278 m_filterIntervals.clear();
285 if (m_filter->useAll()) {
287 this->
m_size = int(this->m_values.size());
291 this->
m_size = int(m_filterMap.empty() ? this->m_values.size() : m_filterMap.size());
314 this->clearFilterCache();
316 if (m_filter->useAll())
320 this->sortIfNecessary();
323 std::size_t index_current_log{0};
325 for (
const auto &splitter : m_filter->toTimeIntervals()) {
326 const auto endTime = splitter.stop();
329 if (endTime < this->m_values[index_current_log].time()) {
334 const auto beginTime = splitter.start();
337 if (this->m_values.back().time() < beginTime) {
339 index_current_log = this->m_values.size() - 1;
342 while ((this->m_values[index_current_log].time() <= beginTime)) {
343 if (index_current_log + 1 > this->m_values.size())
348 if (index_current_log > 0)
351 while (index_current_log > 0 &&
352 this->m_values[index_current_log].time() == this->m_values[index_current_log - 1].time()) {
358 for (; index_current_log < this->m_values.size(); ++index_current_log) {
359 if (this->m_values[index_current_log].time() >= endTime)
363 m_filterMap.emplace_back(index_current_log);
366 DateAndTime myEndTime(endTime);
367 if (index_current_log + 1 < this->m_values.size())
368 myEndTime = std::min(endTime, this->m_values[index_current_log + 1].time());
370 m_filterIntervals.emplace_back(
371 TimeInterval(std::max(beginTime, this->m_values[index_current_log].time()), myEndTime));
374 if (index_current_log > 0)
379 m_filterApplied =
true;
395 return "Could not set value: properties have different type.";
398 this->
m_size = prop->m_size;
399 this->m_propSortedFlag = prop->m_propSortedFlag;
400 m_filter = std::unique_ptr<TimeROI>(prop->m_filter.get());
401 m_filterMap = prop->m_filterMap;
402 m_filterApplied = prop->m_filterApplied;
410template <
typename TYPE>
412 auto roi =
new TimeROI(*m_filter.get());
413 if (other && (!other->useAll()))
419 return *(this->m_filter.get());
428 if (m_filter->useAll()) {
432 if (!m_filterApplied) {
436 return m_filter->toTimeIntervals();
440template <
typename HeldType>
442 const TimeROI *roi = intersectFilterWithOther(timeRoi);
454template <
typename HeldType>
457 if (!time_and_value_compare) {
463 if (m_filter->useAll()) {
466 return time_and_value_compare;
473 return m_filter == rhs_ftsp->
m_filter;
488#define INSTANTIATE(TYPE) template class FilteredTimeSeriesProperty<TYPE>;
size_t m_size
Maximum size of the store.
double value
The value of the point.
#define INSTANTIATE(TYPE)
Marks code as not implemented yet.
Templated class that defines a filtered time series but still gives access to the original data.
std::string setValueFromProperty(const Property &right) override
Set a value from another property.
std::unique_ptr< TimeROI > m_filter
The filter.
std::vector< HeldType > filteredValuesAsVector() const override
const Kernel::TimeROI & getTimeROI() const
TimeInterval nthInterval(int n) const override
Returns n-th valid time interval, in a very inefficient way.
HeldType nthValue(int n) const override
Returns n-th value of n-th interval in an incredibly inefficient way.
void filterWith(const TimeSeriesProperty< bool > *filter)
Divide the property into allowed and disallowed time intervals according to a filter.
double timeAverageValue(const TimeROI *timeRoi=nullptr) const override
Returns the calculated time weighted average value.
std::vector< Mantid::Kernel::TimeInterval > getTimeIntervals() const override
If filtering by log, get the time intervals for splitting.
TimeROI * intersectFilterWithOther(const TimeROI *other) const
Combines the currently held filter with the supplied one as an intersection.
std::vector< Types::Core::DateAndTime > filteredTimesAsVector() const override
void applyFilter() const
Apply a filter.
FilteredTimeSeriesProperty< HeldType > * clone() const override
"Virtual" copy constructor
Types::Core::DateAndTime nthTime(int n) const override
Returns n-th time. NOTE: Complexity is order(n)! regardless of filter.
FilteredTimeSeriesProperty()=delete
Disable default constructor.
void clearFilter() const
Restores the property to the unsorted state.
int size() const override
Return the size of this property.
void countSize() const
Updates size()
~FilteredTimeSeriesProperty() override
Destructor.
const TimeSeriesProperty< HeldType > * unfiltered() const
Access the unfiltered log.
bool operator==(const TimeSeriesProperty< HeldType > &right) const override
void clearFilterCache() const
Clear out the applied filter.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
Base class for properties.
Represents a time interval.
TimeROI : Object that holds information about when the time measurement was active.
bool useAll() const
TimeROI selects all time to be used.
void update_or_replace_intersection(const TimeROI &other)
If this is empty, replace it with the supplied TimeROI, otherwise calculate the intersection.
A specialised Property class for holding a series of time-value pairs.
TimeSeriesProperty< TYPE > * clone() const override
"Virtual" copy constructor
int size() const override
Returns the number of values at UNIQUE time intervals in the time series.
TYPE firstValue() const
Returns the first value regardless of filter.
double timeAverageValue(const TimeROI *timeRoi=nullptr) const override
Returns the calculated time weighted average value.
virtual std::vector< Types::Core::DateAndTime > filteredTimesAsVector() const
void addValue(const Types::Core::DateAndTime &time, const TYPE &value)
Add a value to the map using a DateAndTime object.
TYPE lastValue() const
Returns the last value.
std::vector< TimeValueUnit< TYPE > > m_values
Holds the time series data.
virtual bool operator==(const TimeSeriesProperty< TYPE > &right) const
Deep comparison.
virtual std::vector< Mantid::Kernel::TimeInterval > getTimeIntervals() const
If filtering by log, get the time intervals for splitting.
virtual TYPE nthValue(int n) const
Returns n-th value of n-th interval in an incredibly inefficient way.
virtual TimeInterval nthInterval(int n) const
Returns n-th valid time interval, in a very inefficient way.
virtual std::vector< TYPE > filteredValuesAsVector() const
Logger g_log("DateAndTime")
MANTID_KERNEL_DLL bool operator==(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs)
Compares this to another property for equality.
std::string to_string(const wide_integer< Bits, Signed > &n)