Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Toolbox/ParsedDicomCache.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Toolbox/ParsedDicomCache.cpp@c38c89684d83 |
children | 85e117739eca |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
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-2020 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 | |
22 #include "ParsedDicomCache.h" | |
23 | |
24 namespace OrthancStone | |
25 { | |
26 class ParsedDicomCache::Item : public Orthanc::ICacheable | |
27 { | |
28 private: | |
29 std::unique_ptr<Orthanc::ParsedDicomFile> dicom_; | |
30 size_t fileSize_; | |
31 bool hasPixelData_; | |
32 | |
33 public: | |
34 Item(Orthanc::ParsedDicomFile* dicom, | |
35 size_t fileSize, | |
36 bool hasPixelData) : | |
37 dicom_(dicom), | |
38 fileSize_(fileSize), | |
39 hasPixelData_(hasPixelData) | |
40 { | |
41 if (dicom == NULL) | |
42 { | |
43 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
44 } | |
45 } | |
46 | |
47 virtual size_t GetMemoryUsage() const | |
48 { | |
49 return fileSize_; | |
50 } | |
51 | |
52 Orthanc::ParsedDicomFile& GetDicom() const | |
53 { | |
54 assert(dicom_.get() != NULL); | |
55 return *dicom_; | |
56 } | |
57 | |
58 bool HasPixelData() const | |
59 { | |
60 return hasPixelData_; | |
61 } | |
62 }; | |
63 | |
64 | |
65 std::string ParsedDicomCache::GetIndex(unsigned int bucket, | |
66 const std::string& bucketKey) | |
67 { | |
68 return boost::lexical_cast<std::string>(bucket) + "|" + bucketKey; | |
69 } | |
70 | |
71 | |
72 void ParsedDicomCache::Acquire(unsigned int bucket, | |
73 const std::string& bucketKey, | |
74 Orthanc::ParsedDicomFile* dicom, | |
75 size_t fileSize, | |
76 bool hasPixelData) | |
77 { | |
78 LOG(TRACE) << "new item stored in cache: bucket " << bucket << ", key " << bucketKey; | |
79 cache_.Acquire(GetIndex(bucket, bucketKey), new Item(dicom, fileSize, hasPixelData)); | |
80 } | |
81 | |
82 | |
83 ParsedDicomCache::Reader::Reader(ParsedDicomCache& cache, | |
84 unsigned int bucket, | |
85 const std::string& bucketKey) : | |
86 /** | |
87 * The "DcmFileFormat" object cannot be accessed from multiple | |
88 * threads, even if using only getters. An unique lock (mutex) is | |
89 * mandatory. | |
90 **/ | |
91 accessor_(cache.cache_, GetIndex(bucket, bucketKey), true /* unique */) | |
92 { | |
93 if (accessor_.IsValid()) | |
94 { | |
95 LOG(TRACE) << "accessing item within cache: bucket " << bucket << ", key " << bucketKey; | |
96 item_ = &dynamic_cast<Item&>(accessor_.GetValue()); | |
97 } | |
98 else | |
99 { | |
100 LOG(TRACE) << "missing item within cache: bucket " << bucket << ", key " << bucketKey; | |
101 item_ = NULL; | |
102 } | |
103 } | |
104 | |
105 | |
106 bool ParsedDicomCache::Reader::HasPixelData() const | |
107 { | |
108 if (item_ == NULL) | |
109 { | |
110 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
111 } | |
112 else | |
113 { | |
114 return item_->HasPixelData(); | |
115 } | |
116 } | |
117 | |
118 | |
119 Orthanc::ParsedDicomFile& ParsedDicomCache::Reader::GetDicom() const | |
120 { | |
121 if (item_ == NULL) | |
122 { | |
123 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
124 } | |
125 else | |
126 { | |
127 return item_->GetDicom(); | |
128 } | |
129 } | |
130 | |
131 | |
132 size_t ParsedDicomCache::Reader::GetFileSize() const | |
133 { | |
134 if (item_ == NULL) | |
135 { | |
136 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
137 } | |
138 else | |
139 { | |
140 return item_->GetMemoryUsage(); | |
141 } | |
142 } | |
143 } |