Mantid
Loading...
Searching...
No Matches
Progress.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//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
10#include "MantidAPI/Progress.h"
11#include "MantidAPI/Algorithm.h"
12
13namespace Mantid::API {
14
15namespace {
16void checkEnd(double end) {
17 if (end > 1.) {
18 std::stringstream msg;
19 msg << "Progress range invalid. end=" << end;
20 throw std::invalid_argument(msg.str());
21 }
22}
23} // namespace
24
28Progress::Progress() : ProgressBase(0.0, 1.0, 0), m_alg(nullptr) {}
29
36Progress::Progress(Algorithm *alg, double start, double end, int numSteps)
37 : ProgressBase(start, end, int64_t(numSteps)), m_alg(alg) {
38 checkEnd(end);
39}
40
47Progress::Progress(Algorithm *alg, double start, double end, int64_t numSteps)
48 : ProgressBase(start, end, int64_t(numSteps)), m_alg(alg) {
49 checkEnd(end);
50}
51
58Progress::Progress(Algorithm *alg, double start, double end, size_t numSteps)
59 : ProgressBase(start, end, int64_t(numSteps)), m_alg(alg) {
60 checkEnd(end);
61}
62
70void Progress::doReport(const std::string &msg) {
71 // Progress as a float
72 // must be between 0 and 1
73 double p = m_start + m_step * double(m_i - m_ifirst);
74 if (p > m_end)
75 p = m_end;
76 if (!m_alg)
77 return;
80}
81
86 if (m_alg)
87 return m_alg->getCancel();
88 else
89 return false;
90}
91
92} // namespace Mantid::API
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
Definition: Algorithm.cpp:1687
bool getCancel() const
Returns the cancellation state.
Definition: Algorithm.cpp:1657
Algorithm *const m_alg
Owning algorithm.
Definition: Progress.h:36
Progress()
Default constructor.
Definition: Progress.cpp:28
void doReport(const std::string &msg="") override
Actually do the reporting, without changing the loop counter.
Definition: Progress.cpp:70
bool hasCancellationBeenRequested() const override
Definition: Progress.cpp:85
double m_end
Ending progress.
Definition: ProgressBase.h:73
int64_t m_ifirst
Loop counter initial value.
Definition: ProgressBase.h:75
double m_step
Progress increment at each loop.
Definition: ProgressBase.h:84
int m_notifyStepPrecision
Digits of precision in the reporting.
Definition: ProgressBase.h:92
double getEstimatedTime() const
Returns the estimated number of seconds until the algorithm completes.
double m_start
Starting progress.
Definition: ProgressBase.h:71
std::atomic< int64_t > m_i
Loop counter.
Definition: ProgressBase.h:86