-
Notifications
You must be signed in to change notification settings - Fork 122
/
Pause.cpp
77 lines (63 loc) · 2.24 KB
/
Pause.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidAlgorithms/Pause.h"
#include "MantidAPI/Algorithm.h"
#include "MantidKernel/DateAndTime.h"
#include <Poco/Thread.h>
using namespace Mantid::Kernel;
using namespace Mantid::API;
using Mantid::Types::Core::DateAndTime;
namespace Mantid {
namespace Algorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(Pause)
/// Algorithm's name for identification. @see Algorithm::name
const std::string Pause::name() const { return "Pause"; }
/// Algorithm's version for identification. @see Algorithm::version
int Pause::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string Pause::category() const { return "Utility\\Development"; }
/** Initialize the algorithm's properties.
*/
void Pause::init() {
declareProperty("Duration", 1.0,
"How long to pause, in seconds. Default 1.\n"
"Enter a negative number to pause forever until cancelled.");
}
/** Execute the algorithm.
*/
void Pause::exec() {
DateAndTime startTime = DateAndTime::getCurrentTime();
const double duration = getProperty("Duration");
// Keep going until you get cancelled
while (true) {
bool breakOut = false;
try {
// This call throws if the user presses cancel
this->interruption_point();
} catch (CancelException &) {
// Break out of the lo
breakOut = true;
g_log.notice() << "User stopped the Pause.\n";
}
if (breakOut)
break;
// Sleep for 50 msec
Poco::Thread::sleep(50);
DateAndTime now = DateAndTime::getCurrentTime();
double seconds = DateAndTime::secondsFromDuration(now - startTime);
if (duration > 0) {
// Break when you've waited long enough
if (seconds > duration)
break;
// Report progress for non-infinite runs
this->progress(seconds / duration, "", duration - seconds);
}
}
}
} // namespace Algorithms
} // namespace Mantid