CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
25  <
26  class Numeric,
27  class Axis = UniformAxis,
28  class Converter = Same<Numeric>
29  >
31  {
32  template <typename Num2, typename Axis2, typename Conv2>
34 
35  public:
37 
39 
40  template <class Num2>
43  : StorableMultivariateFunctor(), table_(table) {}
44 
45  template <class Num2>
48  const std::string& descr)
49  : StorableMultivariateFunctor(descr), table_(table) {}
51 
53  template <class Num2, class Conv2>
57  table_(tab.table_) {}
58 
60 
66  const std::vector<Axis>& axes,
67  const std::vector<std::pair<bool,bool> >& interpolationType,
68  const char* functionLabel=0)
70  table_(axes, interpolationType, functionLabel) {}
71 
73  const Axis& xAxis, bool leftX, bool rightX,
74  const char* functionLabel=0)
76  table_(xAxis, leftX, rightX, functionLabel) {}
77 
79  const Axis& xAxis, bool leftX, bool rightX,
80  const Axis& yAxis, bool leftY, bool rightY,
81  const char* functionLabel=0)
83  table_(xAxis, leftX, rightX,
84  yAxis, leftY, rightY, functionLabel) {}
85 
87  const Axis& xAxis, bool leftX, bool rightX,
88  const Axis& yAxis, bool leftY, bool rightY,
89  const Axis& zAxis, bool leftZ, bool rightZ,
90  const char* functionLabel=0)
92  table_(xAxis, leftX, rightX,
93  yAxis, leftY, rightY,
94  zAxis, leftZ, rightZ, functionLabel) {}
95 
97  const Axis& xAxis, bool leftX, bool rightX,
98  const Axis& yAxis, bool leftY, bool rightY,
99  const Axis& zAxis, bool leftZ, bool rightZ,
100  const Axis& tAxis, bool leftT, bool rightT,
101  const char* functionLabel=0)
103  table_(xAxis, leftX, rightX,
104  yAxis, leftY, rightY,
105  zAxis, leftZ, rightZ,
106  tAxis, leftT, rightT, functionLabel) {}
107 
109  const Axis& xAxis, bool leftX, bool rightX,
110  const Axis& yAxis, bool leftY, bool rightY,
111  const Axis& zAxis, bool leftZ, bool rightZ,
112  const Axis& tAxis, bool leftT, bool rightT,
113  const Axis& vAxis, bool leftV, bool rightV,
114  const char* functionLabel=0)
116  table_(xAxis, leftX, rightX,
117  yAxis, leftY, rightY,
118  zAxis, leftZ, rightZ,
119  tAxis, leftT, rightT,
120  vAxis, leftV, rightV, functionLabel) {}
122 
124 
125  virtual unsigned minDim() const {return table_.dim();};
126 
127  virtual double operator()(const double* point, unsigned dim) const
128  {return conv_(table_(point, dim));}
129 
131 
132  inline Table& interpolator() {return table_;}
133  inline const Table& interpolator() const {return table_;}
135 
137 
138  inline ArrayND<Numeric>& table() {return table_.table();}
139  inline const ArrayND<Numeric>& table() const {return table_.table();}
141 
143  inline void setConverter(const Converter& conv) {conv_ = conv;}
144 
146  // Method related to "geners" I/O
147  virtual gs::ClassId classId() const {return gs::ClassId(*this);}
148  virtual bool write(std::ostream& of) const;
150 
151  // I/O methods needed for reading
152  static inline const char* classname();
153  static inline unsigned version() {return 1;}
155  const gs::ClassId& id, std::istream& in);
156 
157  protected:
158  virtual bool isEqual(const StorableMultivariateFunctor& other) const
159  {
160  // Note the use of static_cast rather than dynamic_cast below.
161  // static_cast works faster and it is guaranteed to succeed here.
163  static_cast<const StorableInterpolationFunctor&>(other);
164  return table_ == r.table_ &&
165  this->description() == other.description();
166  }
167 
168  private:
170 
172  Converter conv_;
173  };
174 }
175 
176 #include "Alignment/Geners/interface/binaryIO.hh"
177 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
178 #include "Alignment/Geners/interface/IOException.hh"
179 
180 namespace npstat {
181  template <typename Numeric, class Axis, class Converter>
183  {
184  static const std::string myClass(gs::template_class_name<Numeric,Axis>(
185  "npstat::StorableInterpolationFunctor"));
186  return myClass.c_str();
187  }
188 
189  template<typename Numeric, class Axis, class Converter>
191  std::ostream& of) const
192  {
193  gs::write_pod(of, this->description());
194  return table_.classId().write(of) && table_.write(of);
195  }
196 
197  template<typename Numeric, class Axis, class Converter>
200  const gs::ClassId& id, std::istream& in)
201  {
202  static const gs::ClassId current(
203  gs::ClassId::makeId<StorableInterpolationFunctor<Numeric,Axis> >());
204  current.ensureSameId(id);
205 
206  std::string descr;
207  gs::read_pod(in, &descr);
208  gs::ClassId tabid(in, 1);
209  if (in.fail()) throw gs::IOReadFailure(
210  "In npstat::StorableInterpolationFunctor::read: "
211  "input stream failure");
212  CPP11_auto_ptr<Table> tab(Table::read(tabid, in));
213  return new StorableInterpolationFunctor(*tab, descr);
214  }
215 }
216 
217 
218 #endif // NPSTAT_STORABLEINTERPOLATIONFUNCTOR_HH_
219 
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=0)
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=0)
static HepMC::IO_HEPEVT conv
StorableInterpolationFunctor(const LinInterpolatedTableND< Num2, Axis > &table)
Interface definition for storable multivariate functors.
LinInterpolatedTableND< Numeric, Axis > Table
static StorableInterpolationFunctor * read(const gs::ClassId &id, std::istream &in)
const ArrayND< Numeric > & table() const
Multilinear interpolation/extrapolation on rectangular grids.
StorableInterpolationFunctor(const std::vector< Axis > &axes, const std::vector< std::pair< bool, bool > > &interpolationType, const char *functionLabel=0)
const ArrayND< Numeric > & table() const
StorableInterpolationFunctor(const StorableInterpolationFunctor< Num2, Axis, Conv2 > &tab)
virtual double operator()(const double *point, unsigned dim) const
Interface definitions and concrete simple functors for a variety of functor-based calculations...
tuple description
Definition: idDealer.py:66
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=0)
Table table_
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=0)
tuple zAxis
Definition: MetAnalyzer.py:56
StorableInterpolationFunctor(const Axis &xAxis, bool leftX, bool rightX, const char *functionLabel=0)
virtual bool write(std::ostream &of) const
virtual bool isEqual(const StorableMultivariateFunctor &other) const
*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