Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JTest_t.hh
Go to the documentation of this file.
1#ifndef __JCOMPAREHISTOGRAMS__JTEST_T__
2#define __JCOMPAREHISTOGRAMS__JTEST_T__
3
4#include <istream>
5#include <ostream>
6#include <cmath>
7#include <vector>
8
9#include "Jeep/JPrint.hh"
10#include "Jeep/JProperties.hh"
11
12#include "JLang/JPredicate.hh"
13#include "JLang/JColorFacet.hh"
14
16
17#include <TFile.h>
18#include <TObject.h>
19
20
21/**
22 * \author rgruiz, bjung
23 */
24
25namespace JCOMPAREHISTOGRAMS {}
26namespace JPP { using namespace JCOMPAREHISTOGRAMS; }
27
28namespace JCOMPAREHISTOGRAMS {
29
30
31 /**
32 * Interface to read input and write output for TObject tests.\n
33 * This is an abstract class from which the different tests are derived.\n
34 * All tests have in common the methods from this interface.\n
35 * For each test, the parameters are passed through an istream, and parsed by the read() method.\n
36 * For each test, the different results are stored in the internal results buffer.\n
37 * The write() method is used to print a message with the result of the test.\n
38 * The save() method is used to save a graphical output with the test results into a .root file.\n
39 * For a list of available tests see JTestDictionary()
40 */
41 class JTest_t :
42 public std::vector<JTestResult>
43 {
44 public:
45
46 /**
47 * Constructor.
48 *
49 * \param testName test name
50 * \param resultType result type
51 */
52 JTest_t(const std::string& testName,
53 const std::string& resultType) :
56 {}
57
58
59 /**
60 * Tests compatibility between two TObjects.
61 *
62 * \param o1 First object
63 * \param o2 Second object
64 */
65 virtual void test(const TObject* o1, const TObject* o2) = 0;
66
67
68 /**
69 * Read test parameters from input.
70 *
71 * \param in input stream
72 * \return input stream
73 */
74 virtual std::istream& read (std::istream& in) = 0;
75
76
77 /**
78 * Write test result to output.
79 *
80 * \param out output stream
81 * \param delimiter field delimiter
82 * \param onlyFailures if true, write only failures.
83 * \return output stream
84 */
85 virtual std::ostream& write(std::ostream& out,
86 const char delimiter = ' ',
87 const bool onlyFailures = false) const
88 {
89 using namespace std;
90 using namespace JPP;
91
92 for (vector<JTestResult>::const_iterator r = this->begin() ; r != this->end() ; ++r) {
93
94 if (onlyFailures && r->passed) { continue; }
95
96 print(out, *r, delimiter, true);
97 }
98
99 return out;
100 }
101
102
103 /**
104 * Writes the test result to root file
105 * \param f A ROOT file
106 * \param path Path in root file.
107 * \param onlyFailures If true, write only failures.
108 */
109 virtual void save(TFile* f ,
110 const std::string& path,
111 const bool onlyFailures = false) const
112 {
113 using namespace std;
114 using namespace JPP;
115
116 if (f->GetDirectory(path.c_str())==0) {
117 f->mkdir(path.c_str());
118 }
119
120 f->cd(path.c_str());
121
122 for (vector<JTestResult>::const_iterator r = this->begin() ; r != this->end() ; ++r) {
123
124 if (onlyFailures && r->passed) { continue; }
125
126 r->obj->Write();
127 }
128 }
129
130
131 /**
132 * Get test name.
133 *
134 * \return test name
135 */
136 const std::string& getTestName() const
137 {
138 return testName;
139 }
140
141
142 /**
143 * Get result type.
144 *
145 * \return result type
146 */
147 const std::string& getResultType() const
148 {
149 return resultType;
150 }
151
152
153 /**
154 * Read test parameters from input.
155 *
156 * \param in input stream
157 * \param test test
158 * \return input stream
159 */
160 friend inline std::istream& operator>>(std::istream& in, JTest_t& test)
161 {
162 return test.read(in);
163 }
164
165
166 /**
167 * Write test result to output.
168 *
169 * \param out output stream
170 * \param test test
171 * \return output stream
172 */
173 friend inline std::ostream& operator<<(std::ostream& out, const JTest_t& test)
174 {
175 return test.write(out);
176 }
177
178
179 protected:
180
181 const std::string testName; //!< test name
182 const std::string resultType; //!< test result type
183 };
184}
185
186#endif
I/O formatting auxiliaries.
Utility class to parse parameter values.
Interface to read input and write output for TObject tests.
Definition JTest_t.hh:43
const std::string resultType
test result type
Definition JTest_t.hh:182
friend std::ostream & operator<<(std::ostream &out, const JTest_t &test)
Write test result to output.
Definition JTest_t.hh:173
const std::string & getResultType() const
Get result type.
Definition JTest_t.hh:147
const std::string & getTestName() const
Get test name.
Definition JTest_t.hh:136
virtual void test(const TObject *o1, const TObject *o2)=0
Tests compatibility between two TObjects.
virtual std::ostream & write(std::ostream &out, const char delimiter=' ', const bool onlyFailures=false) const
Write test result to output.
Definition JTest_t.hh:85
const std::string testName
test name
Definition JTest_t.hh:181
friend std::istream & operator>>(std::istream &in, JTest_t &test)
Read test parameters from input.
Definition JTest_t.hh:160
virtual std::istream & read(std::istream &in)=0
Read test parameters from input.
JTest_t(const std::string &testName, const std::string &resultType)
Constructor.
Definition JTest_t.hh:52
virtual void save(TFile *f, const std::string &path, const bool onlyFailures=false) const
Writes the test result to root file.
Definition JTest_t.hh:109
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.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).