Mantid
Loading...
Searching...
No Matches
ISISRunLogs.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 +
7// Includes
9
12
13namespace Mantid::DataHandling {
14namespace {
16Kernel::Logger g_log("ISISRunLogs");
17} // namespace
18
19using Kernel::LogFilter;
20using Kernel::LogParser;
21using Kernel::TimeSeriesProperty;
22
29 // ICP event either in form icp_event or icpevent
30 for (const auto icpLogName : {"icp_event", "icpevent"}) {
31 try {
32 Kernel::Property *icpLog = icpRun.getLogData(icpLogName);
33 m_logParser = std::make_unique<LogParser>(icpLog);
34 return;
35 } catch (std::runtime_error &) {
36 }
37 }
38 // If it does not exist then pass in a NULL log to indicate that period 1
39 // should be assumed
40 m_logParser = std::make_unique<LogParser>(nullptr);
41}
42
47void ISISRunLogs::addStatusLog(API::Run &exptRun) { exptRun.addLogData(m_logParser->createRunningLog()); }
48
54void ISISRunLogs::addPeriodLogs(const int period, API::Run &exptRun) {
55 auto periodLog = m_logParser->createPeriodLog(period);
56
57 exptRun.addProperty(periodLog);
58 exptRun.addProperty(m_logParser->createCurrentPeriodLog(period));
59 try {
60 exptRun.addLogData(m_logParser->createAllPeriodsLog());
61 } catch (const std::runtime_error &) {
62 // Already has one
63 }
64
66}
67
73 const TimeSeriesProperty<bool> *maskProp{nullptr};
74 std::unique_ptr<LogFilter> logFilter{nullptr};
75 try {
76 auto runningLog = exptRun.getTimeSeriesProperty<bool>(LogParser::statusLogName());
77 logFilter = std::make_unique<LogFilter>(*runningLog);
78 } catch (std::exception &) {
79 g_log.warning("Cannot find status log. Logs will be not be filtered by run status");
80 }
81
82 TimeSeriesProperty<bool> *currentPeriodLog = nullptr;
83 bool multiperiod = false;
84 try {
86 currentPeriodLog = exptRun.getTimeSeriesProperty<bool>(LogParser::currentPeriodLogName(period));
87 } catch (const std::exception &) {
88 g_log.warning("Cannot find period log. Logs will be not be filtered by "
89 "current period");
90 }
91
92 try {
93 // get the number of periods as the max of the periods log
94 auto periodsLog = exptRun.getTimeSeriesProperty<int>(LogParser::periodsLogName());
95 multiperiod = (periodsLog->getStatistics().maximum > 1.);
96 } catch (const std::exception &) {
97 g_log.warning("Cannot find periods log. Logs will be not be filtered by "
98 "current period");
99 }
100
101 // If there is more than 1 period filter the logs by period as well
102 if (multiperiod) {
103 if (logFilter) {
104 logFilter->addFilter(*currentPeriodLog);
105 maskProp = logFilter->filter();
106 } else
107 maskProp = currentPeriodLog;
108 } else if (logFilter) {
109 maskProp = logFilter->filter();
110 }
111
112 // Filter logs if we have anything to filter on
113 if (maskProp)
115}
116
122void ISISRunLogs::addPeriodLog(const int period, API::Run &exptRun) {
123 exptRun.addLogData(m_logParser->createPeriodLog(period));
124}
125
126std::vector<std::string> ISISRunLogs::getLogNamesExcludedFromFiltering(const API::Run &run) {
127 std::vector<std::string> retVal;
129 retVal.emplace_back(LogParser::statusLogName());
130 }
132 retVal.emplace_back(LogParser::periodsLogName());
133 }
134 const auto &props = run.getProperties();
135 for (const auto prop : props) {
136 // add all properties starting with period
137 if (prop->name().rfind("period", 0) == 0) {
138 // add if not already in the list
139 if (std::find(retVal.cbegin(), retVal.cend(), prop->name()) == retVal.cend()) {
140 retVal.emplace_back(prop->name());
141 }
142 }
143 }
144 return retVal;
145}
146
147} // namespace Mantid::DataHandling
void addLogData(Kernel::Property *p)
Add a log entry.
Definition: LogManager.h:115
bool hasProperty(const std::string &name) const
Does the property exist on the object.
Definition: LogManager.cpp:265
void filterByLog(const Kernel::TimeSeriesProperty< bool > &filter, const std::vector< std::string > &excludedFromFiltering=std::vector< std::string >())
Filter the run by the given boolean log.
Definition: LogManager.cpp:231
int getPropertyAsIntegerValue(const std::string &name) const
Returns a property as an integer value.
Definition: LogManager.cpp:381
Kernel::Property * getLogData(const std::string &name) const
Access a single log entry.
Definition: LogManager.h:129
const std::vector< Kernel::Property * > & getProperties() const
Return all of the current properties.
Definition: LogManager.cpp:287
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
Definition: LogManager.h:79
Kernel::TimeSeriesProperty< T > * getTimeSeriesProperty(const std::string &name) const
Returns a property as a time series property.
Definition: LogManager.cpp:308
This class stores information regarding an experimental run as a series of log entries.
Definition: Run.h:38
void addPeriodLog(const int period, API::Run &exptRun)
Add 'period i' log.
ISISRunLogs(const API::Run &icpRun)
Construct this object using a run that has the required ICP event log and the number of periods.
Definition: ISISRunLogs.cpp:28
std::unique_ptr< Kernel::LogParser > m_logParser
A LogParser object.
Definition: ISISRunLogs.h:48
void addStatusLog(API::Run &exptRun)
Adds the status log to the this run.
Definition: ISISRunLogs.cpp:47
void addPeriodLogs(const int period, API::Run &exptRun)
Adds period related logs.
Definition: ISISRunLogs.cpp:54
static std::vector< std::string > getLogNamesExcludedFromFiltering(const API::Run &run)
gets the list of log names that should not be filtered
static void applyLogFiltering(Mantid::API::Run &exptRun)
applies log filtering for a run
Definition: ISISRunLogs.cpp:72
static const std::string statusLogName()
Returns the name of the log created that defines the status during a run.
Definition: LogParser.h:46
static const std::string currentPeriodLogName()
Returns the name of the log that contains the current period number.
Definition: LogParser.h:44
static const std::string periodsLogName()
Returns the name of the log that contains all of the periods.
Definition: LogParser.h:50
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.
Kernel::Logger g_log("ExperimentInfo")
static logger object