npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
Distribution1DFactory.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_DISTRIBUTION1DFACTORY_HH_
2 #define NPSTAT_DISTRIBUTION1DFACTORY_HH_
3 
4 /*!
5 // \file Distribution1DFactory.hh
6 //
7 // \brief Factories for 1-d distributions for use in interpretive language
8 // environments
9 //
10 // Author: I. Volobouev
11 //
12 // April 2010
13 */
14 
15 #include <map>
16 #include <vector>
17 #include <string>
18 #include <stdexcept>
19 
21 
22 namespace npstat {
24  {
25  public:
26  inline virtual ~AbsScalableDistribution1DFactory() {}
27  virtual AbsScalableDistribution1D* create(
28  double location, double scale,
29  const std::vector<double>&) const = 0;
30  virtual int nParameters() const = 0;
31  };
32 
33  template <typename T>
35  {
36  public:
37  inline virtual ~ScalableDistribution1DFactory() {}
38 
39  inline int nParameters() const {return T::nParameters();}
40 
41  T* create(const double location, const double scale,
42  const std::vector<double>& params) const
43  {
44  if (nParameters() >= 0)
45  if (params.size() != static_cast<unsigned>(nParameters()))
46  throw std::invalid_argument(
47  "In npstat::ScalableDistribution1DFactory constructor:"
48  " wrong number of distribution parameters");
49  return new T(location, scale, params);
50  }
51  };
52 
53  /**
54  // Use this factory to construct a 1-d distribution from
55  // its name, location, scale, and the vector of other parameters.
56  //
57  // Not all distributions support this construction method. Iterate
58  // over the keys in this map (or look at the Distribution1DFactory.cc
59  // code) for the list of supported distributions. Of course,
60  // user-developed distributions can be added to this factory
61  // as well if they implement a compatible constructor.
62  */
64  public std::map<std::string, AbsScalableDistribution1DFactory *>
65  {
66  public:
69 
70  inline bool contains(const std::string& name) const
71  {return this->find(name) != this->end();}
72 
73  private:
78  };
79 }
80 
81 #endif // NPSTAT_DISTRIBUTION1DFACTORY_HH_
Interface definition for 1-d continuous statistical distributions.
Definition: Distribution1DFactory.hh:24
Definition: AbsDistribution1D.hh:165
Definition: Distribution1DFactory.hh:65
Definition: Distribution1DFactory.hh:35
Definition: AbsArrayProjector.hh:14