Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
JEvtWeightFactor.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTFACTOR__
2 #define __JAANET__JEVTWEIGHTFACTOR__
3 
5 
6 #include "JLang/JStringStream.hh"
7 
8 #include "JSystem/JStat.hh"
9 
10 #include "Jeep/JProperties.hh"
11 
12 #include "JLang/JClonable.hh"
13 
14 
15 /**
16  * \author bjung
17  */
18 
19 namespace JAANET {}
20 namespace JPP { using namespace JAANET; }
21 
22 namespace JAANET {
23 
24  using JLANG::JClonable;
25 
26 
27  /**
28  * Abstract base class for specifiable event-weight factors.
29  */
31  public JClonable<JEvtWeightFactor>
32  {
33  /**
34  * Virtual destructor.
35  */
37  {}
38 
39 
40  /**
41  * Get type keyword.
42  *
43  * \return type keyword
44  */
45  static const char* const getTypeKey()
46  {
47  return "type";
48  }
49 
50 
51  /**
52  * Get event-weight factor of given event.
53  *
54  * \param evt event
55  * \return event-weight factor
56  */
57  virtual double getFactor(const Evt& evt) const = 0;
58 
59 
60  /**
61  * Get event-weight factor of given event.
62  *
63  * \param evt event
64  * \return event-weight factor
65  */
66  double operator()(const Evt& evt) const
67  {
68  return getFactor(evt);
69  }
70 
71 
72  /**
73  * Check whether this event-weight factor is valid.
74  *
75  * \return true if valid; else false
76  */
77  virtual bool is_valid() const
78  {
79  return true;
80  }
81 
82 
83  /**
84  * Check validity of this event-weight factor.
85  */
86  void check_validity() const
87  {
88  using namespace JPP;
89 
90  if (!is_valid()) {
91  THROW(JValueOutOfRange, "JEvtWeightFactor():check_validity(): Invalid event-weight factor " << *this);
92  }
93  }
94 
95 
96  /**
97  * Get equation parameters.
98  *
99  * \return equation parameters
100  */
102  {
103  static JEquationParameters equation("=", ",", "./", "#");
104 
105  return equation;
106  }
107 
108 
109  /**
110  * Set equation parameters.
111  *
112  * \param eqpars equation parameters
113  */
114  static inline void setEquationParameters(const JEquationParameters& eqpars)
115  {
116  getEquationParameters() = eqpars;
117  }
118 
119 
120  /**
121  * Get properties of this class.
122  *
123  * \param eqpars equation parameters
124  */
126  {
127  return JProperties(eqpars,1);
128  }
129 
130 
131  /**
132  * Get properties of this class.
133  *
134  * \param eqpars equation parameters
135  */
137  {
138  return JProperties(eqpars,1);
139  }
140 
141 
142  /**
143  * Read event-weight factor from input.
144  *
145  * \param in input stream
146  * \return input stream
147  */
148  virtual std::istream& read(std::istream& in)
149  {
150  using namespace std;
151  using namespace JPP;
152 
153  JStringStream is(in);
154 
155  if (getFileStatus(is.str().c_str())) {
156  is.load();
157  }
158 
159  JProperties properties = getProperties();
160  is >> properties;
161 
162  check_validity();
163 
164  return in;
165  }
166 
167 
168  /**
169  * Write event-weight factor to output
170  *
171  * \param out output stream
172  * \return output stream
173  */
174  virtual std::ostream& write(std::ostream& out) const
175  {
176  return out << getProperties();
177  }
178 
179 
180  /**
181  * Read event category from input.
182  *
183  * \param in input stream
184  * \param object event category
185  * \return input stream
186  */
187  friend inline std::istream& operator>>(std::istream& in, JEvtWeightFactor& object)
188  {
189  return object.read(in);
190  }
191 
192 
193  /**
194  * Write event category to output.
195  *
196  * \param out output stream
197  * \param object event category
198  * \return output stream
199  */
200  friend inline std::ostream& operator<<(std::ostream& out, const JEvtWeightFactor& object)
201  {
202  return object.write(out);
203  }
204  };
205 }
206 
207 #endif
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Utility class to parse parameter values.
File status.
Utility class to parse parameter values.
Definition: JProperties.hh:501
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
void load()
Load data from file with name corresponding to current contents.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:180
Extensions to Evt data format.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
Abstract base class for specifiable event-weight factors.
static void setEquationParameters(const JEquationParameters &eqpars)
Set equation parameters.
virtual JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) const
Get properties of this class.
friend std::istream & operator>>(std::istream &in, JEvtWeightFactor &object)
Read event category from input.
double operator()(const Evt &evt) const
Get event-weight factor of given event.
static JEquationParameters & getEquationParameters()
Get equation parameters.
virtual ~JEvtWeightFactor()
Virtual destructor.
virtual JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters())
Get properties of this class.
friend std::ostream & operator<<(std::ostream &out, const JEvtWeightFactor &object)
Write event category to output.
virtual std::istream & read(std::istream &in)
Read event-weight factor from input.
virtual bool is_valid() const
Check whether this event-weight factor is valid.
void check_validity() const
Check validity of this event-weight factor.
virtual std::ostream & write(std::ostream &out) const
Write event-weight factor to output.
static const char *const getTypeKey()
Get type keyword.
virtual double getFactor(const Evt &evt) const =0
Get event-weight factor of given event.
Template class for object cloning.
Definition: JClonable.hh:59