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 
138  unsigned minDim() const override { return table_.dim(); };
139 
140  double operator()(const double* point, unsigned dim) const override { return conv_(table_(point, dim)); }
141 
143 
144  inline Table& interpolator() { return table_; }
145  inline const Table& interpolator() const { return table_; }
147 
149 
150  inline ArrayND<Numeric>& table() { return table_.table(); }
151  inline const ArrayND<Numeric>& table() const { return table_.table(); }
153 
155  inline void setConverter(const Converter& conv) { conv_ = conv; }
156 
158  // Method related to "geners" I/O
159  gs::ClassId classId() const override { return gs::ClassId(*this); }
160  bool write(std::ostream& of) const override;
162 
163  // I/O methods needed for reading
164  static inline const char* classname();
165  static inline unsigned version() { return 1; }
166  static StorableInterpolationFunctor* read(const gs::ClassId& id, std::istream& in);
167 
168  protected:
169  bool isEqual(const StorableMultivariateFunctor& other) const override {
170  // Note the use of static_cast rather than dynamic_cast below.
171  // static_cast works faster and it is guaranteed to succeed here.
172  const StorableInterpolationFunctor& r = static_cast<const StorableInterpolationFunctor&>(other);
173  return table_ == r.table_ && this->description() == other.description();
174  }
175 
176  private:
177  StorableInterpolationFunctor() = delete;
178 
180  Converter conv_;
181  };
182 } // namespace npstat
183 
184 #include "Alignment/Geners/interface/binaryIO.hh"
185 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
186 #include "Alignment/Geners/interface/IOException.hh"
187 
188 namespace npstat {
189  template <typename Numeric, class Axis, class Converter>
191  static const std::string myClass(gs::template_class_name<Numeric, Axis>("npstat::StorableInterpolationFunctor"));
192  return myClass.c_str();
193  }
194 
195  template <typename Numeric, class Axis, class Converter>
197  gs::write_pod(of, this->description());
198  return table_.classId().write(of) && table_.write(of);
199  }
200 
201  template <typename Numeric, class Axis, class Converter>
203  const gs::ClassId& id, std::istream& in) {
204  static const gs::ClassId current(gs::ClassId::makeId<StorableInterpolationFunctor<Numeric, Axis> >());
205  current.ensureSameId(id);
206 
207  std::string descr;
208  gs::read_pod(in, &descr);
209  gs::ClassId tabid(in, 1);
210  if (in.fail())
211  throw gs::IOReadFailure(
212  "In npstat::StorableInterpolationFunctor::read: "
213  "input stream failure");
214  CPP11_auto_ptr<Table> tab(Table::read(tabid, in));
215  return new StorableInterpolationFunctor(*tab, descr);
216  }
217 } // namespace npstat
218 
219 #endif // NPSTAT_STORABLEINTERPOLATIONFUNCTOR_HH_
npstat::StorableInterpolationFunctor::Table
LinInterpolatedTableND< Numeric, Axis > Table
Definition: StorableInterpolationFunctor.h:30
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
StorableInterpolationFunctor(const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const char *functionLabel=nullptr)
Definition: StorableInterpolationFunctor.h:62
npstat::StorableInterpolationFunctor::version
static unsigned version()
Definition: StorableInterpolationFunctor.h:165
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
StorableInterpolationFunctor(const LinInterpolatedTableND< Num2, Axis > &table, const std::string &descr)
Definition: StorableInterpolationFunctor.h:39
npstat::StorableInterpolationFunctor::table_
Table table_
Definition: StorableInterpolationFunctor.h:179
npstat::StorableInterpolationFunctor::table
ArrayND< Numeric > & table()
Definition: StorableInterpolationFunctor.h:150
conv
static HepMC::IO_HEPEVT conv
Definition: BeamHaloProducer.cc:48
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
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)
Definition: StorableInterpolationFunctor.h:71
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
npstat::StorableMultivariateFunctor::description
const std::string & description() const
Definition: StorableMultivariateFunctor.h:34
npstat::StorableInterpolationFunctor::table
const ArrayND< Numeric > & table() const
Definition: StorableInterpolationFunctor.h:151
npstat::StorableInterpolationFunctor::interpolator
Table & interpolator()
Definition: StorableInterpolationFunctor.h:144
npstat::LinInterpolatedTableND::table
const ArrayND< Numeric > & table() const
Definition: LinInterpolatedTableND.h:150
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
StorableInterpolationFunctor()=delete
npstat
Definition: AbsArrayProjector.h:14
LinInterpolatedTableND.h
Multilinear interpolation/extrapolation on rectangular grids.
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
StorableInterpolationFunctor(const Axis &xAxis, bool leftX, bool rightX, const char *functionLabel=nullptr)
Definition: StorableInterpolationFunctor.h:59
npstat::StorableInterpolationFunctor::conv_
Converter conv_
Definition: StorableInterpolationFunctor.h:180
SimpleFunctors.h
Interface definitions and concrete simple functors for a variety of functor-based calculations.
npstat::StorableInterpolationFunctor
Definition: StorableInterpolationFunctor.h:25
HLT_FULL_cff.zAxis
zAxis
Definition: HLT_FULL_cff.py:46151
npstat::StorableInterpolationFunctor::setConverter
void setConverter(const Converter &conv)
Definition: StorableInterpolationFunctor.h:155
trackingPlots.other
other
Definition: trackingPlots.py:1460
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
npstat::StorableInterpolationFunctor::classId
gs::ClassId classId() const override
Definition: StorableInterpolationFunctor.h:159
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
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)
Definition: StorableInterpolationFunctor.h:101
HLT_FULL_cff.yAxis
yAxis
Definition: HLT_FULL_cff.py:46152
npstat::StorableInterpolationFunctor::interpolator
const Table & interpolator() const
Definition: StorableInterpolationFunctor.h:145
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
StorableInterpolationFunctor(const std::vector< Axis > &axes, const std::vector< std::pair< bool, bool > > &interpolationType, const char *functionLabel=nullptr)
Definition: StorableInterpolationFunctor.h:54
recoMuon::in
Definition: RecoMuonEnumerators.h:6
npstat::LinInterpolatedTableND::dim
unsigned dim() const
Definition: LinInterpolatedTableND.h:138
npstat::StorableInterpolationFunctor::isEqual
bool isEqual(const StorableMultivariateFunctor &other) const override
Definition: StorableInterpolationFunctor.h:169
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
StorableInterpolationFunctor(const LinInterpolatedTableND< Num2, Axis > &table)
Definition: StorableInterpolationFunctor.h:35
npstat::StorableInterpolationFunctor::read
static StorableInterpolationFunctor * read(const gs::ClassId &id, std::istream &in)
Definition: StorableInterpolationFunctor.h:202
npstat::ArrayND< Numeric >
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
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)
Definition: StorableInterpolationFunctor.h:84
npstat::StorableInterpolationFunctor::write
bool write(std::ostream &of) const override
Definition: StorableInterpolationFunctor.h:196
alignCSCRings.r
r
Definition: alignCSCRings.py:93
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
StorableMultivariateFunctor.h
Interface definition for storable multivariate functors.
npstat::StorableMultivariateFunctor
Definition: StorableMultivariateFunctor.h:23
HLT_FULL_cff.xAxis
xAxis
Definition: HLT_FULL_cff.py:46150
npstat::LinInterpolatedTableND
Definition: LinInterpolatedTableND.h:31
npstat::StorableInterpolationFunctor::~StorableInterpolationFunctor
~StorableInterpolationFunctor() override
Definition: StorableInterpolationFunctor.h:136
npstat::StorableInterpolationFunctor::StorableInterpolationFunctor
StorableInterpolationFunctor(const StorableInterpolationFunctor< Num2, Axis, Conv2 > &tab)
Definition: StorableInterpolationFunctor.h:45
point
*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
table_
Table table_
Definition: ExceptionActions.cc:21
npstat::StorableInterpolationFunctor::classname
static const char * classname()
Definition: StorableInterpolationFunctor.h:190
npstat::StorableInterpolationFunctor::operator()
double operator()(const double *point, unsigned dim) const override
Definition: StorableInterpolationFunctor.h:140
npstat::StorableInterpolationFunctor::minDim
unsigned minDim() const override
Definition: StorableInterpolationFunctor.h:138