SourceXtractorPlusPlus  0.15
Please provide a description of the project.
TileManager.h
Go to the documentation of this file.
1 
17 /*
18  * TileManager.h
19  *
20  * Created on: Feb 23, 2018
21  * Author: mschefer
22  */
23 
24 #ifndef _SEFRAMEWORK_IMAGE_TILEMANAGER_H_
25 #define _SEFRAMEWORK_IMAGE_TILEMANAGER_H_
26 
27 #include <iostream>
28 #include <thread>
29 #include <list>
30 #include <unordered_map>
31 
32 #include <boost/thread/shared_mutex.hpp>
33 
34 #include <ElementsKernel/Logging.h>
35 
38 
39 namespace SourceXtractor {
40 
41 
42 struct TileKey {
45 
46  bool operator==(const TileKey& other) const;
47 
48  std::string getRepr() const;
49 };
50 
51 inline std::ostream& operator<<(std::ostream& out, const TileKey& tk) {
52  out << tk.getRepr();
53  return out;
54 }
55 
56 }
57 
58 namespace std {
59 
60 template<>
61 struct hash<SourceXtractor::TileKey> {
63  std::size_t local_hash = 0;
64  boost::hash_combine(local_hash, key.m_source);
65  boost::hash_combine(local_hash, key.m_tile_x);
66  boost::hash_combine(local_hash, key.m_tile_y);
67  return local_hash;
68  }
69 };
70 
71 }
72 
73 namespace SourceXtractor {
74 
75 class TileManager {
76 public:
77 
78  TileManager();
79 
80  virtual ~TileManager();
81 
82  // Actually not thread safe, call before starting the multi-threading
83  void setOptions(int tile_width, int tile_height, int max_memory);
84 
85  void flush();
86 
89 
91 
92  void saveAllTiles();
93 
94  int getTileWidth() const;
95 
96  int getTileHeight() const;
97 
98 private:
99 
101 
103 
104  void removeTile(TileKey tile_key);
105 
106  void removeExtraTiles();
107 
109 
113 
117 
118  boost::shared_mutex m_mutex;
119 };
120 
121 }
122 
123 
124 #endif /* _SEFRAMEWORK_IMAGE_TILEMANAGER_H_ */
SourceXtractor::TileManager::removeExtraTiles
void removeExtraTiles()
Definition: TileManager.cpp:172
SourceXtractor::TileManager::flush
void flush()
Definition: TileManager.cpp:59
std::string
STL class.
std::shared_ptr
STL class.
std::list
STL class.
SourceXtractor::TileManager::m_tile_list
std::list< TileKey > m_tile_list
Definition: TileManager.h:116
SourceXtractor::TileManager::m_tile_width
int m_tile_width
Definition: TileManager.h:110
SourceXtractor::TileKey::operator==
bool operator==(const TileKey &other) const
Definition: TileManager.cpp:31
SourceXtractor::TileKey
Definition: TileManager.h:42
SourceXtractor::TileManager::getMutexForImageSource
std::shared_ptr< boost::mutex > & getMutexForImageSource(const ImageSource *)
Definition: TileManager.cpp:90
SourceXtractor::TileKey::m_source
std::shared_ptr< const ImageSource > m_source
Definition: TileManager.h:43
SourceXtractor::TileManager::~TileManager
virtual ~TileManager()
Definition: TileManager.cpp:46
SourceXtractor::TileManager::getTileForPixel
std::shared_ptr< ImageTile > getTileForPixel(int x, int y, std::shared_ptr< const ImageSource > source)
Definition: TileManager.cpp:100
SourceXtractor::TileManager::saveAllTiles
void saveAllTiles()
Definition: TileManager.cpp:143
SourceXtractor::TileKey::getRepr
std::string getRepr() const
Definition: TileManager.cpp:35
SourceXtractor::TileManager::m_max_memory
long m_max_memory
Definition: TileManager.h:111
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::TileManager::removeTile
void removeTile(TileKey tile_key)
Definition: TileManager.cpp:159
std::ostream
STL class.
SourceXtractor::TileManager::TileManager
TileManager()
Definition: TileManager.cpp:42
ImageTile.h
SourceXtractor::TileManager::tryTileFromCache
std::shared_ptr< ImageTile > tryTileFromCache(const TileKey &key)
Definition: TileManager.cpp:74
SourceXtractor::TileManager::getTileWidth
int getTileWidth() const
Definition: TileManager.cpp:151
SourceXtractor::TileManager::m_mutex_map
std::unordered_map< const ImageSource *, std::shared_ptr< boost::mutex > > m_mutex_map
Definition: TileManager.h:115
SourceXtractor::ImageSource
Definition: ImageSource.h:52
SourceXtractor::TileManager::addTile
void addTile(TileKey key, std::shared_ptr< ImageTile > tile)
Definition: TileManager.cpp:181
SourceXtractor::TileManager::m_tile_map
std::unordered_map< TileKey, std::shared_ptr< ImageTile > > m_tile_map
Definition: TileManager.h:114
SourceXtractor::TileManager::m_mutex
boost::shared_mutex m_mutex
Definition: TileManager.h:118
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition: MoffatModelFittingTask.cpp:94
SourceXtractor::operator<<
std::ostream & operator<<(std::ostream &out, const TileKey &tk)
Definition: TileManager.h:51
std
STL namespace.
SourceXtractor::TileManager::m_total_memory_used
long m_total_memory_used
Definition: TileManager.h:112
SourceXtractor::TileManager::m_tile_height
int m_tile_height
Definition: TileManager.h:110
ImageSource.h
std::size_t
Logging.h
SourceXtractor::TileManager::getTileHeight
int getTileHeight() const
Definition: TileManager.cpp:155
std::hash< SourceXtractor::TileKey >::operator()
std::size_t operator()(const SourceXtractor::TileKey &key) const
Definition: TileManager.h:62
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition: MoffatModelFittingTask.cpp:94
std::unordered_map
STL class.
SourceXtractor::TileKey::m_tile_y
int m_tile_y
Definition: TileManager.h:44
SourceXtractor::TileManager::setOptions
void setOptions(int tile_width, int tile_height, int max_memory)
Definition: TileManager.cpp:50
SourceXtractor::TileKey::m_tile_x
int m_tile_x
Definition: TileManager.h:44
std::hash
SourceXtractor::TileManager::getInstance
static std::shared_ptr< TileManager > getInstance()
Definition: TileManager.cpp:136
SourceXtractor::TileManager
Definition: TileManager.h:75