annotate ViewerPlugin/DicomPyramidCache.cpp @ 254:20a730889ae2

upgrade to 2023
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Jul 2023 17:38:07 +0200
parents 49f647ed1b4c
children c72fbdecdc38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
254
20a730889ae2 upgrade to 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 242
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
20a730889ae2 upgrade to 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 242
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Affero General Public License for more details.
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../Framework/PrecompiledHeadersWSI.h"
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "DicomPyramidCache.h"
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
199
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
26 #include <Compatibility.h> // For std::unique_ptr
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
27
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <cassert>
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace OrthancWSI
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 DicomPyramid* DicomPyramidCache::GetCachedPyramid(const std::string& seriesId)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 // Mutex is assumed to be locked
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 DicomPyramid* pyramid = NULL;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 // Is the series of interest already cached as a pyramid?
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 if (cache_.Contains(seriesId, pyramid))
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 if (pyramid == NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 // Tag the series as the most recently used
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 cache_.MakeMostRecent(seriesId);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 return pyramid;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 DicomPyramid& DicomPyramidCache::GetPyramid(const std::string& seriesId,
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 boost::mutex::scoped_lock& lock)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 // Mutex is assumed to be locked
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 DicomPyramid* pyramid = GetCachedPyramid(seriesId);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if (pyramid != NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 return *pyramid;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 // Unlock the mutex to construct the pyramid (this is a
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 // time-consuming operation, we don't want it to block other clients)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 lock.unlock();
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
199
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
70 std::unique_ptr<DicomPyramid> pyramid
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 (new DicomPyramid(orthanc_, seriesId, true /* use metadata cache */));
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 // The pyramid is constructed: Store it into the cache
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 lock.lock();
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 DicomPyramid* cached = GetCachedPyramid(seriesId);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 if (cached != NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 // The pyramid was already constructed by another request in
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 // between, reuse the cached value (the auto_ptr destroys
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 // the just-constructed pyramid)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 return *cached;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 if (cache_.GetSize() == maxSize_)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 // The cache has grown too large: First delete the least
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 // recently used entry
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 DicomPyramid* oldest = NULL;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 cache_.RemoveOldest(oldest);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 if (oldest == NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 else
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 delete oldest;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 // Now we have at least one free entry in the cache
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 assert(cache_.GetSize() < maxSize_);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 // Add a new element to the cache and make it the most
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 // recently used entry
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 DicomPyramid* payload = pyramid.release();
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 cache_.Add(seriesId, payload);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 return *payload;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
196
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
115 DicomPyramidCache::DicomPyramidCache(OrthancStone::IOrthancConnection& orthanc,
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 size_t maxSize) :
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 orthanc_(orthanc),
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 maxSize_(maxSize)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 DicomPyramidCache::~DicomPyramidCache()
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 while (!cache_.IsEmpty())
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 DicomPyramid* pyramid = NULL;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 std::string seriesId = cache_.RemoveOldest(pyramid);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 if (pyramid != NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 delete pyramid;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 void DicomPyramidCache::Invalidate(const std::string& seriesId)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 boost::mutex::scoped_lock lock(mutex_);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 if (cache_.Contains(seriesId))
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
199
a1c265cb2174 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
144 std::unique_ptr<DicomPyramid> pyramid(cache_.Invalidate(seriesId));
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 if (pyramid.get() == NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 DicomPyramidCache::Locker::Locker(DicomPyramidCache& cache,
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 const std::string& seriesId) :
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 lock_(cache.mutex_),
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 pyramid_(cache.GetPyramid(seriesId, lock_))
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }