CMS 3D CMS Logo

StorableHistoNDFunctor.h
Go to the documentation of this file.
1 #ifndef NPSTAT_STORABLEHISTONDFUNCTOR_HH_
2 #define NPSTAT_STORABLEHISTONDFUNCTOR_HH_
3 
17 
19 
20 namespace npstat {
25  template
26  <
27  class Numeric,
28  class Axis = HistoAxis,
29  class Converter = Same<Numeric>
30  >
32  {
33  template <typename Num2, typename Axis2, typename Conv2>
34  friend class StorableHistoNDFunctor;
35 
36  public:
38 
40 
45  template <class Num2>
47  const HistoND<Num2,Axis>& table, const unsigned degree=1)
48  : StorableMultivariateFunctor(), table_(table), deg_(degree)
49  {validateInterDegree(degree, table.isUniformlyBinned());}
50 
51  template <class Num2>
54  const unsigned degree,
55  const std::string& descr)
56  : StorableMultivariateFunctor(descr), table_(table), deg_(degree)
57  {validateInterDegree(degree, table.isUniformlyBinned());}
59 
61  template <class Num2, class Conv2>
65  table_(tab.table_, Same<Num2>(), tab.title().c_str(),
66  tab.accumulatedDataLabel().c_str()), deg_(tab.deg_) {}
67 
69 
70  virtual unsigned minDim() const {return table_.dim();};
71 
72  virtual double operator()(const double* point, unsigned dim) const;
73 
75  inline unsigned interpolationDegree() const {return deg_;}
76 
78  void setInterpolationDegree(const unsigned deg);
79 
81 
82  inline Table& interpolator() {return table_;}
83  inline const Table& interpolator() const {return table_;}
85 
87 
89  {return const_cast<ArrayND<Numeric>&>(table_.binContents());}
90 
91  inline const ArrayND<Numeric>& table() const
92  {return table_.binContents();}
94 
96  inline void setConverter(const Converter& conv) {conv_ = conv;}
97 
99  // Method related to "geners" I/O
100  virtual gs::ClassId classId() const {return gs::ClassId(*this);}
101  virtual bool write(std::ostream& of) const;
103 
104  // I/O methods needed for reading
105  static inline const char* classname();
106  static inline unsigned version() {return 1;}
108  const gs::ClassId& id, std::istream& in);
109 
110  protected:
111  virtual bool isEqual(const StorableMultivariateFunctor& other) const
112  {
113  // Note the use of static_cast rather than dynamic_cast below.
114  // static_cast works faster and it is guaranteed to succeed here.
115  const StorableHistoNDFunctor& r =
116  static_cast<const StorableHistoNDFunctor&>(other);
117  return table_ == r.table_ && deg_ == r.deg_ &&
118  this->description() == other.description();
119  }
120 
121  private:
123 
124  Table table_;
125  unsigned deg_;
126  Converter conv_;
127 
128  static void validateInterDegree(unsigned deg, bool isUniform);
129  };
130 }
131 
133 
134 #include "Alignment/Geners/interface/binaryIO.hh"
135 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
136 #include "Alignment/Geners/interface/IOException.hh"
137 
139 
140 namespace npstat {
141  template <class Numeric, class Axis, class Converter>
143  const double* point, const unsigned dim) const
144  {
145  return conv_(interpolateHistoND(table_, point, dim, deg_));
146  }
147 
148  template <class Numeric, class Axis, class Converter>
150  {
151  static const std::string myClass(gs::template_class_name<Numeric,Axis>(
152  "npstat::StorableHistoNDFunctor"));
153  return myClass.c_str();
154  }
155 
156  template <class Numeric, class Axis, class Converter>
158  {
159  gs::write_pod(of, this->description());
160  gs::write_pod(of, deg_);
161  return table_.classId().write(of) && table_.write(of);
162  }
163 
164  template <class Numeric, class Axis, class Converter>
167  const gs::ClassId& id, std::istream& in)
168  {
169  static const gs::ClassId current(
170  gs::ClassId::makeId<StorableHistoNDFunctor<Numeric,Axis> >());
171  current.ensureSameId(id);
172 
173  std::string descr;
174  gs::read_pod(in, &descr);
175  unsigned deg;
176  gs::read_pod(in, &deg);
177  gs::ClassId tabid(in, 1);
178  if (in.fail()) throw gs::IOReadFailure(
179  "In npstat::StorableHistoNDFunctor::read: "
180  "input stream failure");
181  CPP11_auto_ptr<Table> tab(Table::read(tabid, in));
182  return new StorableHistoNDFunctor(*tab, deg, descr);
183  }
184 
185  template <class Numeric, class Axis, class Converter>
187  const unsigned deg)
188  {
190  deg_ = deg;
191  }
192 
193  template <class Numeric, class Axis, class Converter>
195  const unsigned deg, const bool isUniform)
196  {
197  const bool ok = isUniform ? (deg == 0 || deg == 1 || deg == 3) :
198  (deg == 0 || deg == 1);
199  if (!ok)
201  "In npstat::StorableHistoNDFunctor::validateInterDegree: "
202  "unsupported interpolation degree");
203  }
204 }
205 
206 
207 #endif // NPSTAT_STORABLEHISTONDFUNCTOR_HH_
208 
bool write(std::ostream &of) const
Definition: HistoND.h:3575
static HepMC::IO_HEPEVT conv
virtual double operator()(const double *point, unsigned dim) const
virtual bool isEqual(const StorableMultivariateFunctor &other) const
Interface definition for storable multivariate functors.
StorableHistoNDFunctor(const StorableHistoNDFunctor< Num2, Axis, Conv2 > &tab)
virtual bool write(std::ostream &of) const
Arbitrary-dimensional histogram template.
static void validateInterDegree(unsigned deg, bool isUniform)
gs::ClassId classId() const
Definition: HistoND.h:837
const ArrayND< Numeric > & binContents() const
Definition: HistoND.h:167
Exceptions for the npstat namespace.
bool isUniformlyBinned() const
Definition: HistoND.h:1480
static StorableHistoNDFunctor * read(const gs::ClassId &id, std::istream &in)
virtual gs::ClassId classId() const
Interface definitions and concrete simple functors for a variety of functor-based calculations...
virtual unsigned minDim() const
static HistoND * read(const gs::ClassId &id, std::istream &in)
Definition: HistoND.h:3590
StorableHistoNDFunctor(const HistoND< Num2, Axis > &table, const unsigned degree, const std::string &descr)
Float interpolateHistoND(const HistoND< Float, Axis > &histo, const double *coords, unsigned coordsDim, unsigned interpolationDegree)
StorableHistoNDFunctor(const HistoND< Num2, Axis > &table, const unsigned degree=1)
const ArrayND< Numeric > & table() const
void setInterpolationDegree(const unsigned deg)
Interpolate histogram contents.
unsigned dim() const
Definition: HistoND.h:157
*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
void setConverter(const Converter &conv)