From 92320a17176846d70b02841a9054e841efd0b2c2 Mon Sep 17 00:00:00 2001 From: Lorenzo Moneta <Lorenzo.Moneta@cern.ch> Date: Fri, 25 Jun 2010 13:02:47 +0000 Subject: [PATCH] from bartolomeu: fix a compilation error on Windows + some code cleanup git-svn-id: http://root.cern.ch/svn/root/trunk@34132 27541ba8-7e3a-0410-8455-c3a389f83636 --- math/mathcore/inc/Math/GoFTest.h | 36 ++----- math/mathcore/src/GoFTest.cxx | 150 ++++++++++----------------- math/mathcore/test/stressGoFTest.cxx | 2 +- 3 files changed, 59 insertions(+), 129 deletions(-) diff --git a/math/mathcore/inc/Math/GoFTest.h b/math/mathcore/inc/Math/GoFTest.h index d79ea05ba40..5adac5a7aa7 100644 --- a/math/mathcore/inc/Math/GoFTest.h +++ b/math/mathcore/inc/Math/GoFTest.h @@ -11,9 +11,6 @@ #ifndef ROOT_Math_GoFTest #define ROOT_Math_GoFTest -#if !defined(__CINT__) && !defined(__MAKECINT__) -#include <stdexcept> -#endif #ifndef ROOT_Math_WrappedFunction @@ -34,7 +31,7 @@ namespace Math { class GoFTest { public: - enum EDistribution { // H0 distributions for using only with 2-samples tests + enum EDistribution { // H0 distributions for using only with 2-samples tests kUserDefined = -1, // Internal use only for the class's template constructor kGaussian, // Default value kLogNormal, @@ -42,35 +39,17 @@ public: }; enum ETestType { // Goodness of Fit test types for using with the class's unary funtion as a shorthand for the in-built methods - kAD, // Anderson-Darling Test. Default value + kAD, // Anderson-Darling Test. Default value kAD2s, // Anderson-Darling 2-Samples Test kKS, // Kolmogorov-Smirnov Test - kKS2s // Kolmogorov-Smirnov 2-Samples Test - }; - -#if !defined(__CINT__) && !defined(__MAKECINT__) - struct BadSampleArgument : public std::invalid_argument { - BadSampleArgument(std::string type); - }; - - struct DegenerateSamples : public std::domain_error { - DegenerateSamples(std::string type); + kKS2s // Kolmogorov-Smirnov 2-Samples Test }; -#endif - + /* Constructor for using only with 2-samples tests */ - GoFTest(const Double_t* sample1, UInt_t sample1Size, const Double_t* sample2, UInt_t sample2Size) -#if !defined(__CINT__) && !defined(__MAKECINT__) - throw(BadSampleArgument, std::bad_exception) -#endif - ; + GoFTest(const Double_t* sample1, UInt_t sample1Size, const Double_t* sample2, UInt_t sample2Size); /* Constructor for using only with 1-sample tests with a specified distribution */ - GoFTest(const Double_t* sample, UInt_t sampleSize, EDistribution dist = kGaussian) -#if !defined(__CINT__) && !defined(__MAKECINT__) - throw(BadSampleArgument, std::bad_exception) -#endif - ; + GoFTest(const Double_t* sample, UInt_t sampleSize, EDistribution dist = kGaussian); /* Templated constructor for using only with 1-sample tests with a user specified distribution */ template<class Dist> @@ -148,9 +127,6 @@ private: void SetCDF(CDF_Ptr cdf = 0); void Instantiate(const Double_t* sample, UInt_t sampleSize) -#if !defined(__CINT__) && !defined(__MAKECINT__) - throw(BadSampleArgument, std::bad_exception) -#endif ; Double_t ComputeIntegral(Double_t* parms) const; // Computation of the integral term of the 1-Sample Anderson-Darling test statistic's asymtotic distribution as described in (2) diff --git a/math/mathcore/src/GoFTest.cxx b/math/mathcore/src/GoFTest.cxx index 39440be1a33..cd8c6a280b2 100644 --- a/math/mathcore/src/GoFTest.cxx +++ b/math/mathcore/src/GoFTest.cxx @@ -15,7 +15,9 @@ #include <map> #include <numeric> #include <string.h> +#include <cassert> +#include "Math/Error.h" #include "Math/Integrator.h" #include "Math/ProbFuncMathCore.h" @@ -27,80 +29,46 @@ namespace ROOT { namespace Math { -#if !defined(__CINT__) && !defined(__MAKECINT__) -GoFTest::BadSampleArgument::BadSampleArgument(std::string type) : std::invalid_argument(type + " cannot be zero or zero-length!") {} - -GoFTest::DegenerateSamples::DegenerateSamples(std::string type) : std::domain_error(type + " Sampling values all identical.") {} -#else -#include <cassert> -#endif - GoFTest::GoFTest(const Double_t* sample1, UInt_t sample1Size, const Double_t* sample2, UInt_t sample2Size) -#if !defined(__CINT__) && !defined(__MAKECINT__) - throw(BadSampleArgument, std::bad_exception) try -#endif - : fCDF(0), fSamples(std::vector<std::vector<Double_t> >(2)), fTestSampleFromH0(kFALSE) - { -#if !defined(__CINT__) && !defined(__MAKECINT__) - if (sample1 == 0 || sample1Size == 0) { - std::string msg = "'sample1"; - msg += !sample1Size ? "Size'" : "'"; - throw BadSampleArgument(msg); - } else if (sample2 == 0 || sample2Size == 0) { - std::string msg = "'sample2"; - msg += !sample2Size ? "Size'" : "'"; - throw BadSampleArgument(msg); - } -#else - assert(sample2 != 0 && sample2Size != 0); - assert(sample2 != 0 && sample2Size != 0); -#endif - std::vector<const Double_t*> samples(2); - std::vector<UInt_t> samplesSizes(2); - samples[0] = sample1; - samples[1] = sample2; - samplesSizes[0] = sample1Size; - samplesSizes[1] = sample2Size; - SetSamples(samples, samplesSizes); - SetParameters(); -#if !defined(__CINT__) && !defined(__MAKECINT__) - } catch (const BadSampleArgument& bsa) { - delete fCDF; - throw; - } catch (const std::bad_exception& be) { - delete fCDF; - throw; -#endif + : fCDF(0), fSamples(std::vector<std::vector<Double_t> >(2)), fTestSampleFromH0(kFALSE) { + Bool_t badSampleArg = sample1 == 0 || sample1Size == 0; + if (badSampleArg) { + std::string msg = "'sample1"; + msg += !sample1Size ? "Size' cannot be zero" : "' cannot be zero-length"; + MATH_ERROR_MSG("GoFTest::GoFTest", msg.c_str()); + assert(!badSampleArg); + } + badSampleArg = sample2 == 0 || sample2Size == 0; + if (badSampleArg) { + std::string msg = "'sample2"; + msg += !sample2Size ? "Size' cannot be zero" : "' cannot be zero-length"; + MATH_ERROR_MSG("GoFTest::GoFTest", msg.c_str()); + assert(!badSampleArg); + } + std::vector<const Double_t*> samples(2); + std::vector<UInt_t> samplesSizes(2); + samples[0] = sample1; + samples[1] = sample2; + samplesSizes[0] = sample1Size; + samplesSizes[1] = sample2Size; + SetSamples(samples, samplesSizes); + SetParameters(); } - GoFTest::GoFTest(const Double_t* sample, UInt_t sampleSize, EDistribution dist) -#if !defined(__CINT__) && !defined(__MAKECINT__) - throw(BadSampleArgument, std::bad_exception) try -#endif - : fCDF(0), fDist(dist), fSamples(std::vector<std::vector<Double_t> >(1)), fTestSampleFromH0(kTRUE) - { -#if !defined(__CINT__) && !defined(__MAKECINT__) - if (sample == 0 || sampleSize == 0) { - std::string msg = "'sample"; - msg += !sampleSize ? "Size'" : "'"; - throw BadSampleArgument(msg); - } -#else - assert(sample != 0 && sampleSize != 0); -#endif - std::vector<const Double_t*> samples(1, sample); - std::vector<UInt_t> samplesSizes(1, sampleSize); - SetSamples(samples, samplesSizes); - SetParameters(); - SetCDF(); -#if !defined(__CINT__) && !defined(__MAKECINT__) - } catch (const BadSampleArgument& bsa) { - delete fCDF; - throw; - } catch (const std::bad_exception& be) { - delete fCDF; - throw; -#endif + GoFTest::GoFTest(const Double_t* sample, UInt_t sampleSize, EDistribution dist) + : fCDF(0), fDist(dist), fSamples(std::vector<std::vector<Double_t> >(1)), fTestSampleFromH0(kTRUE) { + Bool_t badSampleArg = sample == 0 || sampleSize == 0; + if (badSampleArg) { + std::string msg = "'sample"; + msg += !sampleSize ? "Size' cannot be zero" : "' cannot be zero-length"; + MATH_ERROR_MSG("GoFTest::GoFTest", msg.c_str()); + assert(!badSampleArg); + } + std::vector<const Double_t*> samples(1, sample); + std::vector<UInt_t> samplesSizes(1, sampleSize); + SetSamples(samples, samplesSizes); + SetParameters(); + SetCDF(); } GoFTest::~GoFTest() { @@ -117,17 +85,17 @@ GoFTest::DegenerateSamples::DegenerateSamples(std::string type) : std::domain_er fCombinedSamples[combinedSamplesSize + j] = samples[i][j]; } combinedSamplesSize += samplesSizes[i]; - } + } std::sort(fCombinedSamples.begin(), fCombinedSamples.end()); -#if !defined(__CINT__) && !defined(__MAKECINT__) - if (*fCombinedSamples.begin() == *(fCombinedSamples.end() - 1)) { + + Bool_t degenerateSamples = *(fCombinedSamples.begin()) == *(fCombinedSamples.end() - 1); + if (degenerateSamples) { std::string msg = "Degenerate sample"; msg += samplesSizes.size() > 1 ? "s!" : "!"; - throw DegenerateSamples(msg); + msg += " Sampling values all identical."; + MATH_ERROR_MSG("GoFTest::SetSamples", msg.c_str()); + assert(!degenerateSamples); } -#else - assert(*fCombinedSamples.begin() != *(--fCombinedSamples.end())); -#endif } void GoFTest::SetParameters() { @@ -170,33 +138,19 @@ GoFTest::DegenerateSamples::DegenerateSamples(std::string type) : std::domain_er } } - void GoFTest::Instantiate(const Double_t* sample, UInt_t sampleSize) -#if !defined(__CINT__) && !defined(__MAKECINT__) - throw(BadSampleArgument, std::bad_exception) try -#endif - { -#if ! defined(__CINT__) && !defined(__MAKECINT__) - if (sample == 0 || sampleSize == 0) { + void GoFTest::Instantiate(const Double_t* sample, UInt_t sampleSize) { + Bool_t badSampleArg = sample == 0 || sampleSize == 0; + if (badSampleArg) { std::string msg = "'sample"; - msg += !sampleSize ? "Size'" : "'"; - throw BadSampleArgument(msg); + msg += !sampleSize ? "Size' cannot be zero" : "' cannot be zero-length"; + MATH_ERROR_MSG("GoFTest::GoFTest", msg.c_str()); + assert(!badSampleArg); } -#else - assert(sample != 0 && sampleSize != 0); -#endif fCDF = 0; fDist = kUserDefined; fSamples = std::vector<std::vector<Double_t> >(1); fTestSampleFromH0 = kTRUE; SetSamples(std::vector<const Double_t*>(1, sample), std::vector<UInt_t>(1, sampleSize)); -#if ! defined(__CINT__) && !defined(__MAKECINT__) - } catch (const BadSampleArgument& bsa) { - delete fCDF; - throw; - } catch (const std::bad_exception& be) { - delete fCDF; - throw; -#endif } Double_t GoFTest::ComputeIntegral(Double_t* parms) const { diff --git a/math/mathcore/test/stressGoFTest.cxx b/math/mathcore/test/stressGoFTest.cxx index 2b62faa5b28..a6353f010fa 100644 --- a/math/mathcore/test/stressGoFTest.cxx +++ b/math/mathcore/test/stressGoFTest.cxx @@ -443,7 +443,7 @@ Int_t RunTests(Int_t argc, Char_t* argv[]) { return result; } -Int_t GoFTestStress(Int_t argc = 1 , Char_t* argv[] = 0) { +Int_t stressGoFTest(Int_t argc = 1 , Char_t* argv[] = 0) { return RunTests(argc, argv); } -- GitLab