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