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::API {
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 std::unique_ptr<LogFilter> logFilter{nullptr};
74 try {
75 auto runningLog = exptRun.getTimeSeriesProperty<bool>(LogParser::statusLogName());
76 logFilter = std::make_unique<LogFilter>(*runningLog);
77 } catch (std::exception &) {
78 g_log.warning("Cannot find status log. Logs will be not be filtered by run status");
79 }
80
81 TimeSeriesProperty<bool> *currentPeriodLog = nullptr;
82 bool multiperiod = false;
83 try {
85 currentPeriodLog = exptRun.getTimeSeriesProperty<bool>(LogParser::currentPeriodLogName(period));
86 } catch (const std::exception &) {
87 g_log.warning("Cannot find period log. Logs will be not be filtered by "
88 "current period");
89 }
90
91 try {
92 // get the number of periods as the max of the periods log
93 auto periodsLog = exptRun.getTimeSeriesProperty<int>(LogParser::periodsLogName());
94 multiperiod = (periodsLog->getStatistics().maximum > 1.);
95 } catch (const std::exception &) {
96 g_log.warning("Cannot find periods log. Logs will be not be filtered by "
97 "current period");
98 }
99
100 // If there is more than 1 period filter the logs by period as well
101 if (multiperiod) {
102 if (logFilter) {
103 logFilter->addFilter(*currentPeriodLog);
104 } else if (currentPeriodLog) {
105 logFilter = std::make_unique<LogFilter>(*currentPeriodLog);
106 }
107 }
108
109 // Filter logs if we have anything to filter on
110 if (logFilter) {
111 exptRun.filterByLog(logFilter.get(), ISISRunLogs::getLogNamesExcludedFromFiltering(exptRun));
112 }
113}
114
120void ISISRunLogs::addPeriodLog(const int period, API::Run &exptRun) {
121 exptRun.addLogData(m_logParser->createPeriodLog(period));
122}
123
124std::vector<std::string> ISISRunLogs::getLogNamesExcludedFromFiltering(const API::Run &run) {
125 std::vector<std::string> retVal;
127 retVal.emplace_back(LogParser::statusLogName());
128 }
130 retVal.emplace_back(LogParser::periodsLogName());
131 }
132 const auto &props = run.getProperties();
133 for (const auto prop : props) {
134 // add all properties starting with period
135 if (prop->name().rfind("period", 0) == 0) {
136 // add if not already in the list
137 if (std::find(retVal.cbegin(), retVal.cend(), prop->name()) == retVal.cend()) {
138 retVal.emplace_back(prop->name());
139 }
140 }
141 }
142 return retVal;
143}
144
145} // namespace Mantid::API
static std::vector< std::string > getLogNamesExcludedFromFiltering(const API::Run &run)
gets the list of log names that should not be filtered
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.
void addStatusLog(API::Run &exptRun)
Adds the status log to the this run.
void addPeriodLogs(const int period, API::Run &exptRun)
Adds period related logs.
std::unique_ptr< Kernel::LogParser > m_logParser
A LogParser object.
Definition ISISRunLogs.h:48
static void applyLogFiltering(Mantid::API::Run &exptRun)
applies log filtering for a run
void addLogData(Kernel::Property *p)
Add a log entry.
Definition LogManager.h:127
bool hasProperty(const std::string &name) const
Does the property exist on the object.
int getPropertyAsIntegerValue(const std::string &name) const
Returns a property as an integer value.
Kernel::Property * getLogData(const std::string &name) const
Access a single log entry.
Definition LogManager.h:141
const std::vector< Kernel::Property * > & getProperties() const
Return all of the current properties.
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
Definition LogManager.h:91
Kernel::TimeSeriesProperty< T > * getTimeSeriesProperty(const std::string &name) const
Returns a property as a time series property.
void filterByLog(Mantid::Kernel::LogFilter *filter, const std::vector< std::string > &excludedFromFiltering=std::vector< std::string >())
Filter the run by the given log filter.
This class stores information regarding an experimental run as a series of log entries.
Definition Run.h:35
static const std::string statusLogName()
Returns the name of the log created that defines the status during a run.
Definition LogParser.h:47
static const std::string currentPeriodLogName()
Returns the name of the log that contains the current period number.
Definition LogParser.h:45
static const std::string periodsLogName()
Returns the name of the log that contains all of the periods.
Definition LogParser.h:51
void warning(const std::string &msg)
Logs at warning level.
Definition Logger.cpp:117
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