CARTA Backend
The backend component of CARTA
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
carta::TileCache Class Reference

A cache for full-resolution image tiles. More...

#include <TileCache.h>

Collaboration diagram for carta::TileCache:
[legend]

Public Types

using Key = TileCacheKey
 

Public Member Functions

 TileCache ()
 Default constructor.
 
 TileCache (int capacity)
 Constructor used by Frame.
 
TilePtr Peek (Key key)
 Retrieve a tile from the cache without modifying its access time.
 
TilePtr Get (Key key, std::shared_ptr< FileLoader > loader, std::mutex &image_mutex)
 Retrieve a tile from the cache.
 
void Reset (int32_t z, int32_t stokes, int capacity=0)
 Reset the cache for a new Z coordinate and/or Stokes coordinate, clearing all tiles.
 

Static Public Member Functions

static Key ChunkKey (Key tile_key)
 Calculate the key for the chunk that contains the given tile.
 

Private Types

using TilePair = std::pair< Key, TilePtr >
 
using TileIter = std::vector< float >::iterator
 

Private Member Functions

TilePtr UnsafePeek (Key key)
 Retrieve a tile from the cache.
 
void Touch (Key key)
 Update the access time of a tile.
 
bool LoadChunk (Key chunk_key, std::shared_ptr< FileLoader > loader, std::mutex &image_mutex)
 Load a chunk from the file into the cache.
 

Private Attributes

int32_t _z
 The current Z coordinate.
 
int32_t _stokes
 The current Stokes coordinate.
 
std::list< TilePair_queue
 The queue which stores tiles in order of access time.
 
std::unordered_map< Key, std::list< TilePair >::iterator > _map
 The map which stores references to tiles in the queue.
 
int _capacity
 The maximum number of tiles which may be stored in the cache.
 
std::mutex _tile_cache_mutex
 The cache mutex.
 
std::vector< float > _chunk
 The vector used to load chunk data.
 
std::shared_ptr< TilePool_pool
 The pool used to store reusable tile objects.
 

Detailed Description

A cache for full-resolution image tiles.

A tile cache is used by Frame instead of a full image cache if its FileLoader reports that it should be used. Currently only the Hdf5Loader implements this. This implementation uses a pool to store reusable tile objects. This is an LRU cache: when tile capacity is reached, the least recently used tile is discarded first.

See also
FileLoader::UseTileCache
TilePool
TileCacheKey

Member Typedef Documentation

◆ Key

◆ TileIter

using carta::TileCache::TileIter = std::vector<float>::iterator
private

◆ TilePair

using carta::TileCache::TilePair = std::pair<Key, TilePtr>
private

Constructor & Destructor Documentation

◆ TileCache() [1/2]

carta::TileCache::TileCache ( )
inline

Default constructor.

◆ TileCache() [2/2]

TileCache::TileCache ( int  capacity)

Constructor used by Frame.

Parameters
capacityThe cache capacity

Member Function Documentation

◆ ChunkKey()

TileCache::Key TileCache::ChunkKey ( Key  tile_key)
static

Calculate the key for the chunk that contains the given tile.

Parameters
tile_keyThe tile key
Returns
The chunk key

HDF5 files produced by the fits2idia converter currently use a chunk size which is twice the tile size in each dimension. This means that each chunk is a block of 2x2 tiles.

See also
LoadChunk
Here is the caller graph for this function:

◆ Get()

TilePtr TileCache::Get ( Key  key,
std::shared_ptr< FileLoader loader,
std::mutex &  image_mutex 
)

Retrieve a tile from the cache.

Parameters
keyThe tile key

This function locks the cache because it modifies the cache state.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadChunk()

bool TileCache::LoadChunk ( Key  chunk_key,
std::shared_ptr< FileLoader loader,
std::mutex &  image_mutex 
)
private

Load a chunk from the file into the cache.

Parameters
chunk_keyThe key of the chunk.
loaderThe file loader.
image_mutexThe image mutex to pass to FileLoader::GetChunk.

When a requested tile is not found in the cache, for efficiency we read the entire chunk of data which contains that tile, and add all the tiles contained in the chunk into the cache at once.

See also
ChunkKey
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Peek()

TilePtr TileCache::Peek ( Key  key)

Retrieve a tile from the cache without modifying its access time.

Parameters
keyThe tile key

This is a read-only operation and does not lock the cache.

Here is the call graph for this function:

◆ Reset()

void TileCache::Reset ( int32_t  z,
int32_t  stokes,
int  capacity = 0 
)

Reset the cache for a new Z coordinate and/or Stokes coordinate, clearing all tiles.

Parameters
zThe new Z coordinate
stokesThe new Stokes coordinate
capacityThe new capacity

This function locks the cache because it modifies the cache state.

Here is the caller graph for this function:

◆ Touch()

void TileCache::Touch ( Key  key)
private

Update the access time of a tile.

Parameters
keyThe tile key

This function does not lock the cache, and assumes that the tile is in the cache.

Here is the caller graph for this function:

◆ UnsafePeek()

TilePtr TileCache::UnsafePeek ( Key  key)
private

Retrieve a tile from the cache.

Parameters
keyThe tile key

This function does not lock the cache, and assumes that the tile is in the cache.

Here is the caller graph for this function:

Member Data Documentation

◆ _capacity

int carta::TileCache::_capacity
private

The maximum number of tiles which may be stored in the cache.

◆ _chunk

std::vector<float> carta::TileCache::_chunk
private

The vector used to load chunk data.

◆ _map

std::unordered_map<Key, std::list<TilePair>::iterator> carta::TileCache::_map
private

The map which stores references to tiles in the queue.

◆ _pool

std::shared_ptr<TilePool> carta::TileCache::_pool
private

The pool used to store reusable tile objects.

◆ _queue

std::list<TilePair> carta::TileCache::_queue
private

The queue which stores tiles in order of access time.

◆ _stokes

int32_t carta::TileCache::_stokes
private

The current Stokes coordinate.

◆ _tile_cache_mutex

std::mutex carta::TileCache::_tile_cache_mutex
private

The cache mutex.

◆ _z

int32_t carta::TileCache::_z
private

The current Z coordinate.


The documentation for this class was generated from the following files: