CMS 3D CMS Logo

StorableInterpolationFunctor.h
Go to the documentation of this file.
1 #ifndef NPSTAT_STORABLEINTERPOLATIONFUNCTOR_HH_
2 #define NPSTAT_STORABLEINTERPOLATIONFUNCTOR_HH_
3 
18 
19 namespace npstat {
24  template <class Numeric, class Axis = UniformAxis, class Converter = Same<Numeric> >
26  template <typename Num2, typename Axis2, typename Conv2>
28 
29  public:
31 
33 
34  template <class Num2>
37 
38  template <class Num2>
42 
44  template <class Num2, class Conv2>
47 
49 
54  inline StorableInterpolationFunctor(const std::vector<Axis>& axes,
55  const std::vector<std::pair<bool, bool> >& interpolationType,
56  const char* functionLabel = nullptr)
57  : StorableMultivariateFunctor(), table_(axes, interpolationType, functionLabel) {}
58 
59  inline StorableInterpolationFunctor(const Axis& xAxis, bool leftX, bool rightX, const char* functionLabel = nullptr)
60  : StorableMultivariateFunctor(), table_(xAxis, leftX, rightX, functionLabel) {}
61 
62  inline StorableInterpolationFunctor(const Axis& xAxis,
63  bool leftX,
64  bool rightX,
65  const Axis& yAxis,
66  bool leftY,
67  bool rightY,
68  const char* functionLabel = nullptr)
69  : StorableMultivariateFunctor(), table_(xAxis, leftX, rightX, yAxis, leftY, rightY, functionLabel) {}
70 
71  inline StorableInterpolationFunctor(const Axis& xAxis,
72  bool leftX,
73  bool rightX,
74  const Axis& yAxis,
75  bool leftY,
76  bool rightY,
77  const Axis& zAxis,
78  bool leftZ,
79  bool rightZ,
80  const char* functionLabel = nullptr)
82  table_(xAxis, leftX, rightX, yAxis, leftY, rightY, zAxis, leftZ, rightZ, functionLabel) {}
83 
84  inline StorableInterpolationFunctor(const Axis& xAxis,
85  bool leftX,
86  bool rightX,
87  const Axis& yAxis,
88  bool leftY,
89  bool rightY,
90  const Axis& zAxis,
91  bool leftZ,
92  bool rightZ,
93  const Axis& tAxis,
94  bool leftT,
95  bool rightT,
96  const char* functionLabel = nullptr)
98  table_(
99  xAxis, leftX, rightX, yAxis, leftY, rightY, zAxis, leftZ, rightZ, tAxis, leftT, rightT, functionLabel) {}
100 
102  bool leftX,
103  bool rightX,
104  const Axis& yAxis,
105  bool leftY,
106  bool rightY,
107  const Axis& zAxis,
108  bool leftZ,
109  bool rightZ,
110  const Axis& tAxis,
111  bool leftT,
112  bool rightT,
113  const Axis& vAxis,
114  bool leftV,
115  bool rightV,
116  const char* functionLabel = nullptr)
118  table_(xAxis,
119  leftX,
120  rightX,
121  yAxis,
122  leftY,
123  rightY,
124  zAxis,
125  leftZ,
126  rightZ,
127  tAxis,
128  leftT,
129  rightT,
130  vAxis,
131  leftV,
132  rightV,
133  functionLabel) {}
135 
137  StorableInterpolationFunctor() = delete;
138 
140 
141  unsigned minDim() const override { return table_.dim(); };
142 
143  double operator()(const double* point, unsigned dim) const override { return conv_(table_(point, dim)); }
144 
146 
147  inline Table& interpolator() { return table_; }
148  inline const Table& interpolator() const { return table_; }
150 
152 
153  inline ArrayND<Numeric>& table() { return table_.table(); }
154  inline const ArrayND<Numeric>& table() const { return table_.table(); }
156 
158  inline void setConverter(const Converter& conv) { conv_ = conv; }
159 
161  // Method related to "geners" I/O
162  gs::ClassId classId() const override { return gs::ClassId(*this); }
163  bool write(std::ostream& of) const override;
165 
166  // I/O methods needed for reading
167  static inline const char* classname();
168  static inline unsigned version() { return 1; }
169  static StorableInterpolationFunctor* read(const gs::ClassId& id, std::istream& in);
170 
171  protected:
172  bool isEqual(const StorableMultivariateFunctor& other) const override {
173  // Note the use of static_cast rather than dynamic_cast below.
174  // static_cast works faster and it is guaranteed to succeed here.
176  return table_ == r.table_ && this->description() == other.description();
177  }
178 
179  private:
181  Converter conv_;
182  };
183 } // namespace npstat
184 
185 #include "Alignment/Geners/interface/binaryIO.hh"
186 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
187 #include "Alignment/Geners/interface/IOException.hh"
188 
189 namespace npstat {
190  template <typename Numeric, class Axis, class Converter>
192  static const std::string myClass(gs::template_class_name<Numeric, Axis>("npstat::StorableInterpolationFunctor"));
193  return myClass.c_str();
194  }
195 
196  template <typename Numeric, class Axis, class Converter>
198  gs::write_pod(of, this->description());
199  return table_.classId().write(of) && table_.write(of);
200  }
201 
202  template <typename Numeric, class Axis, class Converter>
204  const gs::ClassId& id, std::istream& in) {
205  static const gs::ClassId current(gs::ClassId::makeId<StorableInterpolationFunctor<Numeric, Axis> >());
206  current.ensureSameId(id);
207 
208  std::string descr;
209  gs::read_pod(in, &descr);
210  gs::ClassId tabid(in, 1);
211  if (in.fail())
212  throw gs::IOReadFailure(
213  "In npstat::StorableInterpolationFunctor::read: "
214  "input stream failure");
215  CPP11_auto_ptr<Table> tab(Table::read(tabid, in));
216  return new StorableInterpolationFunctor(*tab, descr);
217  }
218 } // namespace npstat
219 
220 #endif // NPSTAT_STORABLEINTERPOLATIONFUNCTOR_HH_
const ArrayND< Numeric > & table() const
bool write(std::ostream &of) const override
StorableInterpolationFunctor(const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const Axis &tAxis, bool leftT, bool rightT, const Axis &vAxis, bool leftV, bool rightV, const char *functionLabel=nullptr)
double operator()(const double *point, unsigned dim) const override
StorableInterpolationFunctor(const LinInterpolatedTableND< Num2, Axis > &table)
Interface definition for storable multivariate functors.
static StorableInterpolationFunctor * read(const gs::ClassId &id, std::istream &in)
StorableInterpolationFunctor(const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const Axis &tAxis, bool leftT, bool rightT, const char *functionLabel=nullptr)
StorableInterpolationFunctor(const Axis &xAxis, bool leftX, bool rightX, const char *functionLabel=nullptr)
Multilinear interpolation/extrapolation on rectangular grids.
const ArrayND< Numeric > & table() const
StorableInterpolationFunctor(const StorableInterpolationFunctor< Num2, Axis, Conv2 > &tab)
Interface definitions and concrete simple functors for a variety of functor-based calculations...
StorableInterpolationFunctor(const std::vector< Axis > &axes, const std::vector< std::pair< bool, bool > > &interpolationType, const char *functionLabel=nullptr)
StorableInterpolationFunctor(const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const char *functionLabel=nullptr)
StorableInterpolationFunctor(const LinInterpolatedTableND< Num2, Axis > &table, const std::string &descr)
StorableInterpolationFunctor(const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const char *functionLabel=nullptr)
bool isEqual(const StorableMultivariateFunctor &other) const override
LinInterpolatedTableND< Numeric, Axis > Table
EPOS::IO_EPOS conv
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5