Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/ParsedDicomCache.cpp @ 1224:37bc7f115f81 broker
integration mainline->broker
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 07 Dec 2019 18:45:37 +0100 |
parents | 48befc2bf66d |
children | b9b5d4378874 |
rev | line source |
---|---|
1116 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
1149
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1140
diff
changeset
|
22 #include "ParsedDicomCache.h" |
1116 | 23 |
24 namespace OrthancStone | |
25 { | |
1149
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1140
diff
changeset
|
26 class ParsedDicomCache::Item : public Orthanc::ICacheable |
1116 | 27 { |
28 private: | |
1136
42581a6182c8
reactivation of the cache of parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
29 boost::mutex mutex_; |
42581a6182c8
reactivation of the cache of parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
30 std::auto_ptr<Orthanc::ParsedDicomFile> dicom_; |
42581a6182c8
reactivation of the cache of parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
31 size_t fileSize_; |
42581a6182c8
reactivation of the cache of parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
32 bool hasPixelData_; |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
33 |
1116 | 34 public: |
1136
42581a6182c8
reactivation of the cache of parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
35 Item(Orthanc::ParsedDicomFile* dicom, |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
36 size_t fileSize, |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
37 bool hasPixelData) : |
1116 | 38 dicom_(dicom), |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
39 fileSize_(fileSize), |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
40 hasPixelData_(hasPixelData) |
1116 | 41 { |
42 if (dicom == NULL) | |
43 { | |
44 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
45 } | |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
46 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
47 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
48 boost::mutex& GetMutex() |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
49 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
50 return mutex_; |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
51 } |
1116 | 52 |
53 virtual size_t GetMemoryUsage() const | |
54 { | |
55 return fileSize_; | |
56 } | |
57 | |
1136
42581a6182c8
reactivation of the cache of parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
58 Orthanc::ParsedDicomFile& GetDicom() const |
1116 | 59 { |
60 assert(dicom_.get() != NULL); | |
1136
42581a6182c8
reactivation of the cache of parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
61 return *dicom_; |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
62 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
63 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
64 bool HasPixelData() const |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
65 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
66 return hasPixelData_; |
1116 | 67 } |
68 }; | |
69 | |
70 | |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
71 std::string ParsedDicomCache::GetIndex(unsigned int bucket, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
72 const std::string& bucketKey) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
73 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
74 return boost::lexical_cast<std::string>(bucket) + "|" + bucketKey; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
75 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
76 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
77 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
78 void ParsedDicomCache::Acquire(unsigned int bucket, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
79 const std::string& bucketKey, |
1149
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1140
diff
changeset
|
80 Orthanc::ParsedDicomFile* dicom, |
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1140
diff
changeset
|
81 size_t fileSize, |
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1140
diff
changeset
|
82 bool hasPixelData) |
1116 | 83 { |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
84 LOG(TRACE) << "new item stored in cache: bucket " << bucket << ", key " << bucketKey; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
85 cache_.Acquire(GetIndex(bucket, bucketKey), new Item(dicom, fileSize, hasPixelData)); |
1116 | 86 } |
87 | |
88 | |
1149
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1140
diff
changeset
|
89 ParsedDicomCache::Reader::Reader(ParsedDicomCache& cache, |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
90 unsigned int bucket, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
91 const std::string& bucketKey) : |
1140 | 92 /** |
93 * The "DcmFileFormat" object cannot be accessed from multiple | |
94 * threads, even if using only getters. An unique lock (mutex) is | |
95 * mandatory. | |
96 **/ | |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
97 accessor_(cache.cache_, GetIndex(bucket, bucketKey), true /* unique */) |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
98 { |
1140 | 99 if (accessor_.IsValid()) |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
100 { |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
101 LOG(TRACE) << "accessing item within cache: bucket " << bucket << ", key " << bucketKey; |
1140 | 102 item_ = &dynamic_cast<Item&>(accessor_.GetValue()); |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
103 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
104 else |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
105 { |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1149
diff
changeset
|
106 LOG(TRACE) << "missing item within cache: bucket " << bucket << ", key " << bucketKey; |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
107 item_ = NULL; |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
108 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
109 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
110 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
111 |
1149
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1140
diff
changeset
|
112 bool ParsedDicomCache::Reader::HasPixelData() const |
1116 | 113 { |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
114 if (item_ == NULL) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
115 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
116 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
117 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
118 else |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
119 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
120 return item_->HasPixelData(); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
121 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
122 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
123 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
124 |
1149
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1140
diff
changeset
|
125 Orthanc::ParsedDicomFile& ParsedDicomCache::Reader::GetDicom() const |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
126 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
127 if (item_ == NULL) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
128 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
129 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
130 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
131 else |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
132 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
133 return item_->GetDicom(); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
134 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
135 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
136 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
137 |
1149
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1140
diff
changeset
|
138 size_t ParsedDicomCache::Reader::GetFileSize() const |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
139 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
140 if (item_ == NULL) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
141 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
142 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
143 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
144 else |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
145 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
146 return item_->GetMemoryUsage(); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
147 } |
1116 | 148 } |
149 } |