Jpp  debug
the software that should make you happy
JEvtWeightFactorConstant.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTFACTORCONSTANT__
2 #define __JAANET__JEVTWEIGHTFACTORCONSTANT__
3 
4 #include "JLang/JManip.hh"
5 #include "JLang/JClonable.hh"
6 #include "JLang/JComparable.hh"
7 
8 #include "Jeep/JProperties.hh"
9 
11 
12 
13 /**
14  * \author bjung
15  */
16 
17 namespace JAANET {}
18 namespace JPP { using namespace JAANET; }
19 
20 namespace JAANET {
21 
22  using JLANG::JClonable;
23  using JLANG::JComparable;
24 
25  using JEEP::JProperties;
26 
27 
28  /**
29  * Class for constant event-weight factors.
30  *
31  * The template argument refers to the type of event-weighter.
32  */
33  template<class JEvtWeightFactor_t>
35  public JComparable<JEvtWeightFactorConstant<JEvtWeightFactor_t> >,
36  public JClonable<JEvtWeightFactor_t, JEvtWeightFactorConstant<JEvtWeightFactor_t> >
37  {
39 
40 
41  /**
42  * Default constructor.
43  */
45  constant(1.0)
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param constant constant
53  */
56  {
57  this->check_validity();
58  }
59 
60 
61  /**
62  * Check whether this constant event-weight factor is valid.
63  *
64  * \return true if valid; else false
65  */
66  bool is_valid() const override final
67  {
68  return constant > 0.0;
69  }
70 
71 
72  /**
73  * Get event-weight factor of given event.
74  *
75  * \param evt event
76  * \return event-weight factor
77  */
78  double getFactor(const Evt& evt) const override final
79  {
80  return constant;
81  }
82 
83 
84  /**
85  * Check if this event-weight constant is less than given event-weight constant.
86  *
87  * \param object event-weight constant
88  * \return true if this event-weight constant is less than given event-weight constant; else false
89  */
90  bool less(const JEvtWeightFactorConstant_t& object) const
91  {
92  return this->constant < object.constant;
93  }
94 
95 
96  /**
97  * Get properties of this class.
98  *
99  * \param eqpars equation parameters
100  */
102  {
103  return JEvtWeightFactorConstantHelper(*this, eqpars);
104  }
105 
106 
107  /**
108  * Get properties of this class.
109  *
110  * \param eqpars equation parameters
111  */
113  {
114  return JEvtWeightFactorConstantHelper(*this, eqpars);
115  }
116 
117 
118  /**
119  * Stream input.
120  *
121  * \param in input stream
122  * \return input stream
123  */
124  std::istream& read(std::istream& in) override final
125  {
126  using namespace std;
127 
128  streampos pos = in.tellg();
129 
130  if (!(in >> constant)) {
131 
132  in.clear();
133  in.seekg(pos);
134 
135  JProperties properties = getProperties();
136 
137  in >> properties;
138  }
139 
140  this->check_validity();
141 
142  return in;
143  }
144 
145 
146  /**
147  * Write event-weight factor to output
148  *
149  * \param out output stream
150  * \return output stream
151  */
152  std::ostream& write(std::ostream& out) const override final
153  {
154  using namespace JPP;
155 
156  return out << FIXED(10,3) << constant;
157  }
158 
159 
160  private:
161 
162  /**
163  * Auxiliary class for I/O of constant event-weight factor.
164  */
166  public JProperties
167  {
168  /**
169  * Constructor.
170  *
171  * \param factor constant event-weight factor
172  * \param eqpars equation parameters
173  */
174  template<class JEvtWeightFactorConstant_T>
175  JEvtWeightFactorConstantHelper(JEvtWeightFactorConstant_T& factor,
176  const JEquationParameters& eqpars) :
177  JProperties(eqpars, 1)
178  {
179  (*this)[JEvtWeightFactor::getTypeKey()] = "constant";
180 
181  this->insert(gmake_property(factor.constant));
182  }
183  };
184 
185 
186  double constant; //!< constant value
187  };
188 }
189 
190 #endif
I/O manipulators.
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
Definition: JProperties.hh:501
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Extensions to Evt data format.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Auxiliary class for I/O of constant event-weight factor.
JEvtWeightFactorConstantHelper(JEvtWeightFactorConstant_T &factor, const JEquationParameters &eqpars)
Constructor.
Class for constant event-weight factors.
double getFactor(const Evt &evt) const override final
Get event-weight factor of given event.
JEvtWeightFactorConstant(const double constant)
Constructor.
JEvtWeightFactorConstant< JEvtWeightFactor_t > JEvtWeightFactorConstant_t
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) const override final
Get properties of this class.
bool less(const JEvtWeightFactorConstant_t &object) const
Check if this event-weight constant is less than given event-weight constant.
std::istream & read(std::istream &in) override final
Stream input.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) override final
Get properties of this class.
bool is_valid() const override final
Check whether this constant event-weight factor is valid.
std::ostream & write(std::ostream &out) const override final
Write event-weight factor to output.
static JEquationParameters & getEquationParameters()
Get equation parameters.
static const char *const getTypeKey()
Get type keyword.
Template class for object cloning.
Definition: JClonable.hh:59
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:139