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