OpenM++ runtime library (libopenm)
omModelRunState.h
Go to the documentation of this file.
1
5// Copyright (c) 2013-2015 OpenM++
6// This code is licensed under the MIT license (see LICENSE.txt for details)
7
8#ifndef OM_H_MODEL_RUN_STATE_H
9#define OM_H_MODEL_RUN_STATE_H
10
11#include <chrono>
12#include "common/omHelper.h" // define IRowBase
13
14namespace openm
15{
17 enum class ExitStatus : int
18 {
20 OK = 0,
21
23 FAIL = 1,
24
26 HELPER_ERROR = 4,
27
29 MSG_ERROR = 8,
30
32 DB_ERROR = 12,
33
35 MODEL_ERROR = 16,
36
39 };
40
42 enum class ModelStatus : int
43 {
45 undefined = 0,
46
48 init = 1,
49
52
55
58
60 done = 64,
61
63 exit,
64
66 error = 128
67 };
68
70 struct RunStatus
71 {
73 static const char * init;
74
76 static const char * progress;
77
79 static const char * waitProgress;
80
82 static const char * done;
83
85 static const char * exit;
86
88 static const char * error;
89 };
90
92 struct RunState
93 {
96
99
102
104 std::chrono::system_clock::time_point startTime;
105
107 std::chrono::system_clock::time_point updateTime;
108
110 RunState(void);
111
113 bool operator==(const RunState & i_other) const;
114
116 static bool isFinal(ModelStatus i_status) { return i_status >= ModelStatus::done; }
117
119 static bool isError(ModelStatus i_status) { return i_status >= ModelStatus::error; }
120
122 static bool isShutdownOrFinal(ModelStatus i_status) { return i_status == ModelStatus::shutdown || isFinal(i_status); }
123
125 static ModelStatus fromRunStatus(const std::string & i_runStatus);
126
128 static std::string toRunStatus(ModelStatus i_modelStatus);
129
132
134 void setProgress(int i_count, double i_value);
135 };
136
139 {
140 virtual ~IModelRunState(void) noexcept = 0;
141
143 virtual ModelStatus status(void) = 0;
144
146 virtual bool isShutdownOrFinal(void) = 0;
147
149 virtual RunState get(void) = 0;
150
152 virtual ModelStatus updateStatus(ModelStatus i_status) = 0;
153
155 virtual void updateProgress(int i_count, double i_value = 0.0) = 0;
156 };
157
159 struct RunStateItem : public IRowBase
160 {
162 int runId;
163
165 int subId;
166
169
171 RunStateItem(int i_runId, int i_subId, const RunState i_state) : runId(i_runId), subId(i_subId), state(i_state) {}
172 RunStateItem(void) : RunStateItem(0, 0, RunState()) {}
173 };
174}
175
176#endif // OM_H_MODEL_RUN_STATE_H
openM++ namespace
Definition: log.h:32
@ undefined
undefined function
ExitStatus
model exit status
Definition: omModelRunState.h:18
@ HELPER_ERROR
helper exception: low level error from openM++ runtime
@ MSG_ERROR
messaging exception: message passing (MPI) error
@ DB_ERROR
database exception: database error from openM++ runtime or database vendor
@ FAIL
unknown error
@ MODEL_ERROR
model exception: top level error from openM++ runtime
@ OK
completed successfully
@ SIMULATION_ERROR
simulation exception raised in model code
ModelStatus
modeling job status
Definition: omModelRunState.h:43
@ progress
run in progress
@ shutdown
shutdown model process
@ done
completed successfully
@ waitProgress
run in progress, under external supervision
@ error
error failure
@ init
initial status
@ exit
exit and not completed (reserved)
OpenM++ common helper utilities.
final model run state public interface: thread safe
Definition: omHelper.h:246
model run state public interface: thread safe
Definition: omModelRunState.h:139
virtual void updateProgress(int i_count, double i_value=0.0)=0
set modeling progress count and value
virtual ModelStatus updateStatus(ModelStatus i_status)=0
set model status if not already set as one of final status values
virtual bool isShutdownOrFinal(void)=0
return true if model in shutdown state: modeling completed or one of exiting
virtual RunState get(void)=0
return model run state data
virtual ModelStatus status(void)=0
get model status
db-row abstract base
Definition: omHelper.h:231
model run state data: status, progress, update times
Definition: omModelRunState.h:93
RunState(void)
initialize model run state data with default values
Definition: modelRunState.cpp:40
static bool isError(ModelStatus i_status)
return true if status is an error
Definition: omModelRunState.h:119
static ModelStatus fromRunStatus(const std::string &i_runStatus)
convert run status to model status code
Definition: modelRunState.cpp:54
static std::string toRunStatus(ModelStatus i_modelStatus)
convert model status to run status code
Definition: modelRunState.cpp:67
std::chrono::system_clock::time_point startTime
process start time
Definition: omModelRunState.h:104
void setProgress(int i_count, double i_value)
set modeling progress count and value
Definition: modelRunState.cpp:81
ModelStatus setStatus(ModelStatus i_status)
set model status if not already set as one of final status values
Definition: modelRunState.cpp:96
double progressValue
progress value: number of cases or time completed
Definition: omModelRunState.h:101
ModelStatus theStatus
current status
Definition: omModelRunState.h:95
int progressCount
progress count, usually percent completed
Definition: omModelRunState.h:98
std::chrono::system_clock::time_point updateTime
last update time
Definition: omModelRunState.h:107
static bool isFinal(ModelStatus i_status)
return true if status is one of exiting: ie done, exit, error
Definition: omModelRunState.h:116
bool operator==(const RunState &i_other) const
check if two run states are equal: state, progress and update times are equal
Definition: modelRunState.cpp:46
static bool isShutdownOrFinal(ModelStatus i_status)
return true if model in shutdown state: modeling completed or one of exiting
Definition: omModelRunState.h:122
run state data for sub-value identified by run id and sub-value id
Definition: omModelRunState.h:160
RunStateItem(int i_runId, int i_subId, const RunState i_state)
initialize run state data for sub-value
Definition: omModelRunState.h:171
RunState state
run state data for the sub-value
Definition: omModelRunState.h:168
int subId
sub-value id
Definition: omModelRunState.h:165
int runId
if >0 then model run id
Definition: omModelRunState.h:162
model run status codes
Definition: omModelRunState.h:71
static const char * waitProgress
w = wait: run in progress, under external supervision
Definition: omModelRunState.h:79
static const char * init
i = initial status
Definition: omModelRunState.h:73
static const char * done
s = completed successfully
Definition: omModelRunState.h:82
static const char * error
e = error failure
Definition: omModelRunState.h:88
static const char * progress
p = run in progress
Definition: omModelRunState.h:76
static const char * exit
x = exit and not completed (reserved)
Definition: omModelRunState.h:85