GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GResponseVectorCache.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GResponseVectorCache.hpp - Response vector cache class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2020 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 _______________________________________________ */
36 class GVector;
37 
38 /* __ Constants __________________________________________________________ */
39 
40 /* __ Typedefs ___________________________________________________________ */
41 
42 
43 /***********************************************************************//**
44  * @class GResponseVectorCache
45  *
46  * @brief Response vector cache class
47  *
48  * The class implements a vector cache for the Instrument Response Function
49  * values so that the values do not need to be recomputed each time but can
50  * be fetched from the cache.
51  ***************************************************************************/
52 class GResponseVectorCache : public GBase {
53 
54 public:
55  // Constructors and destructors
58  virtual ~GResponseVectorCache(void);
59 
60  // Operators
62 
63  // Methods
64  void clear(void);
65  GResponseVectorCache* clone(void) const;
66  std::string classname(void) const;
67  bool is_empty(void) const;
68  int size(void) const;
69  void set(const std::string& cache_id,
70  const GVector& vector);
71  void remove(const std::string& cache_id);
72  bool contains(const std::string& cache_id,
73  GVector* irfs = NULL) const;
74  std::string print(const GChatter& chatter = NORMAL) const;
75 
76 protected:
77  // Protected methods
78  void init_members(void);
79  void copy_members(const GResponseVectorCache& cache);
80  void free_members(void);
81  int find_cache(const std::string& cache_id) const;
82 
83  // Protected members
84  std::vector<std::string> m_cache_ids;
85  std::vector<int> m_cache_entries;
86  std::vector<double*> m_cache_values;
87  std::vector<int*> m_cache_indices;
88 };
89 
90 
91 /***********************************************************************//**
92  * @brief Return class name
93  *
94  * @return String containing the class name ("GResponseVectorCache").
95  ***************************************************************************/
96 inline
97 std::string GResponseVectorCache::classname(void) const
98 {
99  return ("GResponseVectorCache");
100 }
101 
102 
103 /***********************************************************************//**
104  * @brief Checks whether the cache is empty
105  *
106  * @return True if cache is empty, false otherwise.
107  *
108  * Checks whether the response cache is empty.
109  ***************************************************************************/
110 inline
112 {
113  return (m_cache_ids.empty());
114 }
115 
116 
117 /***********************************************************************//**
118  * @brief Returns size of vector chache
119  *
120  * @return Size of vector cache.
121  *
122  * Returns the number of vectors that are stored in the vector cache.
123  ***************************************************************************/
124 inline
126 {
127  return ((int)m_cache_ids.size());
128 }
129 
130 #endif /* GRESPONSEVECTORCACHE_HPP */
GResponseVectorCache(void)
Void constructor.
Response vector cache class.
std::vector< int > m_cache_entries
std::string print(const GChatter &chatter=NORMAL) const
Print response cache.
Definition of interface for all GammaLib classes.
void set(const std::string &cache_id, const GVector &vector)
Set cache value.
virtual ~GResponseVectorCache(void)
Destructor.
std::string classname(void) const
Return class name.
void init_members(void)
Initialise class members.
std::vector< double * > m_cache_values
int size(void) const
Returns size of vector chache.
int find_cache(const std::string &cache_id) const
Find cache.
void free_members(void)
Delete class members.
GResponseVectorCache * clone(void) const
Clone response cache.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
GResponseVectorCache & operator=(const GResponseVectorCache &cache)
Assignment operator.
GChatter
Definition: GTypemaps.hpp:33
void copy_members(const GResponseVectorCache &cache)
Copy class members.
void clear(void)
Clear response vector cache.
bool contains(const std::string &cache_id, GVector *irfs=NULL) const
Check if cache contains a value for specific parameters.
std::vector< int * > m_cache_indices
Vector class.
Definition: GVector.hpp:46
std::vector< std::string > m_cache_ids
bool is_empty(void) const
Checks whether the cache is empty.