Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/ArchiveJob.cpp @ 5853:4d932683049d get-scu tip
very first implementation of C-Get SCU
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 29 Oct 2024 17:25:49 +0100 |
parents | f7adfb22e20e |
children | 1980354c8113 |
rev | line source |
---|---|
2632 | 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:
5450
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2632 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
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 | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "../PrecompiledHeadersServer.h" | |
25 #include "ArchiveJob.h" | |
26 | |
4045 | 27 #include "../../../OrthancFramework/Sources/Cache/SharedArchive.h" |
28 #include "../../../OrthancFramework/Sources/Compression/HierarchicalZipWriter.h" | |
29 #include "../../../OrthancFramework/Sources/DicomParsing/DicomDirWriter.h" | |
30 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
31 #include "../../../OrthancFramework/Sources/Logging.h" | |
32 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
33 #include "../../../OrthancFramework/Sources/MultiThreading/Semaphore.h" |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
34 #include "../OrthancConfiguration.h" |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
35 #include "../ServerContext.h" |
2632 | 36 |
37 #include <stdio.h> | |
5448
2d23c92c359a
Zip of studies whose PatientName and PatientID did not contain any ASCII character are now valid
Alain Mazy <am@osimis.io>
parents:
5430
diff
changeset
|
38 #include <boost/range/algorithm/count.hpp> |
2632 | 39 |
40 #if defined(_MSC_VER) | |
41 #define snprintf _snprintf | |
42 #endif | |
43 | |
44 static const uint64_t MEGA_BYTES = 1024 * 1024; | |
45 static const uint64_t GIGA_BYTES = 1024 * 1024 * 1024; | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
46 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
47 static const char* const MEDIA_IMAGES_FOLDER = "IMAGES"; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
48 static const char* const KEY_DESCRIPTION = "Description"; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
49 static const char* const KEY_INSTANCES_COUNT = "InstancesCount"; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
50 static const char* const KEY_UNCOMPRESSED_SIZE_MB = "UncompressedSizeMB"; |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
51 static const char* const KEY_ARCHIVE_SIZE_MB = "ArchiveSizeMB"; |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
52 static const char* const KEY_UNCOMPRESSED_SIZE = "UncompressedSize"; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
53 static const char* const KEY_ARCHIVE_SIZE = "ArchiveSize"; |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
54 static const char* const KEY_TRANSCODE = "Transcode"; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
55 |
2632 | 56 |
57 namespace Orthanc | |
58 { | |
59 static bool IsZip64Required(uint64_t uncompressedSize, | |
60 unsigned int countInstances) | |
61 { | |
62 static const uint64_t SAFETY_MARGIN = 64 * MEGA_BYTES; // Should be large enough to hold DICOMDIR | |
63 static const unsigned int FILES_MARGIN = 10; | |
64 | |
65 /** | |
66 * Determine whether ZIP64 is required. Original ZIP format can | |
67 * store up to 2GB of data (some implementation supporting up to | |
68 * 4GB of data), and up to 65535 files. | |
69 * https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64 | |
70 **/ | |
71 | |
72 const bool isZip64 = (uncompressedSize >= 2 * GIGA_BYTES - SAFETY_MARGIN || | |
73 countInstances >= 65535 - FILES_MARGIN); | |
74 | |
75 LOG(INFO) << "Creating a ZIP file with " << countInstances << " files of size " | |
5430
b83192e7ad10
Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents:
5403
diff
changeset
|
76 << Toolbox::GetHumanFileSize(uncompressedSize) << " using the " |
2632 | 77 << (isZip64 ? "ZIP64" : "ZIP32") << " file format"; |
78 | |
79 return isZip64; | |
80 } | |
81 | |
82 | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
83 class ArchiveJob::InstanceLoader : public boost::noncopyable |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
84 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
85 protected: |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
86 ServerContext& context_; |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
87 bool transcode_; |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
88 DicomTransferSyntax transferSyntax_; |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
89 public: |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
90 explicit InstanceLoader(ServerContext& context, bool transcode, DicomTransferSyntax transferSyntax) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
91 : context_(context), |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
92 transcode_(transcode), |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
93 transferSyntax_(transferSyntax) |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
94 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
95 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
96 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
97 virtual ~InstanceLoader() |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
98 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
99 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
100 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
101 virtual void PrepareDicom(const std::string& instanceId) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
102 { |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
103 } |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
104 |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
105 bool TranscodeDicom(std::string& transcodedBuffer, const std::string& sourceBuffer, const std::string& instanceId) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
106 { |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
107 if (transcode_) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
108 { |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
109 std::set<DicomTransferSyntax> syntaxes; |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
110 syntaxes.insert(transferSyntax_); |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
111 |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
112 IDicomTranscoder::DicomImage source, transcoded; |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
113 source.SetExternalBuffer(sourceBuffer); |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
114 |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
115 if (context_.Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
116 { |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
117 transcodedBuffer.assign(reinterpret_cast<const char*>(transcoded.GetBufferData()), transcoded.GetBufferSize()); |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
118 return true; |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
119 } |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
120 else |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
121 { |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
122 LOG(INFO) << "Cannot transcode instance " << instanceId |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
123 << " to transfer syntax: " << GetTransferSyntaxUid(transferSyntax_); |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
124 } |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
125 } |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
126 |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
127 return false; |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
128 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
129 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
130 virtual void GetDicom(std::string& dicom, const std::string& instanceId) = 0; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
131 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
132 virtual void Clear() |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
133 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
134 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
135 }; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
136 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
137 class ArchiveJob::SynchronousInstanceLoader : public ArchiveJob::InstanceLoader |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
138 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
139 public: |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
140 explicit SynchronousInstanceLoader(ServerContext& context, bool transcode, DicomTransferSyntax transferSyntax) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
141 : InstanceLoader(context, transcode, transferSyntax) |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
142 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
143 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
144 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
145 virtual void GetDicom(std::string& dicom, const std::string& instanceId) ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
146 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
147 context_.ReadDicom(dicom, instanceId); |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
148 |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
149 if (transcode_) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
150 { |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
151 std::string transcoded; |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
152 if (TranscodeDicom(transcoded, dicom, instanceId)) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
153 { |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
154 dicom.swap(transcoded); |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
155 } |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
156 } |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
157 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
158 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
159 }; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
160 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
161 class InstanceId : public Orthanc::IDynamicObject |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
162 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
163 private: |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
164 std::string id_; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
165 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
166 public: |
4815 | 167 explicit InstanceId(const std::string& id) : id_(id) |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
168 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
169 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
170 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
171 virtual ~InstanceId() ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
172 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
173 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
174 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
175 std::string GetId() const {return id_;}; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
176 }; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
177 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
178 class ArchiveJob::ThreadedInstanceLoader : public ArchiveJob::InstanceLoader |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
179 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
180 Semaphore availableInstancesSemaphore_; |
5302
ad3cd5ec2074
Reduced the memory usage when downloading archives when "ZipLoaderThreads" > 0
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
181 Semaphore bufferedInstancesSemaphore_; |
4814
46bfa3a4fd63
fix compatibility with LSB compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4810
diff
changeset
|
182 std::map<std::string, boost::shared_ptr<std::string> > availableInstances_; |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
183 boost::mutex availableInstancesMutex_; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
184 SharedMessageQueue instancesToPreload_; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
185 std::vector<boost::thread*> threads_; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
186 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
187 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
188 public: |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
189 ThreadedInstanceLoader(ServerContext& context, size_t threadCount, bool transcode, DicomTransferSyntax transferSyntax) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
190 : InstanceLoader(context, transcode, transferSyntax), |
5302
ad3cd5ec2074
Reduced the memory usage when downloading archives when "ZipLoaderThreads" > 0
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
191 availableInstancesSemaphore_(0), |
ad3cd5ec2074
Reduced the memory usage when downloading archives when "ZipLoaderThreads" > 0
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
192 bufferedInstancesSemaphore_(3*threadCount) |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
193 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
194 for (size_t i = 0; i < threadCount; i++) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
195 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
196 threads_.push_back(new boost::thread(PreloaderWorkerThread, this)); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
197 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
198 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
199 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
200 virtual ~ThreadedInstanceLoader() |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
201 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
202 Clear(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
203 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
204 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
205 virtual void Clear() ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
206 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
207 for (size_t i = 0; i < threads_.size(); i++) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
208 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
209 instancesToPreload_.Enqueue(NULL); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
210 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
211 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
212 for (size_t i = 0; i < threads_.size(); i++) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
213 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
214 if (threads_[i]->joinable()) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
215 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
216 threads_[i]->join(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
217 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
218 delete threads_[i]; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
219 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
220 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
221 threads_.clear(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
222 availableInstances_.clear(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
223 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
224 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
225 static void PreloaderWorkerThread(ThreadedInstanceLoader* that) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
226 { |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5448
diff
changeset
|
227 static uint16_t threadCounter = 0; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5448
diff
changeset
|
228 Logging::SetCurrentThreadName(std::string("ARCH-LOAD-") + boost::lexical_cast<std::string>(threadCounter++)); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5448
diff
changeset
|
229 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
230 while (true) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
231 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
232 std::unique_ptr<InstanceId> instanceId(dynamic_cast<InstanceId*>(that->instancesToPreload_.Dequeue(0))); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
233 if (instanceId.get() == NULL) // that's the signal to exit the thread |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
234 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
235 return; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
236 } |
5302
ad3cd5ec2074
Reduced the memory usage when downloading archives when "ZipLoaderThreads" > 0
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
237 |
ad3cd5ec2074
Reduced the memory usage when downloading archives when "ZipLoaderThreads" > 0
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
238 // wait for the consumers (zip writer), no need to accumulate instances in memory if loaders are faster than writers |
ad3cd5ec2074
Reduced the memory usage when downloading archives when "ZipLoaderThreads" > 0
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
239 that->bufferedInstancesSemaphore_.Acquire(); |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
240 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
241 try |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
242 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
243 boost::shared_ptr<std::string> dicomContent(new std::string()); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
244 that->context_.ReadDicom(*dicomContent, instanceId->GetId()); |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
245 |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
246 if (that->transcode_) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
247 { |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
248 boost::shared_ptr<std::string> transcodedDicom(new std::string()); |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
249 if (that->TranscodeDicom(*transcodedDicom, *dicomContent, instanceId->GetId())) |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
250 { |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
251 dicomContent = transcodedDicom; |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
252 } |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
253 } |
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
254 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
255 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
256 boost::mutex::scoped_lock lock(that->availableInstancesMutex_); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
257 that->availableInstances_[instanceId->GetId()] = dicomContent; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
258 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
259 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
260 that->availableInstancesSemaphore_.Release(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
261 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
262 catch (OrthancException& e) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
263 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
264 boost::mutex::scoped_lock lock(that->availableInstancesMutex_); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
265 // store a NULL result to notify that we could not read the instance |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
266 that->availableInstances_[instanceId->GetId()] = boost::shared_ptr<std::string>(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
267 that->availableInstancesSemaphore_.Release(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
268 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
269 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
270 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
271 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
272 virtual void PrepareDicom(const std::string& instanceId) ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
273 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
274 instancesToPreload_.Enqueue(new InstanceId(instanceId)); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
275 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
276 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
277 virtual void GetDicom(std::string& dicom, const std::string& instanceId) ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
278 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
279 while (true) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
280 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
281 // wait for an instance to be available but this might not be the one we are waiting for ! |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
282 availableInstancesSemaphore_.Acquire(); |
5302
ad3cd5ec2074
Reduced the memory usage when downloading archives when "ZipLoaderThreads" > 0
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
283 bufferedInstancesSemaphore_.Release(); // unlock the "flow" of loaders |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
284 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
285 boost::shared_ptr<std::string> dicomContent; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
286 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
287 if (availableInstances_.find(instanceId) != availableInstances_.end()) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
288 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
289 // this is the instance we were waiting for |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
290 dicomContent = availableInstances_[instanceId]; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
291 availableInstances_.erase(instanceId); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
292 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
293 if (dicomContent.get() == NULL) // there has been an error while reading the file |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
294 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
295 throw OrthancException(ErrorCode_InexistentItem); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
296 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
297 dicom.swap(*dicomContent); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
298 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
299 if (availableInstances_.size() > 0) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
300 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
301 // we have just read the instance we were waiting for but there are still other instances available -> |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
302 // make sure the next GetDicom call does not wait ! |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
303 availableInstancesSemaphore_.Release(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
304 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
305 return; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
306 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
307 // we have not found the expected instance, simply wait for the next loader thread to signal the semaphore when |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
308 // a new instance is available |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
309 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
310 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
311 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
312 }; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
313 |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
314 // This enum defines specific resource types to be used when exporting the archive. |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
315 // It defines if we should use the PatientInfo from the Patient or from the Study. |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
316 enum ArchiveResourceType |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
317 { |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
318 ArchiveResourceType_Patient = 0, |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
319 ArchiveResourceType_PatientInfoFromStudy = 1, |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
320 ArchiveResourceType_Study = 2, |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
321 ArchiveResourceType_Series = 3, |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
322 ArchiveResourceType_Instance = 4 |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
323 }; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
324 |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
325 ResourceType GetResourceIdType(ArchiveResourceType type) |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
326 { |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
327 switch (type) |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
328 { |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
329 case ArchiveResourceType_Patient: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
330 return ResourceType_Patient; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
331 case ArchiveResourceType_PatientInfoFromStudy: // get the Patient tags from the Study id |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
332 return ResourceType_Study; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
333 case ArchiveResourceType_Study: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
334 return ResourceType_Study; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
335 case ArchiveResourceType_Series: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
336 return ResourceType_Series; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
337 case ArchiveResourceType_Instance: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
338 return ResourceType_Instance; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
339 default: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
340 throw OrthancException(ErrorCode_ParameterOutOfRange); |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
341 } |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
342 } |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
343 |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
344 ResourceType GetResourceLevel(ArchiveResourceType type) |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
345 { |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
346 switch (type) |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
347 { |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
348 case ArchiveResourceType_Patient: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
349 return ResourceType_Patient; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
350 case ArchiveResourceType_PatientInfoFromStudy: // this is actually the same level as the Patient |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
351 return ResourceType_Patient; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
352 case ArchiveResourceType_Study: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
353 return ResourceType_Study; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
354 case ArchiveResourceType_Series: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
355 return ResourceType_Series; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
356 case ArchiveResourceType_Instance: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
357 return ResourceType_Instance; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
358 default: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
359 throw OrthancException(ErrorCode_ParameterOutOfRange); |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
360 } |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
361 } |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
362 |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
363 ArchiveResourceType GetArchiveResourceType(ResourceType type) |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
364 { |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
365 switch (type) |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
366 { |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
367 case ResourceType_Patient: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
368 return ArchiveResourceType_Patient; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
369 case ArchiveResourceType_Study: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
370 return ArchiveResourceType_PatientInfoFromStudy; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
371 case ResourceType_Series: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
372 return ArchiveResourceType_Series; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
373 case ResourceType_Instance: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
374 return ArchiveResourceType_Instance; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
375 default: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
376 throw OrthancException(ErrorCode_ParameterOutOfRange); |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
377 } |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
378 } |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
379 |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
380 ArchiveResourceType GetChildResourceType(ArchiveResourceType type) |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
381 { |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
382 switch (type) |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
383 { |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
384 case ArchiveResourceType_Patient: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
385 case ArchiveResourceType_PatientInfoFromStudy: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
386 return ArchiveResourceType_Study; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
387 |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
388 case ArchiveResourceType_Study: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
389 return ArchiveResourceType_Series; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
390 |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
391 case ArchiveResourceType_Series: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
392 return ArchiveResourceType_Instance; |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
393 |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
394 default: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
395 throw OrthancException(ErrorCode_ParameterOutOfRange); |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
396 } |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
397 } |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
398 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
399 |
2632 | 400 class ArchiveJob::ResourceIdentifiers : public boost::noncopyable |
401 { | |
402 private: | |
403 ResourceType level_; | |
404 std::string patient_; | |
405 std::string study_; | |
406 std::string series_; | |
407 std::string instance_; | |
408 | |
409 static void GoToParent(ServerIndex& index, | |
410 std::string& current) | |
411 { | |
412 std::string tmp; | |
413 | |
414 if (index.LookupParent(tmp, current)) | |
415 { | |
416 current = tmp; | |
417 } | |
418 else | |
419 { | |
420 throw OrthancException(ErrorCode_UnknownResource); | |
421 } | |
422 } | |
423 | |
424 | |
425 public: | |
426 ResourceIdentifiers(ServerIndex& index, | |
427 const std::string& publicId) | |
428 { | |
429 if (!index.LookupResourceType(level_, publicId)) | |
430 { | |
431 throw OrthancException(ErrorCode_UnknownResource); | |
432 } | |
433 | |
434 std::string current = publicId;; | |
435 switch (level_) // Do not add "break" below! | |
436 { | |
437 case ResourceType_Instance: | |
438 instance_ = current; | |
439 GoToParent(index, current); | |
440 | |
441 case ResourceType_Series: | |
442 series_ = current; | |
443 GoToParent(index, current); | |
444 | |
445 case ResourceType_Study: | |
446 study_ = current; | |
447 GoToParent(index, current); | |
448 | |
449 case ResourceType_Patient: | |
450 patient_ = current; | |
451 break; | |
452 | |
453 default: | |
454 throw OrthancException(ErrorCode_InternalError); | |
455 } | |
456 } | |
457 | |
458 ResourceType GetLevel() const | |
459 { | |
460 return level_; | |
461 } | |
462 | |
463 const std::string& GetIdentifier(ResourceType level) const | |
464 { | |
465 // Some sanity check to ensure enumerations are not altered | |
466 assert(ResourceType_Patient < ResourceType_Study); | |
467 assert(ResourceType_Study < ResourceType_Series); | |
468 assert(ResourceType_Series < ResourceType_Instance); | |
469 | |
470 if (level > level_) | |
471 { | |
472 throw OrthancException(ErrorCode_InternalError); | |
473 } | |
474 | |
475 switch (level) | |
476 { | |
477 case ResourceType_Patient: | |
478 return patient_; | |
479 | |
480 case ResourceType_Study: | |
481 return study_; | |
482 | |
483 case ResourceType_Series: | |
484 return series_; | |
485 | |
486 case ResourceType_Instance: | |
487 return instance_; | |
488 | |
489 default: | |
490 throw OrthancException(ErrorCode_InternalError); | |
491 } | |
492 } | |
493 }; | |
494 | |
495 | |
496 class ArchiveJob::IArchiveVisitor : public boost::noncopyable | |
497 { | |
498 public: | |
499 virtual ~IArchiveVisitor() | |
500 { | |
501 } | |
502 | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
503 virtual void Open(ArchiveResourceType level, |
2632 | 504 const std::string& publicId) = 0; |
505 | |
506 virtual void Close() = 0; | |
507 | |
508 virtual void AddInstance(const std::string& instanceId, | |
4510
a3635a01a945
fix signature of virtual method
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4509
diff
changeset
|
509 uint64_t uncompressedSize) = 0; |
2632 | 510 }; |
511 | |
512 | |
513 class ArchiveJob::ArchiveIndex : public boost::noncopyable | |
514 { | |
515 private: | |
516 struct Instance | |
517 { | |
518 std::string id_; | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
519 uint64_t uncompressedSize_; |
2632 | 520 |
521 Instance(const std::string& id, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
522 uint64_t uncompressedSize) : |
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
523 id_(id), |
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
524 uncompressedSize_(uncompressedSize) |
2632 | 525 { |
526 } | |
527 }; | |
528 | |
529 // A "NULL" value for ArchiveIndex indicates a non-expanded node | |
530 typedef std::map<std::string, ArchiveIndex*> Resources; | |
531 | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
532 ArchiveResourceType level_; |
2632 | 533 Resources resources_; // Only at patient/study/series level |
534 std::list<Instance> instances_; // Only at instance level | |
535 | |
536 | |
537 void AddResourceToExpand(ServerIndex& index, | |
538 const std::string& id) | |
539 { | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
540 if (level_ == ArchiveResourceType_Instance) |
2632 | 541 { |
542 FileInfo tmp; | |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
543 int64_t revision; // ignored |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
544 if (index.LookupAttachment(tmp, revision, id, FileContentType_Dicom)) |
2632 | 545 { |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
546 instances_.push_back(Instance(id, tmp.GetUncompressedSize())); |
2632 | 547 } |
548 } | |
549 else | |
550 { | |
551 resources_[id] = NULL; | |
552 } | |
553 } | |
554 | |
555 | |
556 public: | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
557 explicit ArchiveIndex(ArchiveResourceType level) : |
2632 | 558 level_(level) |
559 { | |
560 } | |
561 | |
562 ~ArchiveIndex() | |
563 { | |
564 for (Resources::iterator it = resources_.begin(); | |
565 it != resources_.end(); ++it) | |
566 { | |
567 delete it->second; | |
568 } | |
569 } | |
570 | |
571 | |
572 void Add(ServerIndex& index, | |
573 const ResourceIdentifiers& resource) | |
574 { | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
575 const std::string& id = resource.GetIdentifier(GetResourceIdType(level_)); |
2632 | 576 Resources::iterator previous = resources_.find(id); |
577 | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
578 if (level_ == ArchiveResourceType_Instance) |
2632 | 579 { |
580 AddResourceToExpand(index, id); | |
581 } | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
582 else if (resource.GetLevel() == GetResourceLevel(level_)) |
2632 | 583 { |
584 // Mark this resource for further expansion | |
585 if (previous != resources_.end()) | |
586 { | |
587 delete previous->second; | |
588 } | |
589 | |
590 resources_[id] = NULL; | |
591 } | |
592 else if (previous == resources_.end()) | |
593 { | |
594 // This is the first time we meet this resource | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
595 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
2632 | 596 child->Add(index, resource); |
597 resources_[id] = child.release(); | |
598 } | |
599 else if (previous->second != NULL) | |
600 { | |
601 previous->second->Add(index, resource); | |
602 } | |
603 else | |
604 { | |
605 // Nothing to do: This item is marked for further expansion | |
606 } | |
607 } | |
608 | |
609 | |
610 void Expand(ServerIndex& index) | |
611 { | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
612 if (level_ == ArchiveResourceType_Instance) |
2632 | 613 { |
614 // Expanding an instance node makes no sense | |
615 return; | |
616 } | |
617 | |
618 for (Resources::iterator it = resources_.begin(); | |
619 it != resources_.end(); ++it) | |
620 { | |
621 if (it->second == NULL) | |
622 { | |
623 // This is resource is marked for expansion | |
624 std::list<std::string> children; | |
625 index.GetChildren(children, it->first); | |
626 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
627 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
2632 | 628 |
629 for (std::list<std::string>::const_iterator | |
630 it2 = children.begin(); it2 != children.end(); ++it2) | |
631 { | |
632 child->AddResourceToExpand(index, *it2); | |
633 } | |
634 | |
635 it->second = child.release(); | |
636 } | |
637 | |
638 assert(it->second != NULL); | |
639 it->second->Expand(index); | |
640 } | |
641 } | |
642 | |
643 | |
644 void Apply(IArchiveVisitor& visitor) const | |
645 { | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
646 if (level_ == ArchiveResourceType_Instance) |
2632 | 647 { |
648 for (std::list<Instance>::const_iterator | |
649 it = instances_.begin(); it != instances_.end(); ++it) | |
650 { | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
651 visitor.AddInstance(it->id_, it->uncompressedSize_); |
2632 | 652 } |
653 } | |
654 else | |
655 { | |
656 for (Resources::const_iterator it = resources_.begin(); | |
657 it != resources_.end(); ++it) | |
658 { | |
659 assert(it->second != NULL); // There must have been a call to "Expand()" | |
660 visitor.Open(level_, it->first); | |
661 it->second->Apply(visitor); | |
662 visitor.Close(); | |
663 } | |
664 } | |
665 } | |
666 }; | |
667 | |
668 | |
669 | |
670 class ArchiveJob::ZipCommands : public boost::noncopyable | |
671 { | |
672 private: | |
673 enum Type | |
674 { | |
675 Type_OpenDirectory, | |
676 Type_CloseDirectory, | |
677 Type_WriteInstance | |
678 }; | |
679 | |
680 class Command : public boost::noncopyable | |
681 { | |
682 private: | |
683 Type type_; | |
684 std::string filename_; | |
685 std::string instanceId_; | |
686 | |
687 public: | |
688 explicit Command(Type type) : | |
689 type_(type) | |
690 { | |
691 assert(type_ == Type_CloseDirectory); | |
692 } | |
693 | |
694 Command(Type type, | |
695 const std::string& filename) : | |
696 type_(type), | |
697 filename_(filename) | |
698 { | |
699 assert(type_ == Type_OpenDirectory); | |
700 } | |
701 | |
702 Command(Type type, | |
703 const std::string& filename, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
704 const std::string& instanceId) : |
2632 | 705 type_(type), |
706 filename_(filename), | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
707 instanceId_(instanceId) |
2632 | 708 { |
709 assert(type_ == Type_WriteInstance); | |
710 } | |
711 | |
712 void Apply(HierarchicalZipWriter& writer, | |
713 ServerContext& context, | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
714 InstanceLoader& instanceLoader, |
2632 | 715 DicomDirWriter* dicomDir, |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
716 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
717 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
718 DicomTransferSyntax transferSyntax) const |
2632 | 719 { |
720 switch (type_) | |
721 { | |
722 case Type_OpenDirectory: | |
723 writer.OpenDirectory(filename_.c_str()); | |
724 break; | |
725 | |
726 case Type_CloseDirectory: | |
727 writer.CloseDirectory(); | |
728 break; | |
729 | |
730 case Type_WriteInstance: | |
731 { | |
732 std::string content; | |
733 | |
734 try | |
735 { | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
736 instanceLoader.GetDicom(content, instanceId_); |
2632 | 737 } |
738 catch (OrthancException& e) | |
739 { | |
740 LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_; | |
741 return; | |
742 } | |
2636 | 743 |
2632 | 744 writer.OpenFile(filename_.c_str()); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
745 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
746 std::unique_ptr<ParsedDicomFile> parsed; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
747 |
5109 | 748 writer.Write(content); |
749 | |
750 if (dicomDir != NULL) | |
2632 | 751 { |
5109 | 752 if (parsed.get() == NULL) |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
753 { |
5109 | 754 parsed.reset(new ParsedDicomFile(content)); |
755 } | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
756 |
5109 | 757 dicomDir->Add(dicomDirFolder, filename_, *parsed); |
2632 | 758 } |
759 | |
760 break; | |
761 } | |
762 | |
763 default: | |
764 throw OrthancException(ErrorCode_InternalError); | |
765 } | |
766 } | |
767 }; | |
768 | |
769 std::deque<Command*> commands_; | |
770 uint64_t uncompressedSize_; | |
771 unsigned int instancesCount_; | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
772 InstanceLoader& instanceLoader_; |
2632 | 773 |
774 | |
775 void ApplyInternal(HierarchicalZipWriter& writer, | |
776 ServerContext& context, | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
777 InstanceLoader& instanceLoader, |
2632 | 778 size_t index, |
779 DicomDirWriter* dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
780 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
781 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
782 DicomTransferSyntax transferSyntax) const |
2632 | 783 { |
784 if (index >= commands_.size()) | |
785 { | |
786 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
787 } | |
788 | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
789 commands_[index]->Apply(writer, context, instanceLoader, dicomDir, dicomDirFolder, transcode, transferSyntax); |
2632 | 790 } |
791 | |
792 public: | |
4815 | 793 explicit ZipCommands(InstanceLoader& instanceLoader) : |
2632 | 794 uncompressedSize_(0), |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
795 instancesCount_(0), |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
796 instanceLoader_(instanceLoader) |
2632 | 797 { |
798 } | |
799 | |
800 ~ZipCommands() | |
801 { | |
802 for (std::deque<Command*>::iterator it = commands_.begin(); | |
803 it != commands_.end(); ++it) | |
804 { | |
805 assert(*it != NULL); | |
806 delete *it; | |
807 } | |
808 } | |
809 | |
810 size_t GetSize() const | |
811 { | |
812 return commands_.size(); | |
813 } | |
814 | |
815 unsigned int GetInstancesCount() const | |
816 { | |
817 return instancesCount_; | |
818 } | |
819 | |
820 uint64_t GetUncompressedSize() const | |
821 { | |
822 return uncompressedSize_; | |
823 } | |
824 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
825 // "media" flavor (with DICOMDIR) |
2632 | 826 void Apply(HierarchicalZipWriter& writer, |
827 ServerContext& context, | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
828 InstanceLoader& instanceLoader, |
2632 | 829 size_t index, |
830 DicomDirWriter& dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
831 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
832 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
833 DicomTransferSyntax transferSyntax) const |
2632 | 834 { |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
835 ApplyInternal(writer, context, instanceLoader, index, &dicomDir, dicomDirFolder, transcode, transferSyntax); |
2632 | 836 } |
837 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
838 // "archive" flavor (without DICOMDIR) |
2632 | 839 void Apply(HierarchicalZipWriter& writer, |
840 ServerContext& context, | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
841 InstanceLoader& instanceLoader, |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
842 size_t index, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
843 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
844 DicomTransferSyntax transferSyntax) const |
2632 | 845 { |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
846 ApplyInternal(writer, context, instanceLoader, index, NULL, "", transcode, transferSyntax); |
2632 | 847 } |
848 | |
849 void AddOpenDirectory(const std::string& filename) | |
850 { | |
851 commands_.push_back(new Command(Type_OpenDirectory, filename)); | |
852 } | |
853 | |
854 void AddCloseDirectory() | |
855 { | |
856 commands_.push_back(new Command(Type_CloseDirectory)); | |
857 } | |
858 | |
859 void AddWriteInstance(const std::string& filename, | |
860 const std::string& instanceId, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
861 uint64_t uncompressedSize) |
2632 | 862 { |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
863 instanceLoader_.PrepareDicom(instanceId); |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
864 commands_.push_back(new Command(Type_WriteInstance, filename, instanceId)); |
2632 | 865 instancesCount_ ++; |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
866 uncompressedSize_ += uncompressedSize; |
2632 | 867 } |
868 | |
869 bool IsZip64() const | |
870 { | |
871 return IsZip64Required(GetUncompressedSize(), GetInstancesCount()); | |
872 } | |
873 }; | |
874 | |
875 | |
876 | |
877 class ArchiveJob::ArchiveIndexVisitor : public IArchiveVisitor | |
878 { | |
879 private: | |
880 ZipCommands& commands_; | |
881 ServerContext& context_; | |
882 char instanceFormat_[24]; | |
883 unsigned int counter_; | |
884 | |
885 static std::string GetTag(const DicomMap& tags, | |
886 const DicomTag& tag) | |
887 { | |
888 const DicomValue* v = tags.TestAndGetValue(tag); | |
889 if (v != NULL && | |
890 !v->IsBinary() && | |
891 !v->IsNull()) | |
892 { | |
893 return v->GetContent(); | |
894 } | |
895 else | |
896 { | |
897 return ""; | |
898 } | |
899 } | |
900 | |
901 public: | |
902 ArchiveIndexVisitor(ZipCommands& commands, | |
903 ServerContext& context) : | |
904 commands_(commands), | |
905 context_(context), | |
906 counter_(0) | |
907 { | |
908 if (commands.GetSize() != 0) | |
909 { | |
910 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
911 } | |
912 | |
913 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); | |
914 } | |
915 | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
916 virtual void Open(ArchiveResourceType level, |
4205 | 917 const std::string& publicId) ORTHANC_OVERRIDE |
2632 | 918 { |
919 std::string path; | |
920 | |
921 DicomMap tags; | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
922 ResourceType resourceIdLevel = GetResourceIdType(level); |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
923 ResourceType interestLevel = (level == ArchiveResourceType_PatientInfoFromStudy ? ResourceType_Patient : resourceIdLevel); |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
924 |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
925 if (context_.GetIndex().GetMainDicomTags(tags, publicId, resourceIdLevel, interestLevel)) |
2632 | 926 { |
927 switch (level) | |
928 { | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
929 case ArchiveResourceType_Patient: |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
930 case ArchiveResourceType_PatientInfoFromStudy: |
2632 | 931 path = GetTag(tags, DICOM_TAG_PATIENT_ID) + " " + GetTag(tags, DICOM_TAG_PATIENT_NAME); |
932 break; | |
933 | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
934 case ArchiveResourceType_Study: |
2632 | 935 path = GetTag(tags, DICOM_TAG_ACCESSION_NUMBER) + " " + GetTag(tags, DICOM_TAG_STUDY_DESCRIPTION); |
936 break; | |
937 | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
938 case ArchiveResourceType_Series: |
2632 | 939 { |
940 std::string modality = GetTag(tags, DICOM_TAG_MODALITY); | |
941 path = modality + " " + GetTag(tags, DICOM_TAG_SERIES_DESCRIPTION); | |
942 | |
943 if (modality.size() == 0) | |
944 { | |
945 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); | |
946 } | |
947 else if (modality.size() == 1) | |
948 { | |
949 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%%07d.dcm", | |
950 toupper(modality[0])); | |
951 } | |
952 else if (modality.size() >= 2) | |
953 { | |
954 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%c%%06d.dcm", | |
955 toupper(modality[0]), toupper(modality[1])); | |
956 } | |
957 | |
958 counter_ = 0; | |
959 | |
960 break; | |
961 } | |
962 | |
963 default: | |
964 throw OrthancException(ErrorCode_InternalError); | |
965 } | |
966 } | |
967 | |
968 path = Toolbox::StripSpaces(Toolbox::ConvertToAscii(path)); | |
969 | |
5448
2d23c92c359a
Zip of studies whose PatientName and PatientID did not contain any ASCII character are now valid
Alain Mazy <am@osimis.io>
parents:
5430
diff
changeset
|
970 if (path.empty() |
2d23c92c359a
Zip of studies whose PatientName and PatientID did not contain any ASCII character are now valid
Alain Mazy <am@osimis.io>
parents:
5430
diff
changeset
|
971 || (static_cast<size_t>(boost::count(path, '^')) == path.size())) // this happens with non ASCII patient names: only the '^' remains and this is not a valid zip folder name |
2632 | 972 { |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
973 path = std::string("Unknown ") + EnumerationToString(GetResourceLevel(level)); |
2632 | 974 } |
975 | |
976 commands_.AddOpenDirectory(path.c_str()); | |
977 } | |
978 | |
4205 | 979 virtual void Close() ORTHANC_OVERRIDE |
2632 | 980 { |
981 commands_.AddCloseDirectory(); | |
982 } | |
983 | |
984 virtual void AddInstance(const std::string& instanceId, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
985 uint64_t uncompressedSize) ORTHANC_OVERRIDE |
2632 | 986 { |
987 char filename[24]; | |
988 snprintf(filename, sizeof(filename) - 1, instanceFormat_, counter_); | |
989 counter_ ++; | |
990 | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
991 commands_.AddWriteInstance(filename, instanceId, uncompressedSize); |
2632 | 992 } |
993 }; | |
994 | |
995 | |
996 class ArchiveJob::MediaIndexVisitor : public IArchiveVisitor | |
997 { | |
998 private: | |
999 ZipCommands& commands_; | |
1000 unsigned int counter_; | |
1001 | |
1002 public: | |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4588
diff
changeset
|
1003 explicit MediaIndexVisitor(ZipCommands& commands) : |
2632 | 1004 commands_(commands), |
1005 counter_(0) | |
1006 { | |
1007 } | |
1008 | |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
1009 virtual void Open(ArchiveResourceType level, |
4205 | 1010 const std::string& publicId) ORTHANC_OVERRIDE |
2632 | 1011 { |
1012 } | |
1013 | |
4205 | 1014 virtual void Close() ORTHANC_OVERRIDE |
2632 | 1015 { |
1016 } | |
1017 | |
1018 virtual void AddInstance(const std::string& instanceId, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1019 uint64_t uncompressedSize) ORTHANC_OVERRIDE |
2632 | 1020 { |
1021 // "DICOM restricts the filenames on DICOM media to 8 | |
1022 // characters (some systems wrongly use 8.3, but this does not | |
1023 // conform to the standard)." | |
1024 std::string filename = "IM" + boost::lexical_cast<std::string>(counter_); | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1025 commands_.AddWriteInstance(filename, instanceId, uncompressedSize); |
2632 | 1026 |
1027 counter_ ++; | |
1028 } | |
1029 }; | |
1030 | |
1031 | |
1032 class ArchiveJob::ZipWriterIterator : public boost::noncopyable | |
1033 { | |
1034 private: | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1035 ServerContext& context_; |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1036 InstanceLoader& instanceLoader_; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1037 ZipCommands commands_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1038 std::unique_ptr<HierarchicalZipWriter> zip_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1039 std::unique_ptr<DicomDirWriter> dicomDir_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1040 bool isMedia_; |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1041 bool isStream_; |
2632 | 1042 |
1043 public: | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1044 ZipWriterIterator(ServerContext& context, |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1045 InstanceLoader& instanceLoader, |
2632 | 1046 ArchiveIndex& archive, |
1047 bool isMedia, | |
1048 bool enableExtendedSopClass) : | |
1049 context_(context), | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1050 instanceLoader_(instanceLoader), |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1051 commands_(instanceLoader), |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1052 isMedia_(isMedia), |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1053 isStream_(false) |
2632 | 1054 { |
1055 if (isMedia) | |
1056 { | |
4588 | 1057 MediaIndexVisitor visitor(commands_); |
2632 | 1058 archive.Expand(context.GetIndex()); |
1059 | |
1060 commands_.AddOpenDirectory(MEDIA_IMAGES_FOLDER); | |
1061 archive.Apply(visitor); | |
1062 commands_.AddCloseDirectory(); | |
1063 | |
1064 dicomDir_.reset(new DicomDirWriter); | |
1065 dicomDir_->EnableExtendedSopClass(enableExtendedSopClass); | |
1066 } | |
1067 else | |
1068 { | |
1069 ArchiveIndexVisitor visitor(commands_, context); | |
1070 archive.Expand(context.GetIndex()); | |
1071 archive.Apply(visitor); | |
1072 } | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1073 } |
2632 | 1074 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1075 void SetOutputFile(const std::string& path) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1076 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1077 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1078 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1079 zip_.reset(new HierarchicalZipWriter(path.c_str())); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1080 zip_->SetZip64(commands_.IsZip64()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1081 isStream_ = false; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1082 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1083 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1084 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1085 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1086 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1087 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1088 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1089 void AcquireOutputStream(ZipWriter::IOutputStream* output) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1090 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1091 std::unique_ptr<ZipWriter::IOutputStream> protection(output); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1092 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1093 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1094 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1095 zip_.reset(new HierarchicalZipWriter(protection.release(), commands_.IsZip64())); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1096 isStream_ = true; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1097 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1098 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1099 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1100 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1101 } |
2632 | 1102 } |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1103 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1104 void CancelStream() |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1105 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1106 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1107 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1108 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1109 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1110 else if (isStream_) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1111 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1112 zip_->CancelStream(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1113 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1114 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1115 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1116 void Close() |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1117 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1118 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1119 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1120 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1121 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1122 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1123 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1124 zip_->Close(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1125 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1126 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1127 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1128 uint64_t GetArchiveSize() const |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1129 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1130 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1131 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1132 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1133 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1134 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1135 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1136 return zip_->GetArchiveSize(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1137 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1138 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1139 |
2632 | 1140 size_t GetStepsCount() const |
1141 { | |
1142 return commands_.GetSize() + 1; | |
1143 } | |
1144 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1145 void RunStep(size_t index, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1146 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1147 DicomTransferSyntax transferSyntax) |
2632 | 1148 { |
1149 if (index > commands_.GetSize()) | |
1150 { | |
1151 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1152 } | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1153 else if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1154 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1155 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1156 } |
2632 | 1157 else if (index == commands_.GetSize()) |
1158 { | |
1159 // Last step: Add the DICOMDIR | |
1160 if (isMedia_) | |
1161 { | |
1162 assert(dicomDir_.get() != NULL); | |
1163 std::string s; | |
1164 dicomDir_->Encode(s); | |
1165 | |
1166 zip_->OpenFile("DICOMDIR"); | |
1167 zip_->Write(s); | |
1168 } | |
1169 } | |
1170 else | |
1171 { | |
1172 if (isMedia_) | |
1173 { | |
1174 assert(dicomDir_.get() != NULL); | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1175 commands_.Apply(*zip_, context_, instanceLoader_, index, *dicomDir_, |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1176 MEDIA_IMAGES_FOLDER, transcode, transferSyntax); |
2632 | 1177 } |
1178 else | |
1179 { | |
1180 assert(dicomDir_.get() == NULL); | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1181 commands_.Apply(*zip_, context_, instanceLoader_, index, transcode, transferSyntax); |
2632 | 1182 } |
1183 } | |
1184 } | |
1185 | |
1186 unsigned int GetInstancesCount() const | |
1187 { | |
1188 return commands_.GetInstancesCount(); | |
1189 } | |
1190 | |
1191 uint64_t GetUncompressedSize() const | |
1192 { | |
1193 return commands_.GetUncompressedSize(); | |
1194 } | |
1195 }; | |
1196 | |
1197 | |
2966 | 1198 ArchiveJob::ArchiveJob(ServerContext& context, |
2632 | 1199 bool isMedia, |
5401
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
1200 bool enableExtendedSopClass, |
fc604681e6be
When exporting a study archive, make sure to use the PatientName from the study and not from the patient in case of PatientID collision
Alain Mazy <am@osimis.io>
parents:
5364
diff
changeset
|
1201 ResourceType jobLevel) : |
2632 | 1202 context_(context), |
5403
05cb668c5f3f
fix to keep backward behaviour when exporting a series archive
Alain Mazy <am@osimis.io>
parents:
5401
diff
changeset
|
1203 archive_(new ArchiveIndex(GetArchiveResourceType(jobLevel))), // get patient Info from this level |
2632 | 1204 isMedia_(isMedia), |
1205 enableExtendedSopClass_(enableExtendedSopClass), | |
1206 currentStep_(0), | |
1207 instancesCount_(0), | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1208 uncompressedSize_(0), |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1209 archiveSize_(0), |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1210 transcode_(false), |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1211 transferSyntax_(DicomTransferSyntax_LittleEndianImplicit), |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1212 loaderThreads_(0) |
2632 | 1213 { |
2966 | 1214 } |
1215 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1216 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1217 ArchiveJob::~ArchiveJob() |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1218 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1219 if (!mediaArchiveId_.empty()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1220 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1221 context_.GetMediaArchive().Remove(mediaArchiveId_); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1222 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1223 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1224 |
2966 | 1225 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1226 void ArchiveJob::AcquireSynchronousTarget(ZipWriter::IOutputStream* target) |
2966 | 1227 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1228 std::unique_ptr<ZipWriter::IOutputStream> protection(target); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1229 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1230 if (target == NULL) |
2632 | 1231 { |
1232 throw OrthancException(ErrorCode_NullPointer); | |
1233 } | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1234 else if (writer_.get() != NULL || // Already started |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1235 synchronousTarget_.get() != NULL || |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1236 asynchronousTarget_.get() != NULL) |
2966 | 1237 { |
1238 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1239 } | |
1240 else | |
1241 { | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1242 synchronousTarget_.reset(protection.release()); |
2966 | 1243 } |
2632 | 1244 } |
1245 | |
1246 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1247 void ArchiveJob::SetDescription(const std::string& description) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1248 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1249 if (writer_.get() != NULL) // Already started |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1250 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1251 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1252 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1253 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1254 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1255 description_ = description; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1256 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1257 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1258 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1259 |
5169
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1260 void ArchiveJob::AddResource(const std::string& publicId, |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1261 bool mustExist, |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1262 ResourceType expectedType) |
2632 | 1263 { |
1264 if (writer_.get() != NULL) // Already started | |
1265 { | |
1266 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1267 } | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1268 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1269 { |
5169
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1270 if (mustExist) |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1271 { |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1272 ResourceType type; |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1273 if (!context_.GetIndex().LookupResourceType(type, publicId) || |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1274 type != expectedType) |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1275 { |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1276 throw OrthancException(ErrorCode_InexistentItem, |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1277 "Missing resource while creating an archive: " + publicId); |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1278 } |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1279 } |
8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5109
diff
changeset
|
1280 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1281 ResourceIdentifiers resource(context_.GetIndex(), publicId); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1282 archive_->Add(context_.GetIndex(), resource); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1283 } |
2632 | 1284 } |
1285 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1286 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1287 void ArchiveJob::SetTranscode(DicomTransferSyntax transferSyntax) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1288 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1289 if (writer_.get() != NULL) // Already started |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1290 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1291 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1292 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1293 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1294 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1295 transcode_ = true; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1296 transferSyntax_ = transferSyntax; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1297 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1298 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1299 |
2632 | 1300 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1301 void ArchiveJob::SetLoaderThreads(unsigned int loaderThreads) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1302 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1303 if (writer_.get() != NULL) // Already started |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1304 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1305 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1306 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1307 else |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1308 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1309 loaderThreads_ = loaderThreads; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1310 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1311 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1312 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1313 |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2730
diff
changeset
|
1314 void ArchiveJob::Reset() |
2632 | 1315 { |
2955 | 1316 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
1317 "Cannot resubmit the creation of an archive"); | |
2632 | 1318 } |
1319 | |
1320 | |
1321 void ArchiveJob::Start() | |
1322 { | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1323 if (loaderThreads_ == 0) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1324 { |
4902
df86d2505df8
Orthanc 1.9.8 is now known as Orthanc 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
1325 // default behaviour before loaderThreads was introducted in 1.10.0 |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
1326 instanceLoader_.reset(new SynchronousInstanceLoader(context_, transcode_, transferSyntax_)); |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1327 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1328 else |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1329 { |
5108
a386dfb5b386
Optimization: now using multiple threads to transcode files for asynchronous download of studies archive
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
1330 instanceLoader_.reset(new ThreadedInstanceLoader(context_, loaderThreads_, transcode_, transferSyntax_)); |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1331 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1332 |
2632 | 1333 if (writer_.get() != NULL) |
1334 { | |
1335 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1336 } | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1337 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1338 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1339 if (synchronousTarget_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1340 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1341 if (asynchronousTarget_.get() != NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1342 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1343 // It is up to this method to create the asynchronous target |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1344 throw OrthancException(ErrorCode_InternalError); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1345 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1346 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1347 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1348 OrthancConfiguration::ReaderLock lock; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1349 asynchronousTarget_.reset(lock.GetConfiguration().CreateTemporaryFile()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1350 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1351 assert(asynchronousTarget_.get() != NULL); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1352 asynchronousTarget_->Touch(); // Make sure we can write to the temporary file |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1353 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1354 writer_.reset(new ZipWriterIterator(context_, *instanceLoader_, *archive_, isMedia_, enableExtendedSopClass_)); |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1355 writer_->SetOutputFile(asynchronousTarget_->GetPath()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1356 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1357 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1358 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1359 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1360 assert(synchronousTarget_.get() != NULL); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1361 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1362 writer_.reset(new ZipWriterIterator(context_, *instanceLoader_, *archive_, isMedia_, enableExtendedSopClass_)); |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1363 writer_->AcquireOutputStream(synchronousTarget_.release()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1364 } |
2632 | 1365 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1366 instancesCount_ = writer_->GetInstancesCount(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1367 uncompressedSize_ = writer_->GetUncompressedSize(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1368 } |
2632 | 1369 } |
1370 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1371 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1372 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1373 namespace |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1374 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1375 class DynamicTemporaryFile : public IDynamicObject |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1376 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1377 private: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1378 std::unique_ptr<TemporaryFile> file_; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1379 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1380 public: |
4205 | 1381 explicit DynamicTemporaryFile(TemporaryFile* f) : file_(f) |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1382 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1383 if (f == NULL) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1384 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1385 throw OrthancException(ErrorCode_NullPointer); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1386 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1387 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1388 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1389 const TemporaryFile& GetFile() const |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1390 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1391 assert(file_.get() != NULL); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1392 return *file_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1393 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1394 }; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1395 } |
2632 | 1396 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1397 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1398 void ArchiveJob::FinalizeTarget() |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1399 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1400 if (writer_.get() != NULL) |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1401 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1402 writer_->Close(); // Flush all the results |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1403 archiveSize_ = writer_->GetArchiveSize(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1404 writer_.reset(); |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1405 } |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1406 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1407 if (instanceLoader_.get() != NULL) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1408 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1409 instanceLoader_->Clear(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1410 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1411 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1412 if (asynchronousTarget_.get() != NULL) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1413 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1414 // Asynchronous behavior: Move the resulting file into the media archive |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1415 mediaArchiveId_ = context_.GetMediaArchive().Add( |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1416 new DynamicTemporaryFile(asynchronousTarget_.release())); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1417 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1418 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1419 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1420 |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1421 JobStepResult ArchiveJob::Step(const std::string& jobId) |
2632 | 1422 { |
1423 assert(writer_.get() != NULL); | |
1424 | |
1425 if (writer_->GetStepsCount() == 0) | |
1426 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1427 FinalizeTarget(); |
2632 | 1428 return JobStepResult::Success(); |
1429 } | |
1430 else | |
1431 { | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1432 try |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1433 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1434 writer_->RunStep(currentStep_, transcode_, transferSyntax_); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1435 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1436 catch (Orthanc::OrthancException& e) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1437 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1438 LOG(ERROR) << "Error while creating an archive: " << e.What(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1439 writer_->CancelStream(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1440 throw; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1441 } |
2632 | 1442 |
1443 currentStep_ ++; | |
1444 | |
1445 if (currentStep_ == writer_->GetStepsCount()) | |
1446 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1447 FinalizeTarget(); |
2632 | 1448 return JobStepResult::Success(); |
1449 } | |
1450 else | |
1451 { | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1452 archiveSize_ = writer_->GetArchiveSize(); |
2632 | 1453 return JobStepResult::Continue(); |
1454 } | |
1455 } | |
1456 } | |
1457 | |
1458 | |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1459 void ArchiveJob::Stop(JobStopReason reason) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1460 { |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1461 /** |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1462 * New in Orthanc 1.9.3: Remove the temporary file associated with |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1463 * the job as soon as its job gets canceled (especially visible in |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1464 * asynchronous mode). |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1465 **/ |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1466 if (reason == JobStopReason_Canceled || |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1467 reason == JobStopReason_Failure || |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1468 reason == JobStopReason_Retry) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1469 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1470 writer_->CancelStream(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1471 |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1472 // First delete the writer, as it holds a reference to "(a)synchronousTarget_", cf. (*) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1473 writer_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1474 |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1475 synchronousTarget_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1476 asynchronousTarget_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1477 } |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1478 } |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1479 |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1480 |
2632 | 1481 float ArchiveJob::GetProgress() |
1482 { | |
1483 if (writer_.get() == NULL || | |
1484 writer_->GetStepsCount() == 0) | |
1485 { | |
1486 return 1; | |
1487 } | |
1488 else | |
1489 { | |
1490 return (static_cast<float>(currentStep_) / | |
1491 static_cast<float>(writer_->GetStepsCount() - 1)); | |
1492 } | |
1493 } | |
1494 | |
1495 | |
1496 void ArchiveJob::GetJobType(std::string& target) | |
1497 { | |
1498 if (isMedia_) | |
1499 { | |
1500 target = "Media"; | |
1501 } | |
1502 else | |
1503 { | |
1504 target = "Archive"; | |
1505 } | |
1506 } | |
1507 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1508 |
2632 | 1509 void ArchiveJob::GetPublicContent(Json::Value& value) |
1510 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1511 value = Json::objectValue; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1512 value[KEY_DESCRIPTION] = description_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1513 value[KEY_INSTANCES_COUNT] = instancesCount_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1514 value[KEY_UNCOMPRESSED_SIZE_MB] = |
2643 | 1515 static_cast<unsigned int>(uncompressedSize_ / MEGA_BYTES); |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1516 value[KEY_ARCHIVE_SIZE_MB] = |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1517 static_cast<unsigned int>(archiveSize_ / MEGA_BYTES); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1518 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1519 // New in Orthanc 1.9.4 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1520 value[KEY_ARCHIVE_SIZE] = boost::lexical_cast<std::string>(archiveSize_); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1521 value[KEY_UNCOMPRESSED_SIZE] = boost::lexical_cast<std::string>(uncompressedSize_); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1522 |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1523 if (transcode_) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1524 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1525 value[KEY_TRANSCODE] = GetTransferSyntaxUid(transferSyntax_); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1526 } |
2632 | 1527 } |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1528 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1529 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1530 bool ArchiveJob::GetOutput(std::string& output, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1531 MimeType& mime, |
4805
0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1532 std::string& filename, |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1533 const std::string& key) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1534 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1535 if (key == "archive" && |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1536 !mediaArchiveId_.empty()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1537 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1538 SharedArchive::Accessor accessor(context_.GetMediaArchive(), mediaArchiveId_); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1539 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1540 if (accessor.IsValid()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1541 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1542 const DynamicTemporaryFile& f = dynamic_cast<DynamicTemporaryFile&>(accessor.GetItem()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1543 f.GetFile().Read(output); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1544 mime = MimeType_Zip; |
4805
0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1545 filename = "archive.zip"; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1546 return true; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1547 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1548 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1549 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1550 return false; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1551 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1552 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1553 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1554 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1555 return false; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1556 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1557 } |
5310
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1558 |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1559 bool ArchiveJob::DeleteOutput(const std::string& key) |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1560 { |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1561 if (key == "archive" && |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1562 !mediaArchiveId_.empty()) |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1563 { |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1564 SharedArchive::Accessor accessor(context_.GetMediaArchive(), mediaArchiveId_); |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1565 |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1566 if (accessor.IsValid()) |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1567 { |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1568 context_.GetMediaArchive().Remove(mediaArchiveId_); |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1569 return true; |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1570 } |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1571 else |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1572 { |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1573 return false; |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1574 } |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1575 } |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1576 else |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1577 { |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1578 return false; |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1579 } |
b5c502bcaf99
added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents:
5302
diff
changeset
|
1580 } |
5364
b5f2122a1334
Added a route to delete completed jobs from history: DELETE /jobs/{id}
Alain Mazy <am@osimis.io>
parents:
5310
diff
changeset
|
1581 |
b5f2122a1334
Added a route to delete completed jobs from history: DELETE /jobs/{id}
Alain Mazy <am@osimis.io>
parents:
5310
diff
changeset
|
1582 void ArchiveJob::DeleteAllOutputs() |
b5f2122a1334
Added a route to delete completed jobs from history: DELETE /jobs/{id}
Alain Mazy <am@osimis.io>
parents:
5310
diff
changeset
|
1583 { |
b5f2122a1334
Added a route to delete completed jobs from history: DELETE /jobs/{id}
Alain Mazy <am@osimis.io>
parents:
5310
diff
changeset
|
1584 DeleteOutput("archive"); |
b5f2122a1334
Added a route to delete completed jobs from history: DELETE /jobs/{id}
Alain Mazy <am@osimis.io>
parents:
5310
diff
changeset
|
1585 } |
2632 | 1586 } |