Mantid
Loading...
Searching...
No Matches
LogFilterGenerator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
11
15
16namespace {
18Mantid::Kernel::Logger g_log("LogFilterGenerator");
19} // namespace
20
21namespace Mantid::API {
22
30 : m_filterType(filterType), m_run(workspace->run()) {}
31
38 : m_filterType(filterType), m_run(run) {}
39
45std::unique_ptr<LogFilter> LogFilterGenerator::generateFilter(const std::string &logName) const {
46 const auto *logData = getLogData(logName);
47 if (!logData) {
48 throw std::invalid_argument("Workspace does not contain log " + logName);
49 }
50
51 // This will throw if the log is not a numeric time series.
52 // This behaviour is what we want, so don't catch the exception
53 auto flt = std::make_unique<LogFilter>(logData);
54
55 switch (m_filterType) {
57 break; // Do nothing
59 filterByPeriod(flt.get());
60 break;
62 filterByStatus(flt.get());
63 break;
65 filterByPeriod(flt.get());
66 filterByStatus(flt.get());
67 break;
68 default:
69 break;
70 }
71
72 return flt;
73}
74
84 const auto status = dynamic_cast<Mantid::Kernel::TimeSeriesProperty<bool> *>(getLogData("running", false));
85 if (!status) {
86 return;
87 }
88 filter->addFilter(*status);
89 const auto &time_value_map = filter->data()->valueAsCorrectMap();
90 const auto &firstTime = time_value_map.begin()->first;
91 // If filter records start later than the data we add a value at the
92 // filter's front
93 if (status->firstTime() > firstTime) {
94 // add a "not running" value to the status filter
96 atStart.addValue(firstTime, false);
97 atStart.addValue(status->firstTime(), status->firstValue());
98 filter->addFilter(atStart);
99 }
100}
101
109 const auto &logs = m_run.getLogData();
110 for (const auto &log : logs) {
111 if (log->name().find("period ") == 0) {
112 try {
113 const auto periodLog = dynamic_cast<Mantid::Kernel::TimeSeriesProperty<bool> *>(log);
114 if (periodLog) {
115 filter->addFilter(*periodLog);
116 } else {
117 g_log.warning("Could not filter by period");
118 return;
119 }
120 } catch (const std::runtime_error &err) {
121 g_log.warning() << "Could not filter by period: " << err.what();
122 return;
123 }
124 break;
125 }
126 }
127}
128
136Property *LogFilterGenerator::getLogData(const std::string &logName, bool warnIfNotFound) const {
137 try {
138 const auto logData = m_run.getLogData(logName);
139 return logData;
140 } catch (const std::runtime_error &) {
141 if (warnIfNotFound)
142 g_log.warning("Could not find log value " + logName + " in workspace");
143 return nullptr;
144 }
145}
146
147} // namespace Mantid::API
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
FilterType
Types of filter that can be used.
std::unique_ptr< Mantid::Kernel::LogFilter > generateFilter(const std::string &logName) const
Generate log filter from given workspace and log name.
void filterByPeriod(Mantid::Kernel::LogFilter *filter) const
Filter log by period.
void filterByStatus(Mantid::Kernel::LogFilter *filter) const
Filter log by "running" status.
LogFilterGenerator(const FilterType filterType, const Mantid::API::MatrixWorkspace_const_sptr &workspace)
Constructor taking workspace.
Mantid::Kernel::Property * getLogData(const std::string &logName, bool warnIfNotFound=true) const
Get log data from workspace.
const FilterType m_filterType
Type of filter.
const Mantid::API::Run m_run
Run object containing logs.
Kernel::Property * getLogData(const std::string &name) const
Access a single log entry.
Definition: LogManager.h:129
This class stores information regarding an experimental run as a series of log entries.
Definition: Run.h:38
This class is for filtering TimeSeriesProperty data.
Definition: LogFilter.h:29
void addFilter(const TimeSeriesProperty< bool > &filter)
Adds a filter using boolean AND.
Definition: LogFilter.cpp:41
TimeSeriesProperty< double > * data() const
Returns reference to the filtered property.
Definition: LogFilter.h:50
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
Base class for properties.
Definition: Property.h:94
A specialised Property class for holding a series of time-value pairs.
void addValue(const Types::Core::DateAndTime &time, const TYPE &value)
Add a value to the map using a DateAndTime object.
std::map< Types::Core::DateAndTime, TYPE > valueAsCorrectMap() const
Return the time series as a correct C++ map<DateAndTime, TYPE>.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)