Jpp  18.3.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 #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 
24 namespace JCOMPAREHISTOGRAMS {}
25 namespace JPP { using namespace JCOMPAREHISTOGRAMS; }
26 
27 namespace 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  */
52  const std::string& resultType) :
53  testName (testName),
54  resultType(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
Interface to read input and write output for TObject tests.
Definition: JTest_t.hh:40
o $QUALITY_ROOT d $DEBUG!CHECK_EXIT_CODE JPlot1D f
Definition: JDataQuality.sh:76
Definition: JRoot.hh:19
virtual void test(const TObject *o1, const TObject *o2)=0
Tests compatibility between two TObjects.
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
data_type r[M+1]
Definition: JPolint.hh:868
JTest_t(const std::string &testName, const std::string &resultType)
Constructor.
Definition: JTest_t.hh:51
Utility class to parse parameter values.
virtual std::istream & read(std::istream &in)=0
Read test parameters from input.
friend std::ostream & operator<<(std::ostream &out, const JTest_t &test)
Write test result to output.
Definition: JTest_t.hh:172
I/O formatting auxiliaries.
then awk string
const std::string resultType
test result type
Definition: JTest_t.hh:181
$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:180
print
Definition: JConvertDusj.sh:44
const std::string & getTestName() const
Get test name.
Definition: JTest_t.hh:135
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
friend std::istream & operator>>(std::istream &in, JTest_t &test)
Read test parameters from input.
Definition: JTest_t.hh:159
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:48
const std::string & getResultType() const
Get result type.
Definition: JTest_t.hh:146