Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTest_t.hh
Go to the documentation of this file.
1 #ifndef __JTEST_T__
2 #define __JTEST_T__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "Jeep/JProperties.hh"
8 
9 #include <TROOT.h>
10 #include <TObject.h>
11 #include <TH1.h>
12 #include <TH2.h>
13 #include <TH3.h>
14 
15 /**
16  * \author rgruiz
17  */
18 
19 /**
20  * Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived classes.
21  */
23  public JProperties
24 {
25 public:
26  /**
27  * Default constructor
28  */
30  name (" "),
31  parameter (" "),
32  passed (" "),
33  value (-9999.0)
34  {
35  this->setEndOfLine(":");
36  this->insert(gmake_property(name));
37  this->insert(gmake_property(parameter));
38  this->insert(gmake_property(value));
39  this->insert(gmake_property(passed));
40  };
41 
42  /**
43  * Constructor
44  *
45  * \param Name Test name
46  * \param Parameter Name of the parameter used to decide if the test passes.
47  * \param Value Value of the parameter used to decide if the test passes.
48  * \param Passed True if the test passes, false if it fails.
49  */
50  JResultTitle(std::string Name, std::string Parameter, bool Passed, double Value):
51  name (Name),
52  parameter (Parameter),
53  value (Value)
54  {
55  this->setEndOfLine(":");
56  passed = Passed ? "TRUE" : "FALSE";
57 
58  this->insert(gmake_property(name));
59  this->insert(gmake_property(parameter));
60  this->insert(gmake_property(value));
61  this->insert(gmake_property(passed));
62  }
63 
64  /**
65  * Returns a standard string to be used as title of a graphical root object.
66  */
67  std::string getTitle(){
68  return MAKE_STRING(*this);
69  }
70 
71  std::string name; /*!< Test name. */
72  std::string parameter; /*!< Name of the parameter used to evaluate the test. */
73  std::string passed; /*!< Human readable version of "passed". */
74  double value; /*!< Value of the parameter used to evaluate the test.*/
75 };
76 
77 /**
78  * Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived classes.
79  */
81 {
82 public:
83  /**
84  * Default constructor
85  */
87  testName (" "),
88  nameA (" "),
89  nameB (" "),
90  parameter (" "),
91  value (-9999.0),
92  threshold (-9999.0),
93  passed (false)
94  {};
95 
96  /**
97  * Constructor
98  *
99  * \param testName Test name
100  * \param nameA Name of the first histogram.
101  * \param nameB Name of the second histogram.
102  * \param parameter Name of the parameter used for the test.
103  * \param threshold Threshold value for the tested parameter.
104  * \param value Value of the tested parameter.
105  * \param passed true if the test is passed.
106  */
107  JResultMessage(std::string testName, std::string nameA, std::string nameB, std::string parameter, double value, double threshold, bool passed):
108  testName (testName),
109  nameA (nameA),
110  nameB (nameB),
111  parameter (parameter),
112  value (value),
113  threshold (threshold),
114  passed (passed)
115  {
116  passed_h = passed ? "PASSED" : "FAILED";
117  };
118 
119  /**
120  * Read test parameters from input.
121  *
122  * \param in input stream
123  * \return input stream
124  */
125  std::istream& read(std::istream& in) {
126  in >>
127  testName >>
128  nameA >>
129  nameB >>
130  parameter >>
131  value >>
132  threshold >>
133  passed_h;
134  passed = (passed_h == "PASSED") ? 1 : 0;
135  return in;
136  };
137 
138  /**
139  * Returns a standard string to be used as title of a graphical root object.
140  */
141  std::string getMessage(){
142  return MAKE_STRING(testName << " " <<
143  nameA << " " <<
144  nameB << " " <<
145  parameter << " " <<
146  value << " " <<
147  threshold << " " <<
148  passed_h);
149  }
150 
151  std::string testName; /*!< Test name. */
152  std::string nameA; /*!< Name of the first histogram. */
153  std::string nameB; /*!< Name of the second histogram. */
154  std::string parameter; /*!< Parameter evaluated by the test". */
155  double value; /*!< Value of the parameter evaluated by the test.*/
156  double threshold; /*!< Threshold to evaluate the parameter. */
157  bool passed; /*!< True if the test passed. */
158  std::string passed_h; /*!< Human readable version of passed. */
159 };
160 
161 /**
162  * Structure containing the result of the test. It contains a bool and a message to print
163  */
164 struct JTestResult{
165 
167  passed = false;
168  message = "0";
169  obj = NULL;
170  testName = "";
171  histogramA = "";
172  histogramB = "";
173  fileA = "";
174  fileB = "";
175  parameterName = "";
176  parameterValue = 0.0;
177  parameterThreshold = 0.0;
178  passed = false;
179  passed_h = "";
180  }
181 
182  JTestResult(std::string test, std::string hA, std::string hB, std::string fA, std::string fB, std::string parameter, double value, double threshold, TObject* o, bool pass):
183  testName (test),
184  histogramA (hA),
185  histogramB (hB),
186  fileA (fA),
187  fileB (fB),
188  parameterName (parameter),
189  parameterValue (value),
190  parameterThreshold (threshold),
191  obj (o),
192  passed (pass)
193  {
194  passed_h = passed ? "PASSED" : "FAILED";
195  }
196 
197  std::string print(std::string separator) const {
198  return MAKE_STRING(testName << separator <<
199  fileA .substr (fileA.rfind ('/') + 1 , fileA.npos) <<
200  histogramA.substr (histogramA.rfind (':') + 1 , histogramA.npos) << separator <<
201  fileB .substr (fileB.rfind ('/') + 1 , fileB.npos) <<
202  histogramB.substr (histogramB.rfind (':') + 1 , histogramB.npos) << separator <<
203  parameterName << separator <<
204  parameterValue << separator <<
205  parameterThreshold << separator <<
206  passed_h);
207  }
208 
209  std::string printASCII() const {
210  return MAKE_STRING(testName << ";" <<
211  fileA .substr (fileA.rfind ('/') + 1 , fileA.npos) <<
212  histogramA.substr (histogramA.rfind (':') + 1 , histogramA.npos) << ";" <<
213  fileB .substr (fileB.rfind ('/') + 1 , fileB.npos) <<
214  histogramB.substr (histogramB.rfind (':') + 1 , histogramB.npos) << ";" <<
215  parameterName << ";" <<
216  parameterValue << ";" <<
217  parameterThreshold << ";" <<
218  passed);
219  }
220 
221  std::string testName; /*!< Test name */
222  std::string histogramA; /*!< Name of histogram A */
223  std::string histogramB; /*!< Name of histogram B */
224  std::string fileA; /*!< Name of file A */
225  std::string fileB; /*!< Name of file B */
226  std::string parameterName; /*!< Name of the tested parameter */
227  double parameterValue; /*!< Value of the tested parameter */
228  double parameterThreshold; /*!< Threshold for the tested parameter */
229  TObject* obj; /*!< Graphical output summarising the test. */
230  bool passed; /*!< Test result. True if test passed. */
231  std::string passed_h; /*!< Human readable version of passed */
232  std::string message; /*!< Human readable message with test result. */
233 };
234 
235 /**
236  * Interface to read input and write output for TObject tests.\n
237  * This is an abstract class from which the different tests are derived.\n
238  * All tests have in common the methods from this interface.\n
239  * For each test, the parameters are passed through an istream, and parsed by the read() method.\n
240  * For each test, the different results are stored in the results buffer.\n
241  * The write() method is used to print a message with the result of the test.\n
242  * The save() method is used to save a graphical output with the test results into a .root file.\n
243  * The clear() method clears the results buffer.
244  * For a list of available tests see JTestDictionary()
245  */
246 class JTest_t
247 {
248 
249 public:
250 
251  std::vector<JTestResult> results; /*!< Buffer to store results of multiple tests.*/
252 
253  /**
254  * Read test parameters from input.
255  *
256  * \param in input stream
257  * \return input stream
258  */
259  virtual std::istream& read (std::istream& in) = 0;
260 
261  /**
262  * Write test result to output.
263  *
264  * \param out output stream
265  * \param delimiter field delimiter
266  * \param failures If true, write only failures.
267  * \return output stream
268  */
269  virtual std::ostream& write(std::ostream& out, std::string delimiter = " ", bool failures = false) const = 0;
270 
271  /**
272  * Tests compatibility between two TObjects.
273  *
274  * \param o1 First object
275  * \param o2 Second object
276  */
277  virtual void test(TObject* o1, TObject* o2) = 0;
278 
279  /**
280  * Writes the test result to root file
281  * \param f A ROOT file
282  * \param path Path in root file.
283  * \param failures If true, write only failures.
284  */
285  virtual void save(TFile* f , std::string path, bool failures = false) = 0;
286 
287  /**
288  * Clear results
289  */
290  virtual void clear() = 0;
291 
292  /**
293  * Get test name.
294  */
295  virtual std::string getName() = 0;
296 
297  /**
298  * Get test parameter.
299  */
300  virtual std::string getParameter() = 0;
301 
302 };
303 
304 #endif
std::string nameB
Definition: JTest_t.hh:153
virtual std::string getName()=0
Get test name.
virtual std::string getParameter()=0
Get test parameter.
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JTest_t.hh:22
std::string testName
Definition: JTest_t.hh:151
JTestResult(std::string test, std::string hA, std::string hB, std::string fA, std::string fB, std::string parameter, double value, double threshold, TObject *o, bool pass)
Definition: JTest_t.hh:182
virtual void test(TObject *o1, TObject *o2)=0
Tests compatibility between two TObjects.
JResultTitle(std::string Name, std::string Parameter, bool Passed, double Value)
Constructor.
Definition: JTest_t.hh:50
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object
JResultMessage()
Default constructor.
Definition: JTest_t.hh:86
std::vector< JTestResult > results
Definition: JTest_t.hh:251
virtual void save(TFile *f, std::string path, bool failures=false)=0
Writes the test result to root file.
Utility class to parse parameter values.
Definition: JProperties.hh:496
void setEndOfLine(const std::string &eol)
Set end of line characters.
Definition: JRoot.hh:19
JResultTitle()
Default constructor.
Definition: JTest_t.hh:29
std::string fileB
Definition: JTest_t.hh:225
std::string passed_h
Definition: JTest_t.hh:158
std::string passed_h
Definition: JTest_t.hh:231
std::string histogramA
Definition: JTest_t.hh:222
Utility class to parse parameter values.
Structure containing the result of the test.
Definition: JTest_t.hh:164
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
then JPizza f
Definition: JPizza.sh:46
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JTest_t.hh:80
double value
Definition: JTest_t.hh:155
std::ostream & separator(std::ostream &out)
Print separator.
virtual void clear()=0
Clear results.
std::string getMessage()
Returns a standard string to be used as title of a graphical root object.
Definition: JTest_t.hh:141
std::string message
Definition: JTest_t.hh:232
double value
Definition: JTest_t.hh:74
double threshold
Definition: JTest_t.hh:156
std::string testName
Definition: JTest_t.hh:221
do $DIR JTransitTime o
Definition: JTransitTime.sh:44
virtual std::ostream & write(std::ostream &out, std::string delimiter=" ", bool failures=false) const =0
Write test result to output.
std::string parameter
Definition: JTest_t.hh:154
std::string parameter
Definition: JTest_t.hh:72
std::string fileA
Definition: JTest_t.hh:224
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.
Definition: JTest_t.hh:67
std::string nameA
Definition: JTest_t.hh:152
std::string printASCII() const
Definition: JTest_t.hh:209
std::string parameterName
Definition: JTest_t.hh:226
std::string name
Definition: JTest_t.hh:71
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:246
std::string passed
Definition: JTest_t.hh:73
std::istream & read(std::istream &in)
Read test parameters from input.
Definition: JTest_t.hh:125
double parameterValue
Definition: JTest_t.hh:227
bool passed
Definition: JTest_t.hh:230
virtual std::istream & read(std::istream &in)=0
Read test parameters from input.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:40
TObject * obj
Definition: JTest_t.hh:229
JResultMessage(std::string testName, std::string nameA, std::string nameB, std::string parameter, double value, double threshold, bool passed)
Constructor.
Definition: JTest_t.hh:107
double parameterThreshold
Definition: JTest_t.hh:228
std::string print(std::string separator) const
Definition: JTest_t.hh:197
std::string histogramB
Definition: JTest_t.hh:223