MeVisLab Toolbox Reference
mlDICOMCachedIOTagCacheMap.h
Go to the documentation of this file.
1 // Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2 // **InsertLicense** code
3 //----------------------------------------------------------------------------------
5 
10 //----------------------------------------------------------------------------------
11 #pragma once
12 
13 #include "MLDICOMCachedIOSystem.h"
14 #include <mlTypeDefs.h>
15 
16 #include <ThirdPartyWarningsDisable.h>
17 #include <list>
18 #include <set>
19 #include <ThirdPartyWarningsRestore.h>
20 
21 #include <mlConstantString.h>
22 #include <mlSubImage.h>
24 
25 #include <DCMTree_Tag.h>
26 
27 #include <ThirdPartyWarningsDisable.h>
28 #include <boost/unordered_map.hpp>
29 #include <ThirdPartyWarningsRestore.h>
30 
31 namespace ML_NAMESPACE {
32  class IntField;
33  class DicomMessageCollector;
34 };
35 
36 //----------------------------------------------------------------------------------
39 //----------------------------------------------------------------------------------
41 
42 public:
43 
46 
49 
50  // -------------- Management of tags:
51 
54 
56  void setMaxNumMegaBytes(MLint maxNumMegaBytes);
57 
60 
63 
66 
75  MLint flush(const MLint maxBytes, const bool flushAll=false);
76 
79 
82 
85 
92 
94  void clear();
95 
96  //----------------------------------------------------------------------------------
98  //----------------------------------------------------------------------------------
99  struct TagKey
100  {
102  inline TagKey(): _id(0){}
103 
105  inline TagKey(MLuint32 id, const ML_NAMESPACE::ConstantString& fileName): _id(id), _fileName(fileName){}
106 
108  inline bool operator==(const TagKey& other) const {
109  return (_id == other._id) && (_fileName == other._fileName);
110  }
111 
114 
116  ML_NAMESPACE::ConstantString _fileName;
117 
119  std::list<TagKey>::iterator _recentlyCachedIt;
120  };
121 
133  {
135  inline size_t operator()(TagKey const& key) const
136  {
137  size_t hash = hash_value(key._fileName);
138  boost::hash_combine(hash, key._id);
139  return hash;
140  }
141  };
142 
143 
145  typedef boost::unordered_map< TagKey, DCMTree::Const_TagPtr, TagHashFunction > CacheMapType;
146 
150  DCMTree::RawTagId rawTagId) const;
151 
154  DCMTree::Const_TagPtr tagPtr,
155  const MLint tagValSize);
156 
158  DCMTree::Const_TagPtr loadDCMTag(const ML_NAMESPACE::ConstantString &fileHandle,
159  DCMTree::RawTagId rawTagId,
160  MLint maxTagValueSizeToCache,
161  bool *treeLoadFailed,
162  bool *cacheMiss,
163  ML_NAMESPACE::DicomMessageCollector &dcmMsgCollector);
164 
166  void prefetchDCMTags(const ML_NAMESPACE::ConstantString &fileHandle,
167  const std::set<MLuint32> &tagIds,
168  MLint maxTagValueSizeToCache,
169  bool *treeLoadFailed,
170  ML_NAMESPACE::DicomMessageCollector &dcmMsgCollector);
171 
172 protected:
173 
176 
179 
181  std::list<TagKey> _recentlyCached;
182 
185 
188 
192 };
Project global and OS specific declarations.
#define MLDICOMCachedIO_EXPORT
If included by external modules, exported symbols are declared as import symbols.
Structure containing the DCMTag look up map and the list of most recently used DICOM files as names.
std::list< TagKey > _recentlyCached
Stores the file names of DCMTags added to cache in the order of caching.
boost::unordered_map< TagKey, DCMTree::Const_TagPtr, TagHashFunction > CacheMapType
Defines the map type to be used for tag caching.
MLint getTotalNumberOfBytes() const
Returns the approximate number of cached bytes.
MLint _numFlushedBytes
Counter for number of flushed bytes since most recent resetNumFlushedBytes().
DCMTree::Const_TagPtr getCachedDCMTag(const ml::DICOMCachedIOFileHandle &fileHandle, DCMTree::RawTagId rawTagId) const
Returns a valid tag pointer if the fileName with the rawTagId is cached, otherwise a null tag is retu...
MLint _totalNumBytes
Total number of value bytes in all DICOM tags.
void removeAssociatedEntries(const ml::DICOMCachedIOFileHandle &fileHandle)
Searches all tags with the given fileHandle in the cache and removes them; note that this function ha...
MLint flush()
Same as flush(getMaxNumBytes(), false).
void resetNumFlushedBytes()
Sets counter of flushed bytes to 0.
MLint getNumFlushedBytes() const
Returns the number of flushed bytes since most recent resetNumFlushedBytes().
ml::IntField & getMaxNumMegaBytesFld()
Returns field that specifies the maximum number of bytes for tag data.
MLint flush(const MLint maxBytes, const bool flushAll=false)
Flushes entries which have no other references than those ones from the cache until the given maxByte...
MLint getMaxNumMegaBytes() const
Return maximum number of bytes used for tag data.
void insertTag(MLDICOMCachedIOTagCacheMap::TagKey &key, DCMTree::Const_TagPtr tagPtr, const MLint tagValSize)
Helper to insert a tag and to update all related structures.
void setMaxNumMegaBytes(MLint maxNumMegaBytes)
Set maximum number of mega bytes used for tag data. Values < 0 are clamped to 0.
MLint getMaxNumBytes() const
Return maximum number of bytes used for tag data (rounded down to MB limits).
CacheMapType _cache
The tag map for caching.
~MLDICOMCachedIOTagCacheMap()
Destructor, cleaning up internal objects.
ml::IntField * _limitInMegaBytesFld
IntField specifying the maximum number of value bytes allowed in all DICOM tags.
DCMTree::Const_TagPtr loadDCMTag(const ml::ConstantString &fileHandle, DCMTree::RawTagId rawTagId, MLint maxTagValueSizeToCache, bool *treeLoadFailed, bool *cacheMiss, ml::DicomMessageCollector &dcmMsgCollector)
See DICOMCachedIOTagCache::loadDCMTag() for details.
void prefetchDCMTags(const ml::ConstantString &fileHandle, const std::set< MLuint32 > &tagIds, MLint maxTagValueSizeToCache, bool *treeLoadFailed, ml::DicomMessageCollector &dcmMsgCollector)
See DICOMCachedIOTagCache::prefetchDCMTags() for details.
void clear()
Clears the MLDICOMCachedIOTagCacheMap, and resets all counters.
MLDICOMCachedIOTagCacheMap()
Constructor; it is initialized with 25 MB of cache for DICOM tree tag data.
Class for cached DICOM tag loading from files for DICOM importing modules.
Field to encapsulate an integer value.
Definition: mlFields.h:161
size_t hash_value(MLGlobalFunctionKey const &key)
Calculates the has key from last string segment.
Definition: mlCallGraph.h:59
Header of FileHandle class which should be used in DICOM importing modules to resolve the filename fo...
unsigned int MLuint32
Definition: mlTypeDefs.h:191
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
boost::shared_ptr< const Tag > Const_TagPtr
Definition: DCMTree_Lib.h:63
unsigned int RawTagId
Definition: DCMTree_Lib.h:147
DICOMCachedIOFileHandleBase< char > DICOMCachedIOFileHandle
"Forward" to DICOMCachedIOFileHandle.
This is a self defined hash function for the boost::unordered map used as cache for tags.
size_t operator()(TagKey const &key) const
Calculates the has key from last string segment.
bool operator==(const TagKey &other) const
Returns true if _id and _fileName of *this and other are identical, otherwise false.
std::list< TagKey >::iterator _recentlyCachedIt
Iterator to the entry in _recentlyCached list for faster deletion there.
TagKey()
Initializes _id to 0 and _fileHandle empty.
TagKey(MLuint32 id, const ml::ConstantString &fileName)
Initializes _id with id and _fileHandle with fileName.
ml::ConstantString _fileName
The handle of the DCMTree source associated to the tag.