Mercurial > hg > orthanc
annotate OrthancFramework/Sources/JobsEngine/JobInfo.cpp @ 5657:dedbf019a707
Improved parsing of multiple numerical values in DICOM tags
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 06 Jun 2024 17:55:13 +0200 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
2569 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2569 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
12 * the License, or (at your option) any later version. |
2569 | 13 * |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * Lesser General Public License for more details. |
2569 | 18 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
2569 | 22 **/ |
23 | |
24 | |
25 #include "../PrecompiledHeaders.h" | |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
26 |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
27 #ifdef __EMSCRIPTEN__ |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
28 /* |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
29 Avoid this error: |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
30 |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
31 .../boost/math/special_functions/round.hpp:118:12: warning: implicit conversion from 'std::__2::numeric_limits<long long>::type' (aka 'long long') to 'float' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion] |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
32 .../boost/math/special_functions/round.hpp:125:11: note: in instantiation of function template specialization 'boost::math::llround<float, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >' requested here |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
33 .../orthanc/Core/JobsEngine/JobInfo.cpp:69:44: note: in instantiation of function template specialization 'boost::math::llround<float>' requested here |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
34 |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
35 .../boost/math/special_functions/round.hpp:86:12: warning: implicit conversion from 'std::__2::numeric_limits<int>::type' (aka 'int') to 'float' changes value from 2147483647 to 2147483648 [-Wimplicit-int-float-conversion] |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
36 .../boost/math/special_functions/round.hpp:93:11: note: in instantiation of function template specialization 'boost::math::iround<float, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >' requested here |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
37 .../orthanc/Core/JobsEngine/JobInfo.cpp:133:39: note: in instantiation of function template specialization 'boost::math::iround<float>' requested here |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
38 */ |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
39 #pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion" |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
40 #endif |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
41 |
2569 | 42 #include "JobInfo.h" |
43 | |
44 #include "../OrthancException.h" | |
45 | |
2593 | 46 // This "include" is mandatory for Release builds using Linux Standard Base |
47 #include <boost/math/special_functions/round.hpp> | |
48 | |
2569 | 49 namespace Orthanc |
50 { | |
51 JobInfo::JobInfo(const std::string& id, | |
52 int priority, | |
53 JobState state, | |
54 const JobStatus& status, | |
55 const boost::posix_time::ptime& creationTime, | |
56 const boost::posix_time::ptime& lastStateChangeTime, | |
57 const boost::posix_time::time_duration& runtime) : | |
58 id_(id), | |
59 priority_(priority), | |
60 state_(state), | |
61 timestamp_(boost::posix_time::microsec_clock::universal_time()), | |
62 creationTime_(creationTime), | |
63 lastStateChangeTime_(lastStateChangeTime), | |
64 runtime_(runtime), | |
65 hasEta_(false), | |
66 status_(status) | |
67 { | |
68 if (state_ == JobState_Running) | |
69 { | |
70 float ms = static_cast<float>(runtime_.total_milliseconds()); | |
71 | |
72 if (status_.GetProgress() > 0.01f && | |
73 ms > 0.01f) | |
74 { | |
4767
e1711b6e141f
Fix computation of the estimated time of arrival in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4667
diff
changeset
|
75 float progress = status_.GetProgress(); |
e1711b6e141f
Fix computation of the estimated time of arrival in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4667
diff
changeset
|
76 long long remaining = boost::math::llround(ms / progress * (1.0f - progress)); |
2569 | 77 eta_ = timestamp_ + boost::posix_time::milliseconds(remaining); |
78 hasEta_ = true; | |
79 } | |
80 } | |
81 } | |
82 | |
83 | |
84 JobInfo::JobInfo() : | |
85 priority_(0), | |
86 state_(JobState_Failure), | |
87 timestamp_(boost::posix_time::microsec_clock::universal_time()), | |
88 creationTime_(timestamp_), | |
89 lastStateChangeTime_(timestamp_), | |
90 runtime_(boost::posix_time::milliseconds(0)), | |
91 hasEta_(false) | |
92 { | |
93 } | |
94 | |
4300 | 95 const std::string &JobInfo::GetIdentifier() const |
96 { | |
97 return id_; | |
98 } | |
99 | |
100 int JobInfo::GetPriority() const | |
101 { | |
102 return priority_; | |
103 } | |
104 | |
105 JobState JobInfo::GetState() const | |
106 { | |
107 return state_; | |
108 } | |
109 | |
110 const boost::posix_time::ptime &JobInfo::GetInfoTime() const | |
111 { | |
112 return timestamp_; | |
113 } | |
114 | |
115 const boost::posix_time::ptime &JobInfo::GetCreationTime() const | |
116 { | |
117 return creationTime_; | |
118 } | |
119 | |
120 const boost::posix_time::time_duration &JobInfo::GetRuntime() const | |
121 { | |
122 return runtime_; | |
123 } | |
124 | |
125 bool JobInfo::HasEstimatedTimeOfArrival() const | |
126 { | |
127 return hasEta_; | |
128 } | |
129 | |
2569 | 130 |
131 bool JobInfo::HasCompletionTime() const | |
132 { | |
133 return (state_ == JobState_Success || | |
134 state_ == JobState_Failure); | |
135 } | |
136 | |
137 | |
138 const boost::posix_time::ptime& JobInfo::GetEstimatedTimeOfArrival() const | |
139 { | |
140 if (hasEta_) | |
141 { | |
142 return eta_; | |
143 } | |
144 else | |
145 { | |
146 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
147 } | |
148 } | |
149 | |
150 | |
151 const boost::posix_time::ptime& JobInfo::GetCompletionTime() const | |
152 { | |
153 if (HasCompletionTime()) | |
154 { | |
155 return lastStateChangeTime_; | |
156 } | |
157 else | |
158 { | |
159 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
160 } | |
161 } | |
162 | |
4300 | 163 const JobStatus &JobInfo::GetStatus() const |
164 { | |
165 return status_; | |
166 } | |
167 | |
168 JobStatus &JobInfo::GetStatus() | |
169 { | |
170 return status_; | |
171 } | |
172 | |
2569 | 173 |
2647
73d7d95dd75e
removal of internal job information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2593
diff
changeset
|
174 void JobInfo::Format(Json::Value& target) const |
2569 | 175 { |
176 target = Json::objectValue; | |
177 target["ID"] = id_; | |
178 target["Priority"] = priority_; | |
179 target["ErrorCode"] = static_cast<int>(status_.GetErrorCode()); | |
180 target["ErrorDescription"] = EnumerationToString(status_.GetErrorCode()); | |
4667
08ee98bf103e
"/jobs/..." has new field "ErrorDetails" to help identify the cause of an error
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
181 target["ErrorDetails"] = status_.GetDetails(); |
2569 | 182 target["State"] = EnumerationToString(state_); |
183 target["Timestamp"] = boost::posix_time::to_iso_string(timestamp_); | |
184 target["CreationTime"] = boost::posix_time::to_iso_string(creationTime_); | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
185 target["EffectiveRuntime"] = static_cast<double>(runtime_.total_milliseconds()) / 1000.0; |
2569 | 186 target["Progress"] = boost::math::iround(status_.GetProgress() * 100.0f); |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
187 |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
188 target["Type"] = status_.GetJobType(); |
2647
73d7d95dd75e
removal of internal job information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2593
diff
changeset
|
189 target["Content"] = status_.GetPublicContent(); |
2569 | 190 |
191 if (HasEstimatedTimeOfArrival()) | |
192 { | |
193 target["EstimatedTimeOfArrival"] = boost::posix_time::to_iso_string(GetEstimatedTimeOfArrival()); | |
194 } | |
195 | |
196 if (HasCompletionTime()) | |
197 { | |
198 target["CompletionTime"] = boost::posix_time::to_iso_string(GetCompletionTime()); | |
199 } | |
200 } | |
201 } |