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