annotate OrthancServer/Sources/ServerJobs/ArchiveJob.cpp @ 5406:aaf7c49a9ddc am-http-compression

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