|
[yoda-svn] r432 - in trunk: include/YODA include/YODA/Utils srcblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Dec 8 21:21:10 GMT 2011
Author: buckley Date: Thu Dec 8 21:21:10 2011 New Revision: 432 Log: Making more ND scatter stuff work Modified: trunk/include/YODA/ErrorND.h trunk/include/YODA/PointND.h trunk/include/YODA/Scatter2D.h trunk/include/YODA/Utils/ndarray.h trunk/include/YODA/Utils/sortedvector.h trunk/src/Scatter1D.cc Modified: trunk/include/YODA/ErrorND.h ============================================================================== --- trunk/include/YODA/ErrorND.h Thu Dec 8 18:59:26 2011 (r431) +++ trunk/include/YODA/ErrorND.h Thu Dec 8 21:21:10 2011 (r432) @@ -169,7 +169,8 @@ inline bool operator==(const Error<N>& a, const Error<N>& b) { if (a.name() != b.name()) return false; for (size_t i = 0; i < N; ++i) { - if ( !fuzzyEquals(a.err()[i], b.err()[i]) ) return false; + if (!fuzzyEquals(a.errMinus(i), b.errMinus(i))) return false; + if (!fuzzyEquals(a.errPlus(i), b.errPlus(i))) return false; } return true; } Modified: trunk/include/YODA/PointND.h ============================================================================== --- trunk/include/YODA/PointND.h Thu Dec 8 18:59:26 2011 (r431) +++ trunk/include/YODA/PointND.h Thu Dec 8 21:21:10 2011 (r432) @@ -43,19 +43,20 @@ { } - /// Constructor from values with a single set of symmetric errors - Point(const NdVal& pos, const NdVal& errs) - : _pos(pos) - { - _errs.push_back(Error<N>(errs)); - } + // /// Constructor from values with a single set of symmetric errors + // /// @todo Unnecessary since Error can be implicitly constructed this way + // Point(const NdVal& pos, const NdVal& errs) + // : _pos(pos) + // { + // _errs.insert(Error<N>(errs)); + // } /// Constructor from values with a single set of asymmetric errors Point(const NdVal& pos, const NdValPair& errs) : _pos(pos) { - _errs.push_back(Error<N>(errs)); + _errs.insert(Error<N>(errs)); } @@ -63,7 +64,7 @@ Point(const NdVal& pos, const Error<N>& err) : _pos(pos) { - _errs.push_back(err); + _errs.insert(err); } @@ -200,7 +201,7 @@ inline bool operator<(const Point<N>& a, const Point<N>& b) { #define LT_IF_NOT_EQ(a,b) { if (!fuzzyEquals(a, b)) return a < b; } for (size_t i = 0; i < N; ++i) LT_IF_NOT_EQ(a.pos()[i], b.pos()[i]); - LT_IF_NOT_EQ(a.errs().size(), b.errs().size()); + if (a.errs().size() != b.errs().size()) return a.errs().size() < b.errs().size(); for (size_t i = 0; i < a.errs().size(); ++i) { if (a.errs()[i] != b.errs()[i]) return a.errs()[i] < b.errs()[i]; } Modified: trunk/include/YODA/Scatter2D.h ============================================================================== --- trunk/include/YODA/Scatter2D.h Thu Dec 8 18:59:26 2011 (r431) +++ trunk/include/YODA/Scatter2D.h Thu Dec 8 21:21:10 2011 (r432) @@ -48,9 +48,6 @@ { } - /// @todo Add constructor from generic container/Range - - /// Constructor from a vector of values with no errors Scatter2D(const std::vector<double>& x, const std::vector<double>& y, const std::string& path="", const std::string& title="") Modified: trunk/include/YODA/Utils/ndarray.h ============================================================================== --- trunk/include/YODA/Utils/ndarray.h Thu Dec 8 18:59:26 2011 (r431) +++ trunk/include/YODA/Utils/ndarray.h Thu Dec 8 21:21:10 2011 (r432) @@ -30,7 +30,7 @@ msg << "Value vector of wrong size supplied to a " << N << " dimensional array"; throw RangeError(msg.str()); } - std::copy(vec, vec+N, _val); + for (size_t i = 0; i < N; ++i) _val[i] = vec[i]; } @@ -40,16 +40,16 @@ } - /// Conversion from C array - ndarray(const T arr[5]) { - try { - std::copy(arr, arr+N, _val); - } catch (...) { - std::stringstream msg; - msg << "Value vector of wrong size supplied to a " << N << " dimensional array"; - throw RangeError(msg.str()); - } - } + // /// Conversion from C array + // ndarray(const T arr[N]) { + // try { + // std::copy(arr, arr+N, _val); + // } catch (...) { + // std::stringstream msg; + // msg << "Value vector of wrong size supplied to a " << N << " dimensional array"; + // throw RangeError(msg.str()); + // } + // } //@} Modified: trunk/include/YODA/Utils/sortedvector.h ============================================================================== --- trunk/include/YODA/Utils/sortedvector.h Thu Dec 8 18:59:26 2011 (r431) +++ trunk/include/YODA/Utils/sortedvector.h Thu Dec 8 21:21:10 2011 (r432) @@ -10,29 +10,32 @@ namespace Utils { - /// @brief Specialisation of std::vector to allow indexed access to ordered elements + /// Specialisation of std::vector to allow indexed access to ordered elements + /// /// @todo Need to template on the value-comparison definition? template <typename T> class sortedvector : public std::vector<T> { public: - /// @brief default constructor + /// Default constructor sortedvector() {} - /// @brief conversion from std::vector - sortedvector(const std::vector<T> & vec) - : std::vector<T>(vec) { - std::sort(this->begin(), this->end()); + /// Conversion from std::vector + sortedvector(const std::vector<T> & vec) + : std::vector<T>(vec) { + std::sort(this->begin(), this->end()); } - /// @brief Insertion operator (push_back should not be used!) + /// Insertion operator (push_back should not be used!) void insert(const T& val) { std::vector<T>::push_back(val); std::sort(this->begin(), this->end()); } + private: - /// @brief hiding push_back from the base class + + /// Hiding push_back from the base class void push_back(); }; Modified: trunk/src/Scatter1D.cc ============================================================================== --- trunk/src/Scatter1D.cc Thu Dec 8 18:59:26 2011 (r431) +++ trunk/src/Scatter1D.cc Thu Dec 8 21:21:10 2011 (r432) @@ -3,8 +3,38 @@ namespace YODA { + /// A collection of 1D data points with errors + class Scatter1D : public Scatter<1> { + public: + + typedef Utils::sortedvector< Point<1> > Points; + + + /// @name Constructors + //@{ + + /// Empty constructor + Scatter1D(const std::string& path="", const std::string& title="") + : Scatter<1>(path, title) + { } + + + /// Constructor from a set of points + Scatter1D(const Points& points, + const std::string& path="", const std::string& title="") + : Scatter<1>(points, path, title) + { } + + }; + + void test() { Scatter<2> s2; + Utils::ndarray<double,2> bar({1,2}); + Point<2> p1(bar); + Point<2> p2({{3,4}}, bar); + s2.addPoint(p1); + s2.addPoint(p2); }
More information about the yoda-svn mailing list |