GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GResponseCache Class Reference

Response cache class. More...

#include <GResponseCache.hpp>

Inheritance diagram for GResponseCache:
GBase

Public Member Functions

 GResponseCache (void)
 Void constructor. More...
 
 GResponseCache (const GResponseCache &cache)
 Copy constructor. More...
 
virtual ~GResponseCache (void)
 Destructor. More...
 
GResponseCacheoperator= (const GResponseCache &cache)
 Assignment operator. More...
 
void clear (void)
 Clear response cache. More...
 
GResponseCacheclone (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
 Return number of elements in cache. More...
 
int nenergies (void) const
 Return number of energies in cache. More...
 
void set (const std::string &name, const GEnergy &ereco, const GEnergy &etrue, const double &value)
 Set cache value. More...
 
void set (const std::string &name, const GInstDir &dir, const GEnergy &ereco, const GEnergy &etrue, const double &value)
 Set cache value. More...
 
void remove (const std::string &name)
 Remove cache for source. More...
 
bool contains (const std::string &name, const GEnergy &ereco, const GEnergy &etrue, double *value=NULL) const
 Check if cache contains a value for specific parameters. More...
 
bool contains (const std::string &name, const GInstDir &dir, const GEnergy &ereco, const GEnergy &etrue, double *value=NULL) const
 Check if cache contains a value for specific parameters. 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 GResponseCache &cache)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
u_int64_t hash (const GEnergy &ereco, const GEnergy &etrue) const
 Encode reconstructued and true energy into hash value. More...
 

Protected Attributes

GResponseCacheName m_cache
 

Detailed Description

Response cache class.

The class implements a 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 60 of file GResponseCache.hpp.

Constructor & Destructor Documentation

GResponseCache::GResponseCache ( void  )

Void constructor.

Definition at line 54 of file GResponseCache.cpp.

References init_members().

Referenced by clone().

GResponseCache::GResponseCache ( const GResponseCache cache)

Copy constructor.

Parameters
[in]cacheResponse cache.

Definition at line 69 of file GResponseCache.cpp.

References copy_members(), and init_members().

GResponseCache::~GResponseCache ( void  )
virtual

Destructor.

Definition at line 85 of file GResponseCache.cpp.

References free_members().

Member Function Documentation

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

Return class name.

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

Implements GBase.

Definition at line 117 of file GResponseCache.hpp.

void GResponseCache::clear ( void  )
virtual

Clear response cache.

Implements GBase.

Definition at line 137 of file GResponseCache.cpp.

References free_members(), and init_members().

Referenced by GResponse::init_members().

GResponseCache * GResponseCache::clone ( void  ) const
virtual

Clone response cache.

Returns
Pointer to deep copy of response cache.

Implements GBase.

Definition at line 378 of file GResponseCache.cpp.

References GResponseCache().

bool GResponseCache::contains ( const std::string &  name,
const GEnergy ereco,
const GEnergy etrue,
double *  value = NULL 
) const

Check if cache contains a value for specific parameters.

Parameters
[in]nameCache name.
[in]erecoReconstructed energy.
[in]etrueTrue energy.
[out]valuePointer to cached value (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 276 of file GResponseCache.cpp.

References hash(), and m_cache.

Referenced by contains(), GCTAResponseCube::irf_spatial(), GResponse::irf_spatial(), and GCTAResponseIrf::nroi().

bool GResponseCache::contains ( const std::string &  name,
const GInstDir dir,
const GEnergy ereco,
const GEnergy etrue,
double *  value = NULL 
) const

Check if cache contains a value for specific parameters.

Parameters
[in]nameCache name.
[in]dirInstrument direction.
[in]erecoReconstructed energy.
[in]etrueTrue energy.
[out]valuePointer to cached value (only if found).
Returns
True if cached value was found, otherwise false.

Check if the cache contains a value for a given name, instrument direction dir, 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 332 of file GResponseCache.cpp.

References contains(), GInstDir::hash(), hash(), and m_cache.

void GResponseCache::copy_members ( const GResponseCache cache)
protected

Copy class members.

Parameters
[in]cacheResponse cache.

Definition at line 465 of file GResponseCache.cpp.

References m_cache.

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

void GResponseCache::free_members ( void  )
protected

Delete class members.

Definition at line 478 of file GResponseCache.cpp.

Referenced by clear(), operator=(), and ~GResponseCache().

u_int64_t GResponseCache::hash ( const GEnergy ereco,
const GEnergy etrue 
) const
protected

Encode reconstructued and true energy into hash value.

Parameters
[in]erecoReconstructed energy.
[in]etrueTrue energy.
Returns
Encoded reconstructued and true energy

Encodes the reconstructued and true energy in a 64 Bit unsigned integer value. The energy are converted into single precision floating point values and mapped on a 64 Bit unsigned integer value. This provides unique hash values for all instruments up to the precision of floating point singles.

Definition at line 498 of file GResponseCache.cpp.

References GEnergy::MeV().

Referenced by contains(), and set().

void GResponseCache::init_members ( void  )
protected

Initialise class members.

Definition at line 450 of file GResponseCache.cpp.

References m_cache.

Referenced by clear(), GResponseCache(), and operator=().

bool GResponseCache::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 131 of file GResponseCache.hpp.

References m_cache.

int GResponseCache::nenergies ( void  ) const

Return number of energies in cache.

Returns
Number of energies in cache

Returns the number of energies in the response cache.

Definition at line 184 of file GResponseCache.cpp.

References m_cache.

Referenced by print().

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

Assignment operator.

Parameters
[in]cacheResponse cache.
Returns
Response cache.

Definition at line 107 of file GResponseCache.cpp.

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

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

Print response cache.

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

Implements GBase.

Definition at line 390 of file GResponseCache.cpp.

References m_cache, nenergies(), gammalib::parformat(), SILENT, size(), and gammalib::str().

Referenced by GCTAResponseIrf::print(), and GCTAResponseCube::print().

void GResponseCache::remove ( const std::string &  name)
inline

Remove cache for source.

Parameters
[in]nameSource name.

Remove cache for source with name.

Definition at line 145 of file GResponseCache.hpp.

References m_cache.

Referenced by GResponse::remove_response_cache().

void GResponseCache::set ( const std::string &  name,
const GEnergy ereco,
const GEnergy etrue,
const double &  value 
)

Set cache value.

Parameters
[in]nameCache name.
[in]erecoReconstructed energy.
[in]etrueTrue energy.
[in]valueCache value.

Set cache value for a given name, reconstructed energy ereco, and true energy etrue.

Definition at line 215 of file GResponseCache.cpp.

References hash(), and m_cache.

Referenced by GCTAResponseCube::irf_spatial(), GResponse::irf_spatial(), and GCTAResponseIrf::nroi().

void GResponseCache::set ( const std::string &  name,
const GInstDir dir,
const GEnergy ereco,
const GEnergy etrue,
const double &  value 
)

Set cache value.

Parameters
[in]nameCache name.
[in]dirInstrument direction.
[in]erecoReconstructed energy.
[in]etrueTrue energy.
[in]valueCache value.

Set cache value for a given name, instrument direction dir, reconstructed energy ereco, and true energy etrue.

Definition at line 243 of file GResponseCache.cpp.

References GInstDir::hash(), hash(), and m_cache.

int GResponseCache::size ( void  ) const

Return number of elements in cache.

Returns
Number of elements in cache

Returns the number of elements in the response cache.

Definition at line 157 of file GResponseCache.cpp.

References m_cache.

Referenced by print().

Member Data Documentation

GResponseCacheName GResponseCache::m_cache
protected

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