Jpp  18.2.0-rc.1
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 __JCOMPAREHISTOGRAMS__JTEST_T__
2 #define __JCOMPAREHISTOGRAMS__JTEST_T__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "Jeep/JPrint.hh"
8 #include "Jeep/JProperties.hh"
9 
10 #include "JLang/JColorFacet.hh"
11 
12 #include "JGizmo/JRootObjectID.hh"
13 
15 
16 #include <TROOT.h>
17 #include <TObject.h>
18 #include <TFile.h>
19 #include <TH1.h>
20 #include <TH2.h>
21 #include <TH3.h>
22 
23 
24 /**
25  * \author rgruiz, bjung
26  */
27 
28 namespace JCOMPAREHISTOGRAMS {}
29 namespace JPP { using namespace JCOMPAREHISTOGRAMS; }
30 
31 namespace JCOMPAREHISTOGRAMS {
32 
33  using JGIZMO::JRootObjectID;
34 
35  /**
36  * Interface to read input and write output for TObject tests.\n
37  * This is an abstract class from which the different tests are derived.\n
38  * All tests have in common the methods from this interface.\n
39  * For each test, the parameters are passed through an istream, and parsed by the read() method.\n
40  * For each test, the different results are stored in the results buffer.\n
41  * The write() method is used to print a message with the result of the test.\n
42  * The save() method is used to save a graphical output with the test results into a .root file.\n
43  * The clear() method clears the results buffer.
44  * For a list of available tests see JTestDictionary()
45  */
46  class JTest_t
47  {
48  public:
49 
50 
51  /**
52  * Constructor.
53  *
54  * \param name test name
55  * \param type result type
56  */
58  const std::string& type) :
59  testName (name),
60  resultType(type)
61  {}
62 
63 
64  /**
65  * Read test parameters from input.
66  *
67  * \param in input stream
68  * \return input stream
69  */
70  virtual std::istream& read (std::istream& in) = 0;
71 
72 
73  /**
74  * Write test result to output.
75  *
76  * \param out output stream
77  * \param delimiter field delimiter
78  * \param onlyFailures if true, write only failures.
79  * \return output stream
80  */
81  inline std::ostream& write(std::ostream& out,
82  const char delimiter = ' ',
83  const bool onlyFailures = false) const {
84 
85  for (std::vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
86 
87  if (onlyFailures && r->passed) {
88  continue;
89  }
90 
91  print(out, *r, delimiter, true);
92  }
93 
94  return out;
95  }
96 
97 
98  /**
99  * Tests compatibility between two TObjects.
100  *
101  * \param o1 First object
102  * \param o2 Second object
103  */
104  virtual void test(TObject* o1, TObject* o2) = 0;
105 
106 
107  /**
108  * Writes the test result to root file
109  * \param f A ROOT file
110  * \param path Path in root file.
111  * \param onlyFailures If true, write only failures.
112  */
113  virtual void save(TFile* f ,
114  const std::string& path,
115  const bool onlyFailures = false) {
116 
117  using namespace std;
118 
119  if (f -> GetDirectory(path.c_str())==0) {
120  f->mkdir(path.c_str());
121  }
122 
123  f->cd(path.c_str());
124 
125  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
126 
127  if (!onlyFailures || !r->passed){
128  r->obj->Write();
129  }
130  }
131  }
132 
133 
134  /**
135  * Clear results
136  */
137  virtual void clear() {
138  results.clear();
139  }
140 
141 
142  /**
143  * Get test name.
144  *
145  * \return test name
146  */
148  return testName;
149  }
150 
151 
152  /**
153  * Get result type.
154  *
155  * \return result type
156  */
158  return resultType;
159  }
160 
161 
162  std::vector<JTestResult> results; //!< Buffer to store results of multiple tests.*/
163 
164  protected:
165 
166  const std::string testName; //!< test name
167  const std::string resultType; //!< result type
168  };
169 }
170 
171 #endif
const std::string & getTestName()
Get test name.
Definition: JTest_t.hh:147
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:46
virtual void test(TObject *o1, TObject *o2)=0
Tests compatibility between two TObjects.
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
o $QUALITY_ROOT d $DEBUG!CHECK_EXIT_CODE JPlot1D f
Definition: JDataQuality.sh:76
Definition: JRoot.hh:19
Auxiliary class to handle file name, ROOT directory and object name.
data_type r[M+1]
Definition: JPolint.hh:779
Utility class to parse parameter values.
std::vector< JTestResult > results
Buffer to store results of multiple tests.*/.
Definition: JTest_t.hh:162
std::ostream & write(std::ostream &out, const char delimiter= ' ', const bool onlyFailures=false) const
Write test result to output.
Definition: JTest_t.hh:81
virtual std::istream & read(std::istream &in)=0
Read test parameters from input.
I/O formatting auxiliaries.
then awk string
const std::string & getResultType()
Get result type.
Definition: JTest_t.hh:157
const std::string resultType
result type
Definition: JTest_t.hh:167
$WORKDIR driver txt done cat $WORKDIR driver txt<< EOFprocess ${DATAFILTER}$FILTER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataFilter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAFILTER}-P $PORT</dev/null > &/dev/null &))';process ${DATAWRITER}$WRITER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataWriter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAWRITER}</dev/null > &/dev/null &))';print enterevent ev_init{RC_CMD}event ev_reset{RC_CMD}event ev_init{RC_CMD}event ev_configure{RC_DFLTR%<$WORKDIR/ev_configure_datafilter.txt > RC_DQSIM<$WORKDIR/ev_configure_dqsimulator.txt > RC_DWRT path
const std::string testName
test name
Definition: JTest_t.hh:166
print
Definition: JConvertDusj.sh:44
virtual void save(TFile *f, const std::string &path, const bool onlyFailures=false)
Writes the test result to root file.
Definition: JTest_t.hh:113
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
virtual void clear()
Clear results.
Definition: JTest_t.hh:137
JTest_t(const std::string &name, const std::string &type)
Constructor.
Definition: JTest_t.hh:57