Jpp
JMultiMapTransformer.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JMULTIMAPTRANSFORMER__
2 #define __JTOOLS__JMULTIMAPTRANSFORMER__
3 
4 #include <stdarg.h>
5 
6 #include "JLang/JClonable.hh"
7 #include "JIO/JSerialisable.hh"
8 #include "JTools/JArray.hh"
9 #include "JTools/JTransformer.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JTOOLS {}
17 namespace JPP { using namespace JTOOLS; }
18 
19 namespace JTOOLS {
20 
21  using JLANG::JClonable;
22  using JIO::JSerialisable;
23  using JIO::JReader;
24  using JIO::JWriter;
25 
26 
27  /**
28  * Interface for weight application and coordinate transformation of function.
29  *
30  * The template parameters refer to the dimension of the map and the data type of the argument, respectively.
31  *
32  * This class extends the JClonable and JSerialisable interfacea.
33  */
34  template<unsigned int N, class JArgument_t>
36  public JClonable< JMultiMapTransformer<N, JArgument_t> >,
37  public JSerialisable
38  {
39  public:
40 
42 
44  typedef JArgument_t argument_type;
47 
48 
49  /**
50  * Evaluate xn value as a function of {x0, ..., xn-1}
51  *
52  * \param buffer x0 - xn-1 values
53  * \param xn xn value
54  * \return xn value
55  */
56  virtual argument_type putXn(const_array_type& buffer, const argument_type xn) const = 0;
57 
58 
59  /**
60  * Evaluate xn value as a function of {x0, ..., xn-1}
61  *
62  * \param buffer x0 - xn-1 values
63  * \param xn xn value
64  * \return xn value
65  */
66  virtual argument_type getXn(const_array_type& buffer, const argument_type xn) const = 0;
67 
68 
69  /**
70  * Weight function.
71  *
72  * \param buffer x0 - xn-1 values
73  * \return weight
74  */
75  virtual double getWeight(const_array_type& buffer) const = 0;
76 
77 
78  /**
79  * Weight function.
80  *
81  * \param x comma seperated list of abscissa values
82  * \return weight
83  */
84  double getWeight(const argument_type x, ...) const
85  {
86  va_start(ap, x);
87 
88  buffer[0] = x;
89 
90  for (int i = 1; i != N; ++i) {
91  buffer[i] = va_arg(ap, argument_type);
92  }
93 
94  va_end(ap);
95 
96  return getWeight(buffer);
97  }
98 
99 
100  /**
101  * Default implementation of weight application and coordinate transformation of function.
102  */
103  class JMultiMapDefaultTransformer;
104 
105 
106  /**
107  * Get default transformer.
108  *
109  * \return default transformer
110  */
112  {
113  static const JMultiMapDefaultTransformer transformer;
114 
115  return transformer;
116  }
117 
118 
119  /**
120  * Get clone of default transformer.
121  *
122  * \return pointer to newly created transformer
123  */
125  {
126  return new JMultiMapDefaultTransformer();
127  }
128 
129 
130  private:
131  mutable va_list ap;
133  };
134 
135 
136  /**
137  * Default implementation of weight application and coordinate transformation of function.
138  *
139  * The coordiniate transformation has no effect and the weight is equal to one.
140  *
141  * This class implements the JMultiMapTransformer, JClonable and JSerialisable interfaces.
142  */
143  template<unsigned int N, class JArgument_t>
145  public JMultiMapTransformer<N, JArgument_t>
146  {
147  public:
148 
149  /**
150  * Default constructor.
151  */
153  {}
154 
155 
156  /**
157  * Clone object.
158  *
159  * \return pointer to newly created transformer
160  */
161  virtual clone_type clone() const
162  {
163  return new JMultiMapDefaultTransformer(*this);
164  }
165 
166 
167  /**
168  * Evaluate xn value as a function of {x0, ..., xn-1}
169  *
170  * \param buffer x0 - xn-1 values
171  * \param xn xn value
172  * \return xn value
173  */
175  {
176  return xn;
177  }
178 
179 
180  /**
181  * Evaluate xn value as a function of {x0, ..., xn-1}
182  *
183  * \param buffer x0 - xn-1 values
184  * \param xn xn value
185  * \return xn value
186  */
188  {
189  return xn;
190  }
191 
192 
193  /**
194  * Weight function.
195  *
196  * \param buffer x0 - xn-1 values
197  * \return weight
198  */
199  virtual double getWeight(const_array_type& buffer) const
200  {
201  return 1.0;
202  }
203 
204 
205  /**
206  * Read from input.
207  *
208  * This method reads nothing.
209  *
210  * \param in reader
211  * \return reader
212  */
213  virtual JReader& read(JReader& in)
214  {
215  return in;
216  }
217 
218 
219  /**
220  * Write to output.
221  *
222  * This method writes nothing.
223  *
224  * \param out writer
225  * \return writer
226  */
227  virtual JWriter& write(JWriter& out) const
228  {
229  return out;
230  }
231  };
232 
233 
234  /**
235  * Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
236  *
237  * This class implements the JCollectionElementTransformer interface.
238  */
239  template<unsigned int N, class JElement_t>
241  public JCollectionElementTransformer<JElement_t>
242  {
243  public:
244 
245  typedef typename JElement_t::abscissa_type abscissa_type;
246  typedef typename JElement_t::ordinate_type ordinate_type;
247 
249 
251 
252 
253  /**
254  * Constructor.
255  *
256  * \param __transformer multidimensional map transformer
257  * \param __buffer x0 - xn-1 values
258  */
260  const_array_type& __buffer) :
261  transformer(__transformer),
262  buffer (__buffer),
263  W(transformer.getWeight(buffer))
264  {}
265 
266 
267  /**
268  * Transform element.
269  *
270  * \param element input element
271  * \return output element
272  */
273  virtual JElement_t operator()(const JElement_t& element) const
274  {
275  return JElement_t(transformer.putXn(buffer, element.getX()), element.getY() / W);
276  }
277 
278  private:
281  const double W;
282  };
283 
284 
285  /**
286  * Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
287  *
288  * This class implements the JCollectionElementTransformer interface.
289  */
290  template<unsigned int N, class JElement_t>
292  public JCollectionElementTransformer<JElement_t>
293  {
294  public:
295 
296  typedef typename JElement_t::abscissa_type abscissa_type;
297  typedef typename JElement_t::ordinate_type ordinate_type;
298 
300 
302 
303 
304  /**
305  * Constructor.
306  *
307  * \param __transformer multidimensional map transformer
308  * \param __buffer x0 - xn-1 values
309  */
311  const_array_type& __buffer) :
312  transformer(__transformer),
313  buffer (__buffer),
314  W(transformer.getWeight(buffer))
315  {}
316 
317 
318  /**
319  * Transform element.
320  *
321  * \param element input element
322  * \return output element
323  */
324  virtual JElement_t operator()(const JElement_t& element) const
325  {
326  return JElement_t(transformer.getXn(buffer, element.getX()), element.getY() * W);
327  }
328 
329  private:
332  const double W;
333  };
334 
335 
336  /**
337  * Abstract interface for transformable multidimensional map.
338  *
339  * The template parameters refer to the dimension of the map and the data type of the argument, respectively.
340  */
341  template<unsigned int N, class JArgument_t>
343  {
344  typedef JArgument_t argument_type;
346 
347  /**
348  * Application of transformation.
349  *
350  * \param transformer function transformer
351  */
352  virtual void transform(const transformer_type& transformer) = 0;
353  };
354 }
355 
356 #endif
JTOOLS::JMultiMapGetTransformer
Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
Definition: JMultiMapTransformer.hh:291
JTOOLS::JMultiMapTransformer::ap
va_list ap
Definition: JMultiMapTransformer.hh:131
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JTOOLS::JMultiMapPutTransformer::transformer
const transformer_type & transformer
Definition: JMultiMapTransformer.hh:279
JTOOLS::JMultiMapGetTransformer::transformer_type
JMultiMapTransformer< N, abscissa_type > transformer_type
Definition: JMultiMapTransformer.hh:299
JTOOLS::JMultiMapTransformer::JMultiMapDefaultTransformer::write
virtual JWriter & write(JWriter &out) const
Write to output.
Definition: JMultiMapTransformer.hh:227
JTOOLS::JMultiMapTransformer::JMultiMapDefaultTransformer::read
virtual JReader & read(JReader &in)
Read from input.
Definition: JMultiMapTransformer.hh:213
JTOOLS::JMultiMapGetTransformer::JMultiMapGetTransformer
JMultiMapGetTransformer(const transformer_type &__transformer, const_array_type &__buffer)
Constructor.
Definition: JMultiMapTransformer.hh:310
JTOOLS::JMultiMapTransformer::buffer
JArray< N, argument_type > buffer
Definition: JMultiMapTransformer.hh:132
JIO::JSerialisable
Forward declaration of binary output.
Definition: JSerialisable.hh:31
JTOOLS::JMultiMapGetTransformer::const_array_type
transformer_type::const_array_type const_array_type
Definition: JMultiMapTransformer.hh:301
JTOOLS::JMultiMapTransformer::clone_type
JClonable< multimaptransformer_type >::clone_type clone_type
Definition: JMultiMapTransformer.hh:43
JTOOLS::JMultiMapPutTransformer::ordinate_type
JElement_t::ordinate_type ordinate_type
Definition: JMultiMapTransformer.hh:246
JTOOLS::JArray< N, argument_type >
JTOOLS::JMultiMapTransformer::multimaptransformer_type
JMultiMapTransformer< N, JArgument_t > multimaptransformer_type
Definition: JMultiMapTransformer.hh:41
JTOOLS::JMultiMapPutTransformer::buffer
const_array_type buffer
Definition: JMultiMapTransformer.hh:280
JTOOLS::JMultiMapGetTransformer::ordinate_type
JElement_t::ordinate_type ordinate_type
Definition: JMultiMapTransformer.hh:297
JTOOLS::JMultiMapPutTransformer::const_array_type
transformer_type::const_array_type const_array_type
Definition: JMultiMapTransformer.hh:250
JTOOLS::JMultiMapTransformer::getClone
static JMultiMapTransformer * getClone()
Get clone of default transformer.
Definition: JMultiMapTransformer.hh:124
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTOOLS::JMultiMapTransformer::getWeight
double getWeight(const argument_type x,...) const
Weight function.
Definition: JMultiMapTransformer.hh:84
JTOOLS::JMultiMapPutTransformer::abscissa_type
JElement_t::abscissa_type abscissa_type
Definition: JMultiMapTransformer.hh:245
JSerialisable.hh
JTOOLS::JMultiMapTransformer::getDefaultTransformer
static const JMultiMapTransformer & getDefaultTransformer()
Get default transformer.
Definition: JMultiMapTransformer.hh:111
JLANG::JClonable::clone_type
JClonable< JClonable_t >::clone_type clone_type
Definition: JClonable.hh:61
JTOOLS::JMultiMapTransformer::JMultiMapDefaultTransformer::getWeight
virtual double getWeight(const_array_type &buffer) const
Weight function.
Definition: JMultiMapTransformer.hh:199
JTOOLS::JMultiMapGetTransformer::transformer
const transformer_type & transformer
Definition: JMultiMapTransformer.hh:330
JTOOLS::JMultiMapTransformer
Interface for weight application and coordinate transformation of function.
Definition: JMultiMapTransformer.hh:35
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:131
JTOOLS::JMultiMapPutTransformer
Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
Definition: JMultiMapTransformer.hh:240
JTOOLS::JMultiMapTransformer::array_type
JArray< N, argument_type > array_type
Definition: JMultiMapTransformer.hh:45
JTOOLS::JMultiMapPutTransformer::operator()
virtual JElement_t operator()(const JElement_t &element) const
Transform element.
Definition: JMultiMapTransformer.hh:273
JTOOLS::JTransformable::transform
virtual void transform(const transformer_type &transformer)=0
Application of transformation.
JTOOLS::JMultiMapGetTransformer::W
const double W
Definition: JMultiMapTransformer.hh:332
JTOOLS::JMultiMapTransformer::getXn
virtual argument_type getXn(const_array_type &buffer, const argument_type xn) const =0
Evaluate xn value as a function of {x0, ..., xn-1}.
JTOOLS::JMultiMapTransformer::JMultiMapDefaultTransformer::JMultiMapDefaultTransformer
JMultiMapDefaultTransformer()
Default constructor.
Definition: JMultiMapTransformer.hh:152
JTOOLS::JMultiMapPutTransformer::W
const double W
Definition: JMultiMapTransformer.hh:281
JTOOLS::JMultiMapTransformer::getWeight
virtual double getWeight(const_array_type &buffer) const =0
Weight function.
JTOOLS::JMultiMapTransformer::JMultiMapDefaultTransformer::putXn
virtual argument_type putXn(const_array_type &buffer, const argument_type xn) const
Evaluate xn value as a function of {x0, ..., xn-1}.
Definition: JMultiMapTransformer.hh:174
JTOOLS::JMultiMapTransformer::JMultiMapDefaultTransformer::clone
virtual clone_type clone() const
Clone object.
Definition: JMultiMapTransformer.hh:161
JTOOLS::JMultiMapTransformer::putXn
virtual argument_type putXn(const_array_type &buffer, const argument_type xn) const =0
Evaluate xn value as a function of {x0, ..., xn-1}.
JTOOLS::JMultiMapGetTransformer::operator()
virtual JElement_t operator()(const JElement_t &element) const
Transform element.
Definition: JMultiMapTransformer.hh:324
JTOOLS::JMultiMapPutTransformer::transformer_type
JMultiMapTransformer< N, abscissa_type > transformer_type
Definition: JMultiMapTransformer.hh:248
JTOOLS::JMultiMapGetTransformer::abscissa_type
JElement_t::abscissa_type abscissa_type
Definition: JMultiMapTransformer.hh:296
JTOOLS::JMultiMapTransformer::argument_type
JArgument_t argument_type
Definition: JMultiMapTransformer.hh:44
JTOOLS::JMultiMapTransformer::JMultiMapDefaultTransformer::getXn
virtual argument_type getXn(const_array_type &buffer, const argument_type xn) const
Evaluate xn value as a function of {x0, ..., xn-1}.
Definition: JMultiMapTransformer.hh:187
JTransformer.hh
JTOOLS::JMultiMapGetTransformer::buffer
const_array_type buffer
Definition: JMultiMapTransformer.hh:331
JTOOLS::JTransformable
Abstract interface for transformable multidimensional map.
Definition: JMultiMapTransformer.hh:342
JClonable.hh
JTOOLS::JMultiMapTransformer::JMultiMapDefaultTransformer
Default implementation of weight application and coordinate transformation of function.
Definition: JMultiMapTransformer.hh:144
JTOOLS::JTransformable::transformer_type
JMultiMapTransformer< N, argument_type > transformer_type
Definition: JMultiMapTransformer.hh:345
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
JTOOLS::JMultiMapPutTransformer::JMultiMapPutTransformer
JMultiMapPutTransformer(const transformer_type &__transformer, const_array_type &__buffer)
Constructor.
Definition: JMultiMapTransformer.hh:259
JTOOLS::JTransformable::argument_type
JArgument_t argument_type
Definition: JMultiMapTransformer.hh:344
JLANG::JClonable
Template class for object cloning.
Definition: JClonable.hh:20
JTOOLS::JMultiMapTransformer::const_array_type
const typedef JArray< N, const argument_type > const_array_type
Definition: JMultiMapTransformer.hh:46
JTOOLS::JCollectionElementTransformer
Interface for transformation of collection of elements.
Definition: JTransformer.hh:18
JArray.hh