npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
StorableHistoNDFunctor.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_STORABLEHISTONDFUNCTOR_HH_
2 #define NPSTAT_STORABLEHISTONDFUNCTOR_HH_
3 
4 /*!
5 // \file StorableHistoNDFunctor.hh
6 //
7 // \brief Storable multivariate functor which uses histogram contents for
8 // data representation
9 //
10 // Author: I. Volobouev
11 //
12 // July 2012
13 */
14 
17 
18 #include "npstat/stat/HistoND.hh"
19 
20 namespace npstat {
21  /**
22  // This class adapts HistoND template together with various histogram
23  // interpolation functions to the StorableMultivariateFunctor interface
24  */
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 
39  //@{
40  /**
41  // Constructor from a pre-existing histogram. The "degree"
42  // argument specifies the interpolation degree which can be
43  // 0, 1, or 3.
44  */
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());}
58  //@}
59 
60  /** Converting copy constructor */
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 
68  virtual ~StorableHistoNDFunctor() {}
69 
70  virtual unsigned minDim() const {return table_.dim();};
71 
72  virtual double operator()(const double* point, unsigned dim) const;
73 
74  /** Retrieve interpolation degree */
75  inline unsigned interpolationDegree() const {return deg_;}
76 
77  /** Set interpolation degree (0, 1, or 3) */
78  void setInterpolationDegree(const unsigned deg);
79 
80  //@{
81  /** Retrieve the underlying HistoND object */
82  inline Table& interpolator() {return table_;}
83  inline const Table& interpolator() const {return table_;}
84  //@}
85 
86  //@{
87  /** Retrieve the tabulated data */
89  {return const_cast<ArrayND<Numeric>&>(table_.binContents());}
90 
91  inline const ArrayND<Numeric>& table() const
92  {return table_.binContents();}
93  //@}
94 
95  /** Change the coordinate converter */
96  inline void setConverter(const Converter& conv) {conv_ = conv;}
97 
98  //@{
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;
102  //@}
103 
104  // I/O methods needed for reading
105  static inline const char* classname();
106  static inline unsigned version() {return 1;}
107  static StorableHistoNDFunctor* read(
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 
132 #include "npstat/stat/StorableHistoNDFunctor.icc"
133 
134 #endif // NPSTAT_STORABLEHISTONDFUNCTOR_HH_
Arbitrary-dimensional histogram template.
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Interface definition for storable multivariate functors.
Definition: HistoND.hh:46
const ArrayND< Numeric > & binContents() const
Definition: HistoND.hh:197
unsigned dim() const
Definition: HistoND.hh:187
Definition: StorableHistoNDFunctor.hh:32
StorableHistoNDFunctor(const HistoND< Num2, Axis > &table, const unsigned degree=1)
Definition: StorableHistoNDFunctor.hh:46
virtual double operator()(const double *point, unsigned dim) const
virtual gs::ClassId classId() const
Definition: StorableHistoNDFunctor.hh:100
void setInterpolationDegree(const unsigned deg)
ArrayND< Numeric > & table()
Definition: StorableHistoNDFunctor.hh:88
void setConverter(const Converter &conv)
Definition: StorableHistoNDFunctor.hh:96
StorableHistoNDFunctor(const StorableHistoNDFunctor< Num2, Axis, Conv2 > &tab)
Definition: StorableHistoNDFunctor.hh:62
virtual bool isEqual(const StorableMultivariateFunctor &other) const
Definition: StorableHistoNDFunctor.hh:111
unsigned interpolationDegree() const
Definition: StorableHistoNDFunctor.hh:75
Table & interpolator()
Definition: StorableHistoNDFunctor.hh:82
virtual unsigned minDim() const
Definition: StorableHistoNDFunctor.hh:70
Definition: StorableMultivariateFunctor.hh:24
const std::string & description() const
Definition: StorableMultivariateFunctor.hh:35
Definition: AbsArrayProjector.hh:14
Definition: SimpleFunctors.hh:191