Mantid
Loading...
Searching...
No Matches
ProgressBase.h
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#pragma once
8
9#include "MantidKernel/DllConfig.h"
10
11#include <atomic>
12#include <memory>
13#include <string>
14
15namespace Mantid {
16namespace Kernel {
17//---------------------------------------------------------------------------
18// Forward Declarations
19//---------------------------------------------------------------------------
20class Timer;
21
30class MANTID_KERNEL_DLL ProgressBase {
31public:
33 ProgressBase(double start, double end, int64_t numSteps);
34 ProgressBase(const ProgressBase &source);
35 ProgressBase &operator=(const ProgressBase &rhs);
36 virtual ~ProgressBase();
37
39 virtual void doReport(const std::string &msg = "") = 0;
42 virtual bool hasCancellationBeenRequested() const { return false; }
43
44 // ----------------------- Methods shared between progress reporters
45 // -----------------------
46
47 //----------------------------------------------------------------------------------------------
51 void report() {
52 // This function was put inline for highest speed.
53 if (++m_i - m_last_reported < m_notifyStep)
54 return;
55 m_last_reported.store(m_i.load());
56 this->doReport("");
57 }
58
59 void report(const std::string &msg);
60 void report(int64_t i, const std::string &msg = "");
61 void reportIncrement(int inc, const std::string &msg = "");
62 void reportIncrement(size_t inc, const std::string &msg = "");
63 void setNumSteps(int64_t nsteps);
64 void resetNumSteps(int64_t nsteps, double start, double end);
65 void setNotifyStep(double notifyStepPct);
66
67 double getEstimatedTime() const;
68
69protected:
71 double m_start;
73 double m_end;
75 int64_t m_ifirst;
77 int64_t m_numSteps;
79 int64_t m_notifyStep;
84 double m_step;
86 std::atomic<int64_t> m_i;
88 std::atomic<int64_t> m_last_reported;
90 std::unique_ptr<Kernel::Timer> m_timeElapsed;
93};
94
95} // namespace Kernel
96} // namespace Mantid
const std::vector< double > & rhs
double m_end
Ending progress.
Definition: ProgressBase.h:73
int64_t m_numSteps
Loop counter upper bound.
Definition: ProgressBase.h:77
int64_t m_ifirst
Loop counter initial value.
Definition: ProgressBase.h:75
virtual void doReport(const std::string &msg="")=0
Pure virtual method that does the progress reporting, to be overridden.
std::unique_ptr< Kernel::Timer > m_timeElapsed
Timer that is started when the progress bar is constructed.
Definition: ProgressBase.h:90
double m_step
Progress increment at each loop.
Definition: ProgressBase.h:84
virtual bool hasCancellationBeenRequested() const
Override so that the reporter can inform whether a cancellation request has been used.
Definition: ProgressBase.h:42
double m_notifyStepPct
Frequency of sending the notification (as a min percentage step, e.g.
Definition: ProgressBase.h:82
int m_notifyStepPrecision
Digits of precision in the reporting.
Definition: ProgressBase.h:92
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Definition: ProgressBase.h:51
double m_start
Starting progress.
Definition: ProgressBase.h:71
int64_t m_notifyStep
Frequency of sending the notification (every m_step times)
Definition: ProgressBase.h:79
std::atomic< int64_t > m_i
Loop counter.
Definition: ProgressBase.h:86
virtual ~ProgressBase()
Destructor.
std::atomic< int64_t > m_last_reported
Last loop counter value the was a peport.
Definition: ProgressBase.h:88
Helper class which provides the Collimation Length for SANS instruments.