Jpp  18.4.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMultiMapTransformer.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JMULTIMAPTRANSFORMER__
2 #define __JTOOLS__JMULTIMAPTRANSFORMER__
3 
4 #include "JLang/JClonable.hh"
5 #include "JIO/JSerialisable.hh"
6 #include "JTools/JArray.hh"
7 #include "JTools/JTransformer.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JTOOLS {}
15 namespace JPP { using namespace JTOOLS; }
16 
17 namespace JTOOLS {
18 
19  using JLANG::JClonable;
20  using JIO::JSerialisable;
21  using JIO::JReader;
22  using JIO::JWriter;
23 
24 
25  /**
26  * Interface for weight application and coordinate transformation of function.
27  *
28  * The template parameters refer to the dimension of the map and the data type of the argument, respectively.
29  *
30  * This class extends the JClonable and JSerialisable interfaces.
31  */
32  template<unsigned int N, class JArgument_t>
34  public JClonable< JMultiMapTransformer<N, JArgument_t> >,
35  public JSerialisable
36  {
37  public:
38 
40 
42  typedef JArgument_t argument_type;
45 
46 
47  /**
48  * Evaluate xn value as a function of {x0, ..., xn-1}
49  *
50  * \param buffer x0 - xn-1 values
51  * \param xn xn value
52  * \return xn value
53  */
54  virtual argument_type putXn(const_array_type& buffer, const argument_type xn) const = 0;
55 
56 
57  /**
58  * Evaluate xn value as a function of {x0, ..., xn-1}
59  *
60  * \param buffer x0 - xn-1 values
61  * \param xn xn value
62  * \return xn value
63  */
64  virtual argument_type getXn(const_array_type& buffer, const argument_type xn) const = 0;
65 
66 
67  /**
68  * Weight function.
69  *
70  * \param buffer x0 - xn-1 values
71  * \return weight
72  */
73  virtual double getWeight(const_array_type& buffer) const = 0;
74 
75 
76  /**
77  * Weight function.
78  *
79  * \param x first abscissa values
80  * \param args comma seperated list of remaining abscissa values
81  * \return weight
82  */
83  template<class ...Args>
84  double getWeight(const argument_type x, const Args& ...args) const
85  {
86  return getWeight(array_type(x, args...));
87  }
88 
89 
90  /**
91  * Default implementation of weight application and coordinate transformation of function.
92  */
93  class JMultiMapDefaultTransformer;
94 
95 
96  /**
97  * Get default transformer.
98  *
99  * \return default transformer
100  */
102  {
103  static const JMultiMapDefaultTransformer transformer;
104 
105  return transformer;
106  }
107 
108 
109  /**
110  * Get clone of default transformer.
111  *
112  * \return pointer to newly created transformer
113  */
115  {
116  return new JMultiMapDefaultTransformer();
117  }
118  };
119 
120 
121  /**
122  * Default implementation of weight application and coordinate transformation of function.
123  *
124  * The coordiniate transformation has no effect and the weight is equal to one.
125  *
126  * This class implements the JMultiMapTransformer, JClonable and JSerialisable interfaces.
127  */
128  template<unsigned int N, class JArgument_t>
130  public JMultiMapTransformer<N, JArgument_t>
131  {
132  public:
133 
134  /**
135  * Default constructor.
136  */
138  {}
139 
140 
141  /**
142  * Clone object.
143  *
144  * \return pointer to newly created transformer
145  */
146  virtual clone_type clone() const override
147  {
148  return new JMultiMapDefaultTransformer(*this);
149  }
150 
151 
152  /**
153  * Evaluate xn value as a function of {x0, ..., xn-1}
154  *
155  * \param buffer x0 - xn-1 values
156  * \param xn xn value
157  * \return xn value
158  */
159  virtual argument_type putXn(const_array_type& buffer, const argument_type xn) const override
160  {
161  return xn;
162  }
163 
164 
165  /**
166  * Evaluate xn value as a function of {x0, ..., xn-1}
167  *
168  * \param buffer x0 - xn-1 values
169  * \param xn xn value
170  * \return xn value
171  */
172  virtual argument_type getXn(const_array_type& buffer, const argument_type xn) const override
173  {
174  return xn;
175  }
176 
177 
178  /**
179  * Weight function.
180  *
181  * \param buffer x0 - xn-1 values
182  * \return weight
183  */
184  virtual double getWeight(const_array_type& buffer) const override
185  {
186  return 1.0;
187  }
188 
189 
190  /**
191  * Read from input.
192  *
193  * This method reads nothing.
194  *
195  * \param in reader
196  * \return reader
197  */
198  virtual JReader& read(JReader& in) override
199  {
200  return in;
201  }
202 
203 
204  /**
205  * Write to output.
206  *
207  * This method writes nothing.
208  *
209  * \param out writer
210  * \return writer
211  */
212  virtual JWriter& write(JWriter& out) const override
213  {
214  return out;
215  }
216  };
217 
218 
219  /**
220  * Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
221  *
222  * This class implements the JCollectionElementTransformer interface.
223  */
224  template<unsigned int N, class JElement_t>
226  public JCollectionElementTransformer<JElement_t>
227  {
228  public:
229 
230  typedef typename JElement_t::abscissa_type abscissa_type;
231  typedef typename JElement_t::ordinate_type ordinate_type;
232 
234 
236 
237 
238  /**
239  * Constructor.
240  *
241  * \param __transformer multidimensional map transformer
242  * \param __buffer x0 - xn-1 values
243  */
245  const_array_type& __buffer) :
246  transformer(__transformer),
247  buffer (__buffer),
249  {}
250 
251 
252  /**
253  * Transform element.
254  *
255  * \param element input element
256  * \return output element
257  */
258  virtual JElement_t operator()(const JElement_t& element) const override
259  {
260  return JElement_t(transformer.putXn(buffer, element.getX()), element.getY() / W);
261  }
262 
263  private:
266  const double W;
267  };
268 
269 
270  /**
271  * Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer.
272  *
273  * This class implements the JCollectionElementTransformer interface.
274  */
275  template<unsigned int N, class JElement_t>
277  public JCollectionElementTransformer<JElement_t>
278  {
279  public:
280 
281  typedef typename JElement_t::abscissa_type abscissa_type;
282  typedef typename JElement_t::ordinate_type ordinate_type;
283 
285 
287 
288 
289  /**
290  * Constructor.
291  *
292  * \param __transformer multidimensional map transformer
293  * \param __buffer x0 - xn-1 values
294  */
296  const_array_type& __buffer) :
297  transformer(__transformer),
298  buffer (__buffer),
300  {}
301 
302 
303  /**
304  * Transform element.
305  *
306  * \param element input element
307  * \return output element
308  */
309  virtual JElement_t operator()(const JElement_t& element) const override
310  {
311  return JElement_t(transformer.getXn(buffer, element.getX()), element.getY() * W);
312  }
313 
314  private:
317  const double W;
318  };
319 
320 
321  /**
322  * Abstract interface for transformable multidimensional map.
323  *
324  * The template parameters refer to the dimension of the map and the data type of the argument, respectively.
325  */
326  template<unsigned int N, class JArgument_t>
328  {
329  typedef JArgument_t argument_type;
331 
332  /**
333  * Application of transformation.
334  *
335  * \param transformer function transformer
336  */
337  virtual void transform(const transformer_type& transformer) = 0;
338  };
339 }
340 
341 #endif
transformer_type::const_array_type const_array_type
Interface for binary output.
double getWeight(T __begin, T __end)
Get total weight of data points.
Definition: JKatoomba_t.hh:61
virtual argument_type putXn(const_array_type &buffer, const argument_type xn) const override
Evaluate xn value as a function of {x0, ..., xn-1}.
JMultiMapTransformer< N, JArgument_t > multimaptransformer_type
JMultiMapTransformer< N, abscissa_type > transformer_type
double getWeight(const argument_type x, const Args &...args) const
Weight function.
virtual JWriter & write(JWriter &out) const override
Write to output.
virtual JElement_t operator()(const JElement_t &element) const override
Transform element.
JClonable< multimaptransformer_type >::clone_type clone_type
Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer. ...
virtual clone_type clone() const override
Clone object.
virtual void transform(const transformer_type &transformer)=0
Application of transformation.
transformer_type::const_array_type const_array_type
Forward declaration of binary output.
const transformer_type & transformer
JArray< N, argument_type > array_type
virtual double getWeight(const_array_type &buffer) const =0
Weight function.
const transformer_type & transformer
JClonable< JClonable_t >::clone_type clone_type
Definition: JClonable.hh:61
Abstract interface for transformable multidimensional map.
JElement_t::abscissa_type abscissa_type
JMultiMapTransformer< N, argument_type > transformer_type
virtual JElement_t operator()(const JElement_t &element) const override
Transform element.
Template class for object cloning.
Definition: JClonable.hh:20
const JArray< N, const argument_type > const_array_type
static JMultiMapTransformer * getClone()
Get clone of default transformer.
Interface for binary input.
virtual double getWeight(const_array_type &buffer) const override
Weight function.
Default implementation of weight application and coordinate transformation of function.
One dimensional array of template objects with fixed length.
Definition: JArray.hh:40
Interface for transformation of collection of elements.
Definition: JTransformer.hh:18
JMultiMapPutTransformer(const transformer_type &__transformer, const_array_type &__buffer)
Constructor.
JMultiMapGetTransformer(const transformer_type &__transformer, const_array_type &__buffer)
Constructor.
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
JElement_t::ordinate_type ordinate_type
Interface for weight application and coordinate transformation of function.
virtual argument_type getXn(const_array_type &buffer, const argument_type xn) const =0
Evaluate xn value as a function of {x0, ..., xn-1}.
Auxiliary class to convert JMultiMapTransformer to JCollectionElementTransformer. ...
JElement_t::ordinate_type ordinate_type
virtual argument_type getXn(const_array_type &buffer, const argument_type xn) const override
Evaluate xn value as a function of {x0, ..., xn-1}.
virtual argument_type putXn(const_array_type &buffer, const argument_type xn) const =0
Evaluate xn value as a function of {x0, ..., xn-1}.
JMultiMapTransformer< N, abscissa_type > transformer_type
JElement_t::abscissa_type abscissa_type
static const JMultiMapTransformer & getDefaultTransformer()
Get default transformer.
virtual JReader & read(JReader &in) override
Read from input.