CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
rescanArray.h
Go to the documentation of this file.
1 #ifndef NPSTAT_RESCANARRAY_HH_
2 #define NPSTAT_RESCANARRAY_HH_
3 
16 
17 namespace npstat {
28  template<typename Num1, unsigned Len1, unsigned Dim1,
29  typename Num2, unsigned Len2, unsigned Dim2>
30  void rescanArray(const ArrayND<Num1,Len1,Dim1>& from,
31  ArrayND<Num2,Len2,Dim2>* to,
32  unsigned interpolationDegree=0);
33 }
34 
35 #include <cassert>
37 
39 
40 namespace npstat {
41  namespace Private {
42  template<typename Num1, unsigned Len1, unsigned Dim1,
43  typename Num2, unsigned Len2, unsigned Dim2>
45  {
46  public:
49  const unsigned interpolationDegree)
50  : mapped_(from.rank()),
51  from_(from),
52  dim_(from.rank()),
53  ideg_(interpolationDegree)
54  {
55  assert(dim_ == to.rank());
56  if (dim_)
57  {
58  mappers_.reserve(dim_);
59  for (unsigned i=0; i<dim_; ++i)
60  mappers_.push_back(LinearMapper1d(-0.5, -0.5,
61  to.span(i) - 0.5,
62  from.span(i) - 0.5));
63  }
64  }
65 
66  Num1 operator()(const unsigned* index, unsigned indexLen) const
67  {
68  if (dim_)
69  {
70  const LinearMapper1d* m = &mappers_[0];
71  double* coords = &mapped_[0];
72  for (unsigned i=0; i<dim_; ++i)
73  coords[i] = m[i](index[i]);
74  switch (ideg_)
75  {
76  case 0U:
77  return from_.closest(coords, dim_);
78 
79  case 1U:
80  return from_.interpolate1(coords, dim_);
81 
82  case 3U:
83  return from_.interpolate3(coords, dim_);
84 
85  default:
86  assert(0);
87  }
88  }
89  return from_();
90  }
91 
92  private:
93  std::vector<LinearMapper1d> mappers_;
94  mutable std::vector<double> mapped_;
96  unsigned dim_;
97  unsigned ideg_;
98  };
99  }
100 
101  template<typename Num1, unsigned Len1, unsigned Dim1,
102  typename Num2, unsigned Len2, unsigned Dim2>
105  const unsigned interpolationDegree)
106  {
107  assert(to);
108  if (from.rank() != to->rank()) throw npstat::NpstatInvalidArgument(
109  "In npstat::rescanArray: incompatible dimensionalities "
110  "of input and output arrays");
111  if (!(interpolationDegree == 0U ||
112  interpolationDegree == 1U ||
113  interpolationDegree == 3U)) throw npstat::NpstatInvalidArgument(
114  "In npstat::rescanArray: unsupported interpolation degree");
116  from, *to, interpolationDegree));
117  }
118 }
119 
120 
121 #endif // NPSTAT_RESCANARRAY_HH_
122 
int i
Definition: DBlmapReader.cc:9
unsigned rank() const
Definition: ArrayND.h:240
Linear transformation functor.
const ArrayND< Num1, Len1, Dim1 > & from_
Definition: rescanArray.h:95
Numeric & closest(const double *x, unsigned xDim)
Definition: ArrayND.h:3205
void rescanArray(const ArrayND< Num1, Len1, Dim1 > &from, ArrayND< Num2, Len2, Dim2 > *to, unsigned interpolationDegree=0)
Definition: rescanArray.h:103
unsigned span(unsigned dim) const
Definition: ArrayND.h:5440
Numeric interpolate1(const double *x, unsigned xDim) const
Definition: ArrayND.h:4428
ArrayND & functorFill(Functor f)
Exceptions for the npstat namespace.
ArrayMapper(const ArrayND< Num1, Len1, Dim1 > &from, const ArrayND< Num2, Len2, Dim2 > &to, const unsigned interpolationDegree)
Definition: rescanArray.h:47
std::vector< LinearMapper1d > mappers_
Definition: rescanArray.h:93
std::vector< double > mapped_
Definition: rescanArray.h:94
Arbitrary-dimensional array template.
Num1 operator()(const unsigned *index, unsigned indexLen) const
Definition: rescanArray.h:66
Numeric interpolate3(const double *x, unsigned xDim) const
Definition: ArrayND.h:4544