Jpp test-rotations-old
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/JColorFacet.hh"
13
15
16
17/**
18 * \author rgruiz, bjung
19 */
20
21namespace JCOMPAREHISTOGRAMS {}
22namespace JPP { using namespace JCOMPAREHISTOGRAMS; }
23
24namespace JCOMPAREHISTOGRAMS {
25
27
28 static const char* const PASSED_t = "PASSED";
29 static const char* const FAILED_t = "FAILED";
30
31 /**
32 * Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived classes.
33 */
35 {
36 public:
37
38 /**
39 * Default constructor.
40 */
42 testName (""),
45 parameterName (""),
46 parameterValue (0.0),
48 passed (false),
50 {}
51
52
53 /**
54 * Constructor
55 *
56 * \param testName Test name
57 * \param hA Name of the first histogram.
58 * \param hB Name of the second histogram.
59 * \param parameter Name of the parameter used for the test.
60 * \param threshold Threshold value for the tested parameter.
61 * \param value Value of the tested parameter.
62 * \param passed true if the test is passed; else false.
63 */
64 JTestSummary(const std::string& testName,
65 const JRootObjectID& hA,
66 const JRootObjectID& hB,
67 const std::string& parameter,
68 const double value,
69 const double threshold,
70 const bool passed):
72 histogramA (hA),
73 histogramB (hB),
74 parameterName (parameter),
75 parameterValue (value),
76 parameterThreshold(threshold),
77 passed (passed),
79 {}
80
81
82 /**
83 * Get equation parameters.
84 *
85 * \return equation parameters
86 */
88 {
89 static JEquationParameters equation("=", "; ", "", "#");
90
91 return equation;
92 }
93
94
95 /**
96 * Set equation parameters.
97 *
98 * \param equation equation parameters
99 */
100 static inline void setEquationParameters(const JEquationParameters& equation)
101 {
102 getEquationParameters() = equation;
103 }
104
105
106 /**
107 * Get properties of this class.
108 *
109 * \param equation equation parameters
110 */
112 {
113 return JTestSummaryHelper(*this, equation);
114 }
115
116
117 /**
118 * Get properties of this class.
119 *
120 * \param equation equation parameters
121 */
123 {
124 return JTestSummaryHelper(*this, equation);
125 }
126
127
128 /**
129 * Read test summary from input.
130 *
131 * \param in input stream
132 * \param object test summary
133 * \return input stream
134 */
135 friend inline std::istream& operator>>(std::istream& in,
136 JTestSummary& object)
137 {
138 using namespace std;
139
140 in >> object.testName
141 >> object.histogramA
142 >> object.histogramB
143 >> object.parameterName
144 >> object.parameterThreshold
145 >> object.passed_h;
146
147 object.passed = (object.passed_h == PASSED_t) ? 1 : 0;
148
149 return in;
150 }
151
152
153 /**
154 * Write test summary to output.
155 *
156 * \param out output stream
157 * \param object test summary
158 * \return output stream
159 */
160 friend inline std::ostream& operator<<(std::ostream& out,
161 JTestSummary& object)
162 {
163 const JFormat format(out);
164
165 out << object.testName << ' '
166 << object.histogramA << ' '
167 << object.histogramB << ' '
168 << object.parameterName << ' '
169 << object.parameterValue << ' '
170 << object.parameterThreshold << ' '
171 << object.passed_h;
172
173 return out;
174 }
175
176 std::string testName; /*!< Test name. */
177 JRootObjectID histogramA; /*!< First histogram. */
178 JRootObjectID histogramB; /*!< Second histogram. */
179 std::string parameterName; /*!< Parameter evaluated by the test. */
180 double parameterValue; /*!< Value of the parameter evaluated by the test.*/
181 double parameterThreshold; /*!< Threshold to evaluate the parameter. */
182 bool passed; /*!< True if the test passed. */
183 std::string passed_h; /*!< Human readable version of passed. */
184
185 private:
186 /**
187 * Auxiliary class for I/O of test result message
188 */
190 public JProperties
191 {
192 public:
193 /**
194 * Constructor.
195 *
196 * \param object test result message
197 * \param equation equation parameters
198 */
199 template<class JTestSummary_t>
200 JTestSummaryHelper(JTestSummary_t& object,
201 const JEquationParameters& equation) :
202 JProperties(equation, 1)
203 {
204 insert(gmake_property(object.testName));
205 insert(gmake_property(object.histogramA));
206 insert(gmake_property(object.histogramB));
207 insert(gmake_property(object.parameterName));
208 insert(gmake_property(object.parameterValue));
209 insert(gmake_property(object.parameterThreshold));
210 insert(gmake_property(object.passed_h));
211 }
212 };
213 };
214
215
216 /**
217 * Read test summary.
218 *
219 * \param in input stream
220 * \param summary test summary
221 * \param delimiter delimiter
222 */
223 inline std::istream& read(std::istream& in,
224 JTestSummary& summary,
225 const char delimiter = ' ')
226 {
227 using namespace std;
228 using namespace JPP;
229
230 JProperties properties = summary.getProperties();
231
232 for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
233
234 string buffer;
235 getline(in, buffer, delimiter);
236
237 istringstream iss(buffer);
238
239 i->second->read(iss);
240 }
241
242 summary.passed = (summary.passed_h == PASSED_t);
243
244 return in;
245 }
246
247
248 /**
249 * Print test summary.
250 *
251 * \param out output stream
252 * \param summary test summary
253 * \param delimiter delimiter
254 * \param useColors
255 */
256 inline std::ostream& print(std::ostream& out,
257 const JTestSummary& summary,
258 const char delimiter = ' ',
259 const bool useColors = true)
260 {
261 using namespace std;
262 using namespace JPP;
263
264 out << scientific << setprecision(2);
265
266 if (useColors) {
267 out << (summary.passed ? GREEN : RED);
268 }
269
270 const JProperties& properties = summary.getProperties();
271
272 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
273 out << i->second.toString() << delimiter;
274 }
275
276 out << RESET << endl;
277
278 return out;
279 }
280
281
282 /**
283 * Print test summary.
284 *
285 * \param out output stream
286 * \param summary test summary
287 * \param __begin begin list of keys
288 * \param __end end list of keys
289 * \param delimiter delimiter
290 * \param useColors
291 */
292 template<class T>
293 inline std::ostream& print(std::ostream& out,
294 const JTestSummary& summary,
295 T __begin,
296 T __end,
297 const char delimiter = ' ',
298 const bool useColors = true)
299 {
300 using namespace std;
301 using namespace JPP;
302
303 out << scientific << setprecision(2);
304
305 if (useColors) {
306 out << (summary.passed ? GREEN : RED);
307 }
308
309 for (T i = __begin; i != __end; ++i) {
310
311 summary.getProperties()[*i]->write(out);
312
313 out << delimiter;
314 }
315
316 out << endl;
317
318 return out;
319 }
320}
321
322#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 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.
std::ostream & write(std::ostream &out) const
Write the current 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).
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter=' ')
Read test summary.
static const char *const FAILED_t
static const char *const PASSED_t
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter=' ', const bool useColors=true)
Print test summary.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636