Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JTestSummary.hh
Go to the documentation of this file.
1#ifndef __JCOMPAREHISTOGRAMS__JTESTSUMMARY_T__
2#define __JCOMPAREHISTOGRAMS__JTESTSUMMARY_T__
3
4#include <string>
5#include <istream>
6#include <ostream>
7
8#include "Jeep/JPrint.hh"
9#include "Jeep/JProperties.hh"
10
11#include "JLang/JManip.hh"
12#include "JLang/JVectorize.hh"
13#include "JLang/JColorFacet.hh"
14
16
17
18/**
19 * \author rgruiz, bjung
20 */
21
22namespace JCOMPAREHISTOGRAMS {}
23namespace JPP { using namespace JCOMPAREHISTOGRAMS; }
24
25namespace JCOMPAREHISTOGRAMS {
26
28
29 static const char* const PASSED_t = "PASSED";
30 static const char* const FAILED_t = "FAILED";
31
32 /**
33 * Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived classes.
34 */
36 {
37 public:
38
39 /**
40 * Default constructor.
41 */
43 testName (""),
46 parameterName (""),
47 parameterValue (0.0),
49 passed (false),
51 {}
52
53
54 /**
55 * Constructor
56 *
57 * \param testName Test name
58 * \param hA Name of the first histogram.
59 * \param hB Name of the second histogram.
60 * \param parameter Name of the parameter used for the test.
61 * \param threshold Threshold value for the tested parameter.
62 * \param value Value of the tested parameter.
63 * \param passed true if the test is passed; else false.
64 */
65 JTestSummary(const std::string& testName,
66 const JRootObjectID& hA,
67 const JRootObjectID& hB,
68 const std::string& parameter,
69 const double value,
70 const double threshold,
71 const bool passed):
73 histogramA (hA),
74 histogramB (hB),
75 parameterName (parameter),
76 parameterValue (value),
77 parameterThreshold(threshold),
78 passed (passed),
80 {}
81
82
83 /**
84 * Get equation parameters.
85 *
86 * \return equation parameters
87 */
89 {
90 static JEquationParameters equation("=", "; ", "", "#");
91
92 return equation;
93 }
94
95
96 /**
97 * Set equation parameters.
98 *
99 * \param equation equation parameters
100 */
101 static inline void setEquationParameters(const JEquationParameters& equation)
102 {
103 getEquationParameters() = equation;
104 }
105
106
107 /**
108 * Get properties of this class.
109 *
110 * \param equation equation parameters
111 */
113 {
114 return JTestSummaryHelper(*this, equation);
115 }
116
117
118 /**
119 * Get properties of this class.
120 *
121 * \param equation equation parameters
122 */
124 {
125 return JTestSummaryHelper(*this, equation);
126 }
127
128
129 /**
130 * Read test summary from input.
131 *
132 * \param in input stream
133 * \param object test summary
134 * \return input stream
135 */
136 friend inline std::istream& operator>>(std::istream& in,
137 JTestSummary& object)
138 {
139 in >> object.testName
140 >> object.histogramA
141 >> object.histogramB
142 >> object.parameterName
143 >> object.parameterThreshold
144 >> object.passed_h;
145
146 object.passed = (object.passed_h == PASSED_t) ? 1 : 0;
147
148 return in;
149 }
150
151
152 /**
153 * Write test summary to output.
154 *
155 * \param out output stream
156 * \param object test summary
157 * \return output stream
158 */
159 friend inline std::ostream& operator<<(std::ostream& out,
160 JTestSummary& object)
161 {
162 out << object.testName << ' '
163 << object.histogramA << ' '
164 << object.histogramB << ' '
165 << object.parameterName << ' '
166 << object.parameterValue << ' '
167 << object.parameterThreshold << ' '
168 << object.passed_h;
169
170 return out;
171 }
172
173 std::string testName; /*!< Test name. */
174 JRootObjectID histogramA; /*!< First histogram. */
175 JRootObjectID histogramB; /*!< Second histogram. */
176 std::string parameterName; /*!< Parameter evaluated by the test. */
177 double parameterValue; /*!< Value of the parameter evaluated by the test.*/
178 double parameterThreshold; /*!< Threshold to evaluate the parameter. */
179 bool passed; /*!< True if the test passed. */
180 std::string passed_h; /*!< Human readable version of passed. */
181
182 private:
183 /**
184 * Auxiliary class for I/O of test result message
185 */
187 public JProperties
188 {
189 public:
190 /**
191 * Constructor.
192 *
193 * \param object test result message
194 * \param equation equation parameters
195 */
196 template<class JTestSummary_t>
197 JTestSummaryHelper(JTestSummary_t& object,
198 const JEquationParameters& equation) :
199 JProperties(equation, 1)
200 {
201 insert(gmake_property(object.testName));
202 insert(gmake_property(object.histogramA));
203 insert(gmake_property(object.histogramB));
204 insert(gmake_property(object.parameterName));
205 insert(gmake_property(object.parameterValue));
206 insert(gmake_property(object.parameterThreshold));
207 insert(gmake_property(object.passed_h));
208 }
209 };
210 };
211
212
213 /**
214 * Read test summary.
215 *
216 * \param in input stream
217 * \param summary test summary
218 */
219 inline std::istream& read(std::istream& in,
220 JTestSummary& summary)
221 {
222 using namespace std;
223 using namespace JPP;
224
225 JProperties properties = summary.getProperties();
226
227 for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
228
229 string buffer;
230 in >> buffer;
231
232 istringstream iss(buffer);
233
234 i->second->read(iss);
235 }
236
237 summary.passed = (summary.passed_h == PASSED_t);
238
239 return in;
240 }
241
242
243 /**
244 * Print test summary.
245 *
246 * \param out output stream
247 * \param summary test summary
248 * \param __begin begin list of keys
249 * \param __end end list of keys
250 * \param useColors toggle colors
251 * \param formatting formatting
252 */
253 template<class T>
254 inline std::ostream& print(std::ostream& out,
255 const JTestSummary& summary,
256 T __begin,
257 T __end,
258 const bool useColors = true,
259 const JFormat_t& formatting = JFormat_t(18, 3, std::ios::fixed))
260 {
261 using namespace std;
262 using namespace JPP;
263
264 const JFormat format(out, formatting);
265
266 if (useColors) {
267 out << (summary.passed ? GREEN : RED);
268 }
269
270 const JProperties& properties = summary.getProperties();
271
272 for (T i = __begin; i != __end; ++i) {
273
274 JProperties::const_iterator p = properties.find(*i);
275
276 if (p != properties.cend()) {
277
278 out << format;
279
280 p->second->write(out);
281
282 out << properties.getDefaultWhiteSpace();
283 }
284 }
285
286 out << RESET << endl;
287
288 return out;
289 }
290
291
292 /**
293 * Print test summary.
294 *
295 * \param out output stream
296 * \param summary test summary
297 * \param useColors toggle colors
298 * \param formatting formatting
299 */
300 inline std::ostream& print(std::ostream& out,
301 const JTestSummary& summary,
302 const bool useColors = true,
303 const JFormat_t& formatting = JFormat_t(18, 3, std::ios::fixed))
304 {
305 using namespace std;
306 using namespace JPP;
307
308 const JProperties& properties = summary.getProperties();
309
310 const array_type<string>& keys = get_keys(properties);
311
312 return print(out, summary, keys.cbegin(), keys.cend(), useColors, formatting);
313 }
314}
315
316#endif
I/O manipulators.
I/O formatting auxiliaries.
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
Auxiliary class for I/O of test result message.
JTestSummaryHelper(JTestSummary_t &object, const JEquationParameters &equation)
Constructor.
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
static JEquationParameters & getEquationParameters()
Get equation parameters.
friend std::ostream & operator<<(std::ostream &out, JTestSummary &object)
Write test summary to output.
JTestSummary()
Default constructor.
JTestSummary(const std::string &testName, const JRootObjectID &hA, const JRootObjectID &hB, const std::string &parameter, const double value, const double threshold, const bool passed)
Constructor.
static void setEquationParameters(const JEquationParameters &equation)
Set equation parameters.
friend std::istream & operator>>(std::istream &in, JTestSummary &object)
Read test summary from input.
JProperties getProperties(const JEquationParameters &equation=JTestSummary::getEquationParameters())
Get properties of this class.
JProperties getProperties(const JEquationParameters &equation=JTestSummary::getEquationParameters()) const
Get properties of this class.
Utility class to parse parameter values.
Auxiliary class to handle file name, ROOT directory and object name.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
const char getDefaultWhiteSpace() const
Get default white space character.
static const char *const FAILED_t
std::ostream & print(std::ostream &out, const JTestSummary &summary, T __begin, T __end, const bool useColors=true, const JFormat_t &formatting=JFormat_t(18, 3, std::ios::fixed))
Print test summary.
static const char *const PASSED_t
std::istream & read(std::istream &in, JTestSummary &summary)
Read test summary.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636
Auxiliary data structure for return type of make methods.
Definition JVectorize.hh:28