npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
BoundaryHandling.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_BOUNDARYHANDLING_HH_
2 #define NPSTAT_BOUNDARYHANDLING_HH_
3 
4 /*!
5 // \file BoundaryHandling.hh
6 //
7 // \brief API for LOrPE boundary handling methods
8 //
9 // Author: I. Volobouev
10 //
11 // June 2015
12 */
13 
14 #include <vector>
15 #include <string>
16 
17 #include "geners/ClassId.hh"
18 
19 namespace npstat {
21  {
22  public:
23  /**
24  // Maximum number of parameters used by any of the LOrPE boundary
25  // handling methods
26  */
27  enum {
28  BM_MAXPARAMS = 4U
29  };
30 
31  /*
32  // Default constructor actually creates a usable default method
33  */
34  inline BoundaryHandling() {initialize(0, 0, 0);}
35 
36  inline explicit BoundaryHandling(const char* in_methodName,
37  const double* params = 0,
38  const unsigned nParams = 0)
39  {initialize(in_methodName, params, nParams);}
40 
41  inline BoundaryHandling(const char* in_methodName,
42  const std::vector<double>& params)
43  {
44  const unsigned nParams = params.size();
45  initialize(in_methodName, nParams?&params[0]:(double*)0, nParams);
46  }
47 
48  const char* methodName() const;
49 
50  inline const double* parameters() const
51  {return nParams_ ? params_ : (double*)0;}
52 
53  inline unsigned nParameters() const {return nParams_;}
54 
55  /**
56  // The id of the given boundary handling method can change from
57  // one NPStat release to another, so do not store it anywhere
58  */
59  inline unsigned methodId() const {return id_;}
60 
61  bool operator==(const BoundaryHandling& r) const;
62  inline bool operator!=(const BoundaryHandling& r) const
63  {return !(*this == r);}
64 
65  bool operator<(const BoundaryHandling& r) const;
66 
67  inline bool operator>(const BoundaryHandling& r) const
68  {return r < *this;}
69 
70  /**
71  // Does given C-string represent a valid boundary method name?
72  // Valid boundary method names are listed in the comments to the
73  // "npstat/stat/BoundaryMethod.hh" header file. Nullptr corresponds
74  // to a valid name with id 0.
75  */
76  static bool isValidMethodName(const char* name);
77 
78  /** All valid boundary method names (for use in error messages, etc) */
79  static std::string validMethodNames();
80 
81  /**
82  // Does given C-string represent a valid boundary method name for
83  // a method which does not need additional parameters?
84  */
85  static bool isParameterFree(const char* name);
86 
87  /** Names of boundary methods which do not need any parameters */
88  static std::string parameterFreeNames();
89 
90  /** Number of parameters needed for the method with the given name */
91  static unsigned expectedNParameters(const char* name);
92 
93  // I/O methods needed for writing
94  inline gs::ClassId classId() const {return gs::ClassId(*this);}
95  bool write(std::ostream& of) const;
96 
97  // I/O methods needed for reading
98  static inline const char* classname()
99  {return "npstat::BoundaryHandling";}
100  static inline unsigned version() {return 1;}
101  static void restore(const gs::ClassId& id, std::istream& in,
102  BoundaryHandling* ptr);
103 
104  private:
105  void initialize(const char* methodName,
106  const double* params, unsigned nParams);
107 
108  double params_[BM_MAXPARAMS];
109  unsigned nParams_;
110  unsigned id_;
111  };
112 }
113 
114 #endif // NPSTAT_BOUNDARYHANDLING_HH_
Definition: BoundaryHandling.hh:21
static bool isValidMethodName(const char *name)
static std::string validMethodNames()
static std::string parameterFreeNames()
static bool isParameterFree(const char *name)
static unsigned expectedNParameters(const char *name)
unsigned methodId() const
Definition: BoundaryHandling.hh:59
Definition: AbsArrayProjector.hh:14