#ifndef __JCOMPAREHISTOGRAMS__JTEST_T__ #define __JCOMPAREHISTOGRAMS__JTEST_T__ #include #include #include "Jeep/JPrint.hh" #include "Jeep/JProperties.hh" #include "JLang/JColorFacet.hh" #include "JGizmo/JRootObjectID.hh" #include "JCompareHistograms/JTestResult.hh" #include #include #include #include #include #include /** * \author rgruiz, bjung */ namespace JCOMPAREHISTOGRAMS {} namespace JPP { using namespace JCOMPAREHISTOGRAMS; } namespace JCOMPAREHISTOGRAMS { using JGIZMO::JRootObjectID; /** * Interface to read input and write output for TObject tests.\n * This is an abstract class from which the different tests are derived.\n * All tests have in common the methods from this interface.\n * For each test, the parameters are passed through an istream, and parsed by the read() method.\n * For each test, the different results are stored in the results buffer.\n * The write() method is used to print a message with the result of the test.\n * The save() method is used to save a graphical output with the test results into a .root file.\n * The clear() method clears the results buffer. * For a list of available tests see JTestDictionary() */ class JTest_t { public: /** * Constructor. * * \param name test name * \param type result type */ JTest_t(const std::string& name, const std::string& type) : testName (name), resultType(type) {} /** * Read test parameters from input. * * \param in input stream * \return input stream */ virtual std::istream& read (std::istream& in) = 0; /** * Write test result to output. * * \param out output stream * \param delimiter field delimiter * \param onlyFailures if true, write only failures. * \return output stream */ inline std::ostream& write(std::ostream& out, const char delimiter = ' ', const bool onlyFailures = false) const { for (std::vector::const_iterator r = results.begin() ; r != results.end() ; ++r) { if (onlyFailures && r->passed) { continue; } print(out, *r, delimiter, true); } return out; } /** * Tests compatibility between two TObjects. * * \param o1 First object * \param o2 Second object */ virtual void test(TObject* o1, TObject* o2) = 0; /** * Writes the test result to root file * \param f A ROOT file * \param path Path in root file. * \param onlyFailures If true, write only failures. */ virtual void save(TFile* f , const std::string& path, const bool onlyFailures = false) { using namespace std; if (f -> GetDirectory(path.c_str())==0) { f->mkdir(path.c_str()); } f->cd(path.c_str()); for (vector::const_iterator r = results.begin() ; r != results.end() ; ++r){ if (!onlyFailures || !r->passed){ r->obj->Write(); } } } /** * Clear results */ virtual void clear() { results.clear(); } /** * Get test name. * * \return test name */ const std::string& getTestName() { return testName; } /** * Get result type. * * \return result type */ const std::string& getResultType() { return resultType; } std::vector results; //!< Buffer to store results of multiple tests.*/ protected: const std::string testName; //!< test name const std::string resultType; //!< result type }; } #endif