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 
14 using namespace std;
15 
16 namespace openm
17 {
19  enum class ExitStatus : int
20  {
22  OK = 0,
23 
25  FAIL = 1,
26 
28  HELPER_ERROR = 4,
29 
31  MSG_ERROR = 8,
32 
34  DB_ERROR = 12,
35 
37  MODEL_ERROR = 16,
38 
40  SIMULATION_ERROR = 32
41  };
42 
44  enum class ModelStatus : int
45  {
47  undefined = 0,
48 
50  init = 1,
51 
53  progress,
54 
57 
59  shutdown,
60 
62  done = 64,
63 
65  exit,
66 
68  error = 128
69  };
70 
72  struct RunStatus
73  {
75  static const char * init;
76 
78  static const char * progress;
79 
81  static const char * waitProgress;
82 
84  static const char * done;
85 
87  static const char * exit;
88 
90  static const char * error;
91  };
92 
94  struct RunState
95  {
98 
101 
104 
106  chrono::system_clock::time_point startTime;
107 
109  chrono::system_clock::time_point updateTime;
110 
112  RunState(void);
113 
115  bool operator==(const RunState & i_other) const;
116 
118  static bool isFinal(ModelStatus i_status) { return i_status >= ModelStatus::done; }
119 
121  static bool isError(ModelStatus i_status) { return i_status >= ModelStatus::error; }
122 
124  static bool isShutdownOrFinal(ModelStatus i_status) { return i_status == ModelStatus::shutdown || isFinal(i_status); }
125 
127  static ModelStatus fromRunStatus(const string & i_runStatus);
128 
130  static string toRunStatus(ModelStatus i_modelStatus);
131 
133  ModelStatus setStatus(ModelStatus i_status);
134 
136  void setProgress(int i_count, double i_value);
137  };
138 
140  struct IModelRunState : public IFinalState
141  {
142  virtual ~IModelRunState(void) noexcept = 0;
143 
145  virtual ModelStatus status(void) = 0;
146 
148  virtual bool isShutdownOrFinal(void) = 0;
149 
151  virtual RunState get(void) = 0;
152 
154  virtual ModelStatus updateStatus(ModelStatus i_status) = 0;
155 
157  virtual void updateProgress(int i_count, double i_value = 0.0) = 0;
158  };
159 
161  struct RunStateItem : public IRowBase
162  {
164  int runId;
165 
167  int subId;
168 
171 
173  RunStateItem(int i_runId, int i_subId, const RunState i_state) : runId(i_runId), subId(i_subId), state(i_state) {}
174  RunStateItem(void) : RunStateItem(0, 0, RunState()) {}
175  };
176 }
177 
178 #endif // OM_H_MODEL_RUN_STATE_H
RunState state
run state data for the sub-value
Definition: omModelRunState.h:170
run in progress, under external supervision
static bool isFinal(ModelStatus i_status)
return true if status is one of exiting: ie done, exit, error
Definition: omModelRunState.h:118
chrono::system_clock::time_point updateTime
last update time
Definition: omModelRunState.h:109
model run state public interface: thread safe
Definition: omModelRunState.h:140
static const char * waitProgress
w = wait: run in progress, under external supervision
Definition: omModelRunState.h:81
db-row abstract base
Definition: omHelper.h:181
final model run state public interface: thread safe
Definition: omHelper.h:196
messaging exception: message passing (MPI) error
database exception: database error from openM++ runtime or database vendor
helper exception: low level error from openM++ runtime
static bool isShutdownOrFinal(ModelStatus i_status)
return true if model in shutdown state: modeling completed or one of exiting
Definition: omModelRunState.h:124
ModelStatus
modeling job status
Definition: omModelRunState.h:44
static bool isError(ModelStatus i_status)
return true if status is an error
Definition: omModelRunState.h:121
simulation exception raised in model code
model run status codes
Definition: omModelRunState.h:72
model exception: top level error from openM++ runtime
openM++ namespace
Definition: argReader.cpp:16
int subId
sub-value id
Definition: omModelRunState.h:167
run state data for sub-value identified by run id and sub-value id
Definition: omModelRunState.h:161
model run state data: status, progress, update times
Definition: omModelRunState.h:94
static const char * progress
p = run in progress
Definition: omModelRunState.h:78
int runId
if >0 then model run id
Definition: omModelRunState.h:164
completed successfully
exit and not completed (reserved)
static const char * done
s = completed successfully
Definition: omModelRunState.h:84
static const char * exit
x = exit and not completed (reserved)
Definition: omModelRunState.h:87
static const char * error
e = error failure
Definition: omModelRunState.h:90
int progressCount
progress count, usually percent completed
Definition: omModelRunState.h:100
static const char * init
i = initial status
Definition: omModelRunState.h:75
RunStateItem(int i_runId, int i_subId, const RunState i_state)
initialize run state data for sub-value
Definition: omModelRunState.h:173
ModelStatus theStatus
current status
Definition: omModelRunState.h:97
chrono::system_clock::time_point startTime
process start time
Definition: omModelRunState.h:106
undefined aggregation function
double progressValue
progress value: number of cases or time completed
Definition: omModelRunState.h:103
ExitStatus
model exit status
Definition: omModelRunState.h:19
OpenM++ common helper utilities.
completed successfully
shutdown model process