GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GResponseVectorCache.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GResponseVectorCache.hpp - Response vector cache class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2020-2022 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GResponseVectorCache.hpp
23 * @brief Response vector cache class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GRESPONSEVECTORCACHE_HPP
28#define GRESPONSEVECTORCACHE_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <vector>
32#include <string>
33#include "GBase.hpp"
34
35/* __ Forward declarations _______________________________________________ */
36class GVector;
37class GFilename;
38class GFitsTable;
39
40/* __ Constants __________________________________________________________ */
41
42/* __ Typedefs ___________________________________________________________ */
43
44
45/***********************************************************************//**
46 * @class GResponseVectorCache
47 *
48 * @brief Response vector cache class
49 *
50 * The class implements a vector cache for the Instrument Response Function
51 * values so that the values do not need to be recomputed each time but can
52 * be fetched from the cache.
53 ***************************************************************************/
55
56public:
57 // Constructors and destructors
60 virtual ~GResponseVectorCache(void);
61
62 // Operators
64
65 // Methods
66 void clear(void);
67 GResponseVectorCache* clone(void) const;
68 std::string classname(void) const;
69 bool is_empty(void) const;
70 int size(void) const;
71 void set(const std::string& cache_id,
72 const GVector& vector);
73 void remove(const std::string& cache_id);
74 bool contains(const std::string& cache_id,
75 GVector* irfs = NULL) const;
76 void load(const GFilename& filename);
77 void save(const GFilename& filename,
78 const bool& clobber = false) const;
79 void read(const GFitsTable& table);
80 std::string print(const GChatter& chatter = NORMAL) const;
81
82protected:
83 // Protected methods
84 void init_members(void);
85 void copy_members(const GResponseVectorCache& cache);
86 void free_members(void);
87 int find_cache(const std::string& cache_id) const;
88
89 // Protected members
90 std::vector<std::string> m_cache_ids;
91 std::vector<int> m_cache_entries;
92 std::vector<double*> m_cache_values;
93 std::vector<int*> m_cache_indices;
94};
95
96
97/***********************************************************************//**
98 * @brief Return class name
99 *
100 * @return String containing the class name ("GResponseVectorCache").
101 ***************************************************************************/
102inline
103std::string GResponseVectorCache::classname(void) const
104{
105 return ("GResponseVectorCache");
106}
107
108
109/***********************************************************************//**
110 * @brief Checks whether the cache is empty
111 *
112 * @return True if cache is empty, false otherwise.
113 *
114 * Checks whether the response cache is empty.
115 ***************************************************************************/
116inline
118{
119 return (m_cache_ids.empty());
120}
121
122
123/***********************************************************************//**
124 * @brief Returns size of vector chache
125 *
126 * @return Size of vector cache.
127 *
128 * Returns the number of vectors that are stored in the vector cache.
129 ***************************************************************************/
130inline
132{
133 return ((int)m_cache_ids.size());
134}
135
136#endif /* GRESPONSEVECTORCACHE_HPP */
Definition of interface for all GammaLib classes.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface class for all GammaLib classes.
Definition GBase.hpp:52
Filename class.
Definition GFilename.hpp:62
Abstract interface for FITS table.
Response vector cache class.
std::string print(const GChatter &chatter=NORMAL) const
Print response cache.
bool contains(const std::string &cache_id, GVector *irfs=NULL) const
Check if cache contains a value for specific parameters.
bool is_empty(void) const
Checks whether the cache is empty.
void read(const GFitsTable &table)
Read response vector cache from FITS table.
void free_members(void)
Delete class members.
int size(void) const
Returns size of vector chache.
std::vector< int > m_cache_entries
virtual ~GResponseVectorCache(void)
Destructor.
std::vector< int * > m_cache_indices
GResponseVectorCache(void)
Void constructor.
void save(const GFilename &filename, const bool &clobber=false) const
Save the response vector cache into FITS file.
std::vector< double * > m_cache_values
void remove(const std::string &cache_id)
Remove cache.
void copy_members(const GResponseVectorCache &cache)
Copy class members.
void init_members(void)
Initialise class members.
void clear(void)
Clear response vector cache.
int find_cache(const std::string &cache_id) const
Find cache.
std::vector< std::string > m_cache_ids
void load(const GFilename &filename)
Load response vector cache from FITS file.
void set(const std::string &cache_id, const GVector &vector)
Set cache value.
GResponseVectorCache * clone(void) const
Clone response cache.
std::string classname(void) const
Return class name.
GResponseVectorCache & operator=(const GResponseVectorCache &cache)
Assignment operator.
Vector class.
Definition GVector.hpp:46