CMS 3D CMS Logo

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 
npstat::ArrayND::interpolate3
Numeric interpolate3(const double *x, unsigned xDim) const
Definition: ArrayND.h:4309
mps_fire.i
i
Definition: mps_fire.py:355
npstat::Private::ArrayMapper
Definition: rescanArray.h:44
npstat::LinearMapper1d
Definition: LinearMapper1d.h:18
to
cms::cuda::assert
assert(be >=bs)
npstat::Private::ArrayMapper::ArrayMapper
ArrayMapper(const ArrayND< Num1, Len1, Dim1 > &from, const ArrayND< Num2, Len2, Dim2 > &to, const unsigned interpolationDegree)
Definition: rescanArray.h:47
npstat::ArrayND::rank
unsigned rank() const
Definition: ArrayND.h:242
LinearMapper1d.h
Linear transformation functor.
npstat
Definition: AbsArrayProjector.h:14
npstat::Private::ArrayMapper::mappers_
std::vector< LinearMapper1d > mappers_
Definition: rescanArray.h:93
npstat::Private::ArrayMapper::ideg_
unsigned ideg_
Definition: rescanArray.h:97
npstat::ArrayND::closest
Numeric & closest(const double *x, unsigned xDim)
Definition: ArrayND.h:3173
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
ArrayND.h
Arbitrary-dimensional array template.
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
npstat::Private::ArrayMapper::dim_
unsigned dim_
Definition: rescanArray.h:96
npstat::ArrayND::span
unsigned span(unsigned dim) const
Definition: ArrayND.h:5088
npstat::ArrayND::interpolate1
Numeric interpolate1(const double *x, unsigned xDim) const
Definition: ArrayND.h:4211
npstat::rescanArray
void rescanArray(const ArrayND< Num1, Len1, Dim1 > &from, ArrayND< Num2, Len2, Dim2 > *to, unsigned interpolationDegree=0)
Definition: rescanArray.h:103
npstat::ArrayND< Num1, Len1, Dim1 >
npstat::Private::ArrayMapper::mapped_
std::vector< double > mapped_
Definition: rescanArray.h:94
npstat::Private::ArrayMapper::from_
const ArrayND< Num1, Len1, Dim1 > & from_
Definition: rescanArray.h:95
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
NpstatException.h
Exceptions for the npstat namespace.
npstat::Private::ArrayMapper::operator()
Num1 operator()(const unsigned *index, unsigned indexLen) const
Definition: rescanArray.h:66