GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GResponseCache.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GResponseCache.hpp - Response 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 GResponseCache.hpp
23  * @brief Response cache class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GRESPONSECACHE_HPP
28 #define GRESPONSECACHE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <sys/types.h>
33 #if defined(__sun) && (defined(__svr4__) || defined(__SVR4)) // SOLARIS
34  typedef uint64_t u_int64_t;
35 #endif // SOLARIS
36 #include <map>
37 #include "GBase.hpp"
38 #include "GEnergy.hpp"
39 
40 /* __ Forward declarations _______________________________________________ */
41 class GInstDir;
42 
43 /* __ Constants __________________________________________________________ */
44 
45 /* __ Typedefs ___________________________________________________________ */
46 typedef std::map<u_int64_t,double> GResponseCacheDir;
47 typedef std::map<u_int64_t,GResponseCacheDir> GResponseCacheEnergy;
48 typedef std::map<std::string,GResponseCacheEnergy> GResponseCacheName;
49 
50 
51 /***********************************************************************//**
52  * @class GResponseCache
53  *
54  * @brief Response cache class
55  *
56  * The class implements a cache for the Instrument Response Function values
57  * so that the values do not need to be recomputed each time but can be
58  * fetched from the cache.
59  ***************************************************************************/
60 class GResponseCache : public GBase {
61 
62 public:
63  // Constructors and destructors
64  GResponseCache(void);
65  GResponseCache(const GResponseCache& cache);
66  virtual ~GResponseCache(void);
67 
68  // Operators
70 
71  // Methods
72  void clear(void);
73  GResponseCache* clone(void) const;
74  std::string classname(void) const;
75  bool is_empty(void) const;
76  int size(void) const;
77  int nenergies(void) const;
78  void set(const std::string& name,
79  const GEnergy& ereco,
80  const GEnergy& etrue,
81  const double& value);
82  void set(const std::string& name,
83  const GInstDir& dir,
84  const GEnergy& ereco,
85  const GEnergy& etrue,
86  const double& value);
87  void remove(const std::string& name);
88  bool contains(const std::string& name,
89  const GEnergy& ereco,
90  const GEnergy& etrue,
91  double* value = NULL) const;
92  bool contains(const std::string& name,
93  const GInstDir& dir,
94  const GEnergy& ereco,
95  const GEnergy& etrue,
96  double* value = NULL) const;
97  std::string print(const GChatter& chatter = NORMAL) const;
98 
99 protected:
100  // Protected methods
101  void init_members(void);
102  void copy_members(const GResponseCache& cache);
103  void free_members(void);
104  u_int64_t hash(const GEnergy& ereco, const GEnergy& etrue) const;
105 
106  // Protected members
107  GResponseCacheName m_cache; //<! Response cache
108 };
109 
110 
111 /***********************************************************************//**
112  * @brief Return class name
113  *
114  * @return String containing the class name ("GResponseCache").
115  ***************************************************************************/
116 inline
117 std::string GResponseCache::classname(void) const
118 {
119  return ("GResponseCache");
120 }
121 
122 
123 /***********************************************************************//**
124  * @brief Checks whether the cache is empty
125  *
126  * @return True if cache is empty, false otherwise.
127  *
128  * Checks whether the response cache is empty.
129  ***************************************************************************/
130 inline
131 bool GResponseCache::is_empty(void) const
132 {
133  return (m_cache.empty());
134 }
135 
136 
137 /***********************************************************************//**
138  * @brief Remove cache for source
139  *
140  * @param[in] name Source name.
141  *
142  * Remove cache for source with @p name.
143  ***************************************************************************/
144 inline
145 void GResponseCache::remove(const std::string& name)
146 {
147  m_cache.erase(name);
148  return;
149 }
150 
151 #endif /* GRESPONSECACHE_HPP */
std::map< std::string, GResponseCacheEnergy > GResponseCacheName
std::map< u_int64_t, GResponseCacheDir > GResponseCacheEnergy
void free_members(void)
Delete class members.
Energy value class definition.
void init_members(void)
Initialise class members.
std::string classname(void) const
Return class name.
GResponseCache & operator=(const GResponseCache &cache)
Assignment operator.
Definition of interface for all GammaLib classes.
GResponseCache(void)
Void constructor.
void copy_members(const GResponseCache &cache)
Copy class members.
int size(void) const
Return number of elements in cache.
u_int64_t hash(const GEnergy &ereco, const GEnergy &etrue) const
Encode reconstructued and true energy into hash value.
Abstract instrument direction base class.
Definition: GInstDir.hpp:51
void remove(const std::string &name)
Remove cache for source.
std::map< u_int64_t, double > GResponseCacheDir
virtual ~GResponseCache(void)
Destructor.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
bool is_empty(void) const
Checks whether the cache is empty.
GChatter
Definition: GTypemaps.hpp:33
GResponseCacheName m_cache
int nenergies(void) const
Return number of energies in cache.
GResponseCache * clone(void) const
Clone response cache.
void clear(void)
Clear response cache.
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.
Response cache class.
void set(const std::string &name, const GEnergy &ereco, const GEnergy &etrue, const double &value)
Set cache value.
std::string print(const GChatter &chatter=NORMAL) const
Print response cache.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48