Jpp
JMultiGrid.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JMULTIGRID__
2 #define __JTOOLS__JMULTIGRID__
3 
5 #include "JTools/JGrid.hh"
6 
7 
8 /**
9  * \author mdejong
10  */
11 
12 namespace JTOOLS {}
13 namespace JPP { using namespace JTOOLS; }
14 
15 namespace JTOOLS {
16 
17 
18  /**
19  * Simple data structure for an abstract multidimensional map of equidistant elements.
20  *
21  * This class implements the JAbstractMultiMap interface.
22  */
23  template<unsigned int N, class JAbscissa_t>
24  struct JMultiGrid :
25  public virtual JAbstractMultiMap<N, JAbscissa_t>,
26  public JMultiGrid<N - 1, JAbscissa_t>
27  {
28  typedef JAbscissa_t abscissa_type;
29  typedef JMultiKey<N - 1, abscissa_type> key_type;
30 
32 
33 
34  /**
35  * Default constructor.
36  */
38  JMultiGrid<N - 1, JAbscissa_t>()
39  {}
40 
41 
42  /**
43  * Constructor.
44  *
45  * \param bounds bounds
46  */
48  JMultiGrid<N - 1, JAbscissa_t>(bounds)
49  {
50  this->bounds = bounds;
51  }
52 
53 
54  /**
55  * Set bounds.
56  *
57  * \param index index of dimension
58  * \param bounds bounds
59  * \return true if correctly set; else false
60  */
61  bool set(unsigned int index, const JGrid<abscissa_type>& bounds)
62  {
63  if (index == N - 1) {
64 
65  this->bounds = bounds;
66 
67  } else if (index < N - 1) {
68 
69  return static_cast<JMultiGrid<N - 1, abscissa_type>&>(*this).set(index, bounds);
70  }
71 
72  return false;
73  }
74 
75 
76  /**
77  * Get abscissa values as a function of given key.
78  *
79  * \param key key
80  * \return abscissa values
81  */
82  virtual const JGrid<abscissa_type>& operator()(const key_type& key) const
83  {
84  return bounds;
85  }
86 
87  protected:
89  };
90 
91 
92  /**
93  * Terminator class of recursive class JMultiGrid.
94  * This class provides for dummy implementations of interface methods.
95  */
96  template<class JAbscissa_t>
97  struct JMultiGrid<0, JAbscissa_t>
98  {
99  protected:
100 
101  typedef JAbscissa_t abscissa_type;
102 
103  friend class JMultiGrid<1, JAbscissa_t>;
104 
105 
106  /**
107  * Default constructor.
108  */
110  {}
111 
112 
113  /**
114  * Constructor.
115  *
116  * \param bounds bounds
117  */
119  {}
120 
121 
122  /**
123  * This method does nothing.
124  *
125  * \param index index
126  * \param bounds bounds
127  * \return false
128  */
129  bool set(unsigned int index, const JGrid<abscissa_type>& bounds) const
130  {
131  return false;
132  }
133 
134 
135  /**
136  * Dummy operator.
137  */
138  void operator()() const
139  {}
140  };
141 
142 
143  /**
144  * Helper method for JMultiGrid.
145  *
146  * \param bounds bounds
147  * \return multidimensional grid
148  */
149  template<unsigned int N, class JAbscissa_t>
151  {
152  return JMultiGrid<N, JAbscissa_t>(bounds);
153  }
154 }
155 
156 #endif
JTOOLS::JMultiGrid< 0, JAbscissa_t >::JMultiGrid
JMultiGrid()
Default constructor.
Definition: JMultiGrid.hh:109
JTOOLS::JMultiGrid::operator()
virtual const JGrid< abscissa_type > & operator()(const key_type &key) const
Get abscissa values as a function of given key.
Definition: JMultiGrid.hh:82
JTOOLS::make_multigrid
JMultiGrid< N, JAbscissa_t > make_multigrid(const JGrid< JAbscissa_t > &bounds)
Helper method for JMultiGrid.
Definition: JMultiGrid.hh:150
JTOOLS::JMultiGrid< 0, JAbscissa_t >::operator()
void operator()() const
Dummy operator.
Definition: JMultiGrid.hh:138
JGrid.hh
JAbstractMultiMap.hh
JTOOLS::JMultiGrid< 0, JAbscissa_t >::set
bool set(unsigned int index, const JGrid< abscissa_type > &bounds) const
This method does nothing.
Definition: JMultiGrid.hh:129
JTOOLS::JMultiGrid::abscissa_type
JAbscissa_t abscissa_type
Definition: JMultiGrid.hh:28
JTOOLS::JMultiGrid::bounds
JGrid< JAbscissa_t > bounds
Definition: JMultiGrid.hh:88
JTOOLS::JMultiGrid< 0, JAbscissa_t >::JMultiGrid
JMultiGrid(const JGrid< abscissa_type > &bounds)
Constructor.
Definition: JMultiGrid.hh:118
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTOOLS::JGrid
Simple data structure for an abstract collection of equidistant abscissa values.
Definition: JGrid.hh:32
JTOOLS::JMultiGrid::set
bool set(unsigned int index, const JGrid< abscissa_type > &bounds)
Set bounds.
Definition: JMultiGrid.hh:61
JTOOLS::JMultiGrid< 0, JAbscissa_t >::abscissa_type
JAbscissa_t abscissa_type
Definition: JMultiGrid.hh:101
JTOOLS::JAbstractMultiMap::abscissa_type
JAbscissa_t abscissa_type
Definition: JAbstractMultiMap.hh:27
JTOOLS::JMultiKey
Forward declaration of template JMultiKey class.
Definition: JMultiKey.hh:29
JTOOLS::JMultiGrid::key_type
JMultiKey< N - 1, abscissa_type > key_type
Definition: JMultiGrid.hh:29
JTOOLS::JMultiGrid::JMultiGrid
JMultiGrid()
Default constructor.
Definition: JMultiGrid.hh:37
JTOOLS::JAbstractMultiMap
Abstract interface for abscissa values of a multidimensional map.
Definition: JAbstractMultiMap.hh:24
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
JTOOLS::JMultiGrid::JMultiGrid
JMultiGrid(const JGrid< abscissa_type > &bounds)
Constructor.
Definition: JMultiGrid.hh:47
JTOOLS::JMultiGrid
Simple data structure for an abstract multidimensional map of equidistant elements.
Definition: JMultiGrid.hh:24