GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GResponseVectorCache Class Reference

Response vector cache class. More...

#include <GResponseVectorCache.hpp>

Inheritance diagram for GResponseVectorCache:
GBase

Public Member Functions

 GResponseVectorCache (void)
 Void constructor. More...
 
 GResponseVectorCache (const GResponseVectorCache &cache)
 Copy constructor. More...
 
virtual ~GResponseVectorCache (void)
 Destructor. More...
 
GResponseVectorCacheoperator= (const GResponseVectorCache &cache)
 Assignment operator. More...
 
void clear (void)
 Clear response vector cache. More...
 
GResponseVectorCacheclone (void) const
 Clone response cache. More...
 
std::string classname (void) const
 Return class name. More...
 
bool is_empty (void) const
 Checks whether the cache is empty. More...
 
int size (void) const
 Returns size of vector chache. More...
 
void set (const std::string &cache_id, const GVector &vector)
 Set cache value. More...
 
void remove (const std::string &cache_id)
 Remove cache. More...
 
bool contains (const std::string &cache_id, GVector *irfs=NULL) const
 Check if cache contains a value for specific parameters. More...
 
void load (const GFilename &filename)
 Load response vector cache from FITS file. More...
 
void save (const GFilename &filename, const bool &clobber=false) const
 Save the response vector cache into FITS file. More...
 
void read (const GFitsTable &table)
 Read response vector cache from FITS table. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print response cache. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GResponseVectorCache &cache)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
int find_cache (const std::string &cache_id) const
 Find cache. More...
 

Protected Attributes

std::vector< std::string > m_cache_ids
 
std::vector< int > m_cache_entries
 
std::vector< double * > m_cache_values
 
std::vector< int * > m_cache_indices
 

Detailed Description

Response vector cache class.

The class implements a vector cache for the Instrument Response Function values so that the values do not need to be recomputed each time but can be fetched from the cache.

Definition at line 54 of file GResponseVectorCache.hpp.

Constructor & Destructor Documentation

GResponseVectorCache::GResponseVectorCache ( void  )

Void constructor.

Definition at line 61 of file GResponseVectorCache.cpp.

References init_members().

Referenced by clone().

GResponseVectorCache::GResponseVectorCache ( const GResponseVectorCache cache)

Copy constructor.

Parameters
[in]cacheResponse vector cache.

Definition at line 76 of file GResponseVectorCache.cpp.

References copy_members(), and init_members().

GResponseVectorCache::~GResponseVectorCache ( void  )
virtual

Destructor.

Definition at line 92 of file GResponseVectorCache.cpp.

References free_members().

Member Function Documentation

std::string GResponseVectorCache::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GResponseVectorCache").

Implements GBase.

Definition at line 103 of file GResponseVectorCache.hpp.

void GResponseVectorCache::clear ( void  )
virtual

Clear response vector cache.

Implements GBase.

Definition at line 144 of file GResponseVectorCache.cpp.

References free_members(), and init_members().

Referenced by GResponse::init_members().

GResponseVectorCache * GResponseVectorCache::clone ( void  ) const
virtual

Clone response cache.

Returns
Pointer to deep copy of response cache.

Implements GBase.

Definition at line 162 of file GResponseVectorCache.cpp.

References GResponseVectorCache().

bool GResponseVectorCache::contains ( const std::string &  cache_id,
GVector vector = NULL 
) const

Check if cache contains a value for specific parameters.

Parameters
[in]cache_idCache identifier.
[in,out]vectorPointer to cached vector (only if found).
Returns
True if cached value was found, otherwise false.

Check if the cache contains a value for a given name, reconstructed energy ereco, and true energy etrue.

If the value pointer argument is not NULL, the method will return the cached value through this argument in case that the value exists.

Definition at line 302 of file GResponseVectorCache.cpp.

References find_cache(), m_cache_entries, m_cache_indices, m_cache_values, and GVector::size().

Referenced by GResponse::irf_spatial().

void GResponseVectorCache::copy_members ( const GResponseVectorCache cache)
protected

Copy class members.

Parameters
[in]cacheResponse cache.

Definition at line 588 of file GResponseVectorCache.cpp.

References m_cache_entries, m_cache_ids, m_cache_indices, m_cache_values, and size().

Referenced by GResponseVectorCache(), and operator=().

int GResponseVectorCache::find_cache ( const std::string &  cache_id) const
protected

Find cache.

Parameters
[in]cache_idCache identifier.
Returns
Cache index (-1 if no cache was found)

Find cache for a given cache_id. If no cache was found the method returns -1.

Definition at line 642 of file GResponseVectorCache.cpp.

References m_cache_ids.

Referenced by contains(), remove(), and set().

void GResponseVectorCache::free_members ( void  )
protected

Delete class members.

Definition at line 618 of file GResponseVectorCache.cpp.

References m_cache_indices, m_cache_values, and size().

Referenced by clear(), load(), operator=(), and ~GResponseVectorCache().

void GResponseVectorCache::init_members ( void  )
protected

Initialise class members.

Definition at line 570 of file GResponseVectorCache.cpp.

References m_cache_entries, m_cache_ids, m_cache_indices, and m_cache_values.

Referenced by clear(), GResponseVectorCache(), load(), and operator=().

bool GResponseVectorCache::is_empty ( void  ) const
inline

Checks whether the cache is empty.

Returns
True if cache is empty, false otherwise.

Checks whether the response cache is empty.

Definition at line 117 of file GResponseVectorCache.hpp.

References m_cache_ids.

void GResponseVectorCache::load ( const GFilename filename)

Load response vector cache from FITS file.

Parameters
[in]filenameFITS file name.

Loads the response vector cache from a FITS file. All binary tables in the FITS file are assumed to be response vector cache entries.

Definition at line 362 of file GResponseVectorCache.cpp.

References GFits::close(), free_members(), GFitsHDU::HT_BIN_TABLE, init_members(), read(), GFits::size(), and GFits::table().

Referenced by GCOMResponse::load_cache().

GResponseVectorCache & GResponseVectorCache::operator= ( const GResponseVectorCache cache)

Assignment operator.

Parameters
[in]cacheResponse vector cache.
Returns
Response vector cache.

Definition at line 114 of file GResponseVectorCache.cpp.

References copy_members(), free_members(), and init_members().

std::string GResponseVectorCache::print ( const GChatter chatter = NORMAL) const
virtual

Print response cache.

Parameters
[in]chatterChattiness.
Returns
String containing response cache information.

Implements GBase.

Definition at line 532 of file GResponseVectorCache.cpp.

References m_cache_entries, m_cache_ids, gammalib::parformat(), SILENT, size(), and gammalib::str().

void GResponseVectorCache::read ( const GFitsTable table)

Read response vector cache from FITS table.

Parameters
[in]tableFITS table.

Reads response vector cache from a FITS table. There is one cache entry in a FITS table, with the table extension name specifying the cache identifier. Only tables containing the "HDUCLAS2" keyword set to "VECTOR_CACHE" will be considered by the method, all other tables will be simply skipped.

Definition at line 483 of file GResponseVectorCache.cpp.

References GFitsHDU::extname(), GFitsHDU::has_card(), GFitsTableCol::integer(), m_cache_entries, m_cache_ids, m_cache_indices, m_cache_values, GFitsTable::nrows(), GFitsTableCol::real(), and GFitsHDU::string().

Referenced by load().

void GResponseVectorCache::remove ( const std::string &  cache_id)

Remove cache.

Parameters
[in]cache_idCache identifier.

Remove cache for a given cache_id.

Definition at line 264 of file GResponseVectorCache.cpp.

References find_cache(), m_cache_entries, m_cache_ids, m_cache_indices, and m_cache_values.

Referenced by GResponse::remove_response_cache().

void GResponseVectorCache::save ( const GFilename filename,
const bool &  clobber = false 
) const

Save the response vector cache into FITS file.

Parameters
[in]filenameFITS file name.
[in]clobberOverwrite an response vector cache file?

Saves the response vector cache into a FITS file. If a file with the given filename does not yet exist it will be created, otherwise the method opens the existing file. The response vector cache can only be appended to an existing file if the clobber flag is set to "true" (otherwise an exception is thrown).

The method will append all cache entries as binary FITS tables to the FITS file. The table extension names are defined by the cache identifiers. All cache entries with identifiers exceeding 80 characters will be skipped to avoid truncation of cache identifiers.

Definition at line 408 of file GResponseVectorCache.cpp.

References GFitsTable::append(), GFitsHDU::card(), GFitsHDU::extname(), m_cache_entries, m_cache_ids, m_cache_indices, m_cache_values, size(), and GFilename::url().

Referenced by GCOMResponse::save_cache().

void GResponseVectorCache::set ( const std::string &  cache_id,
const GVector vector 
)

Set cache value.

Parameters
[in]cache_idCache identifier.
[in]vectorCache vector.

Set cache vector for a given cache_id.

Definition at line 176 of file GResponseVectorCache.cpp.

References find_cache(), m_cache_entries, m_cache_ids, m_cache_indices, m_cache_values, GVector::non_zeros(), and GVector::size().

Referenced by GResponse::irf_spatial().

int GResponseVectorCache::size ( void  ) const
inline

Returns size of vector chache.

Returns
Size of vector cache.

Returns the number of vectors that are stored in the vector cache.

Definition at line 131 of file GResponseVectorCache.hpp.

References m_cache_ids.

Referenced by copy_members(), free_members(), print(), and save().

Member Data Documentation

std::vector<int> GResponseVectorCache::m_cache_entries
protected

Definition at line 91 of file GResponseVectorCache.hpp.

Referenced by contains(), copy_members(), init_members(), print(), read(), remove(), save(), and set().

std::vector<std::string> GResponseVectorCache::m_cache_ids
protected
std::vector<int*> GResponseVectorCache::m_cache_indices
protected
std::vector<double*> GResponseVectorCache::m_cache_values
protected

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