|
[yoda-svn] r504 - in trunk: . include/YODA pyext/yoda pyext/yoda/includeblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Jul 19 00:46:05 BST 2012
Author: buckley Date: Thu Jul 19 00:46:04 2012 New Revision: 504 Log: Adding more Cython mappings for Point3D and WriterYODA, and removing mixed symm/asymm constructors for Point/Scatter2D Added: trunk/pyext/yoda/include/20-Point3D.pyx trunk/pyext/yoda/include/30-Writer.pyx trunk/pyext/yoda/include/40-WriterYODA.pyx Modified: trunk/ChangeLog trunk/include/YODA/Point2D.h trunk/include/YODA/Point3D.h trunk/include/YODA/Scatter2D.h trunk/pyext/yoda/Makefile.am trunk/pyext/yoda/include/20-Point2D.pyx trunk/pyext/yoda/include/30-Reader.pyx trunk/pyext/yoda/include/30-Scatter2D.pyx trunk/pyext/yoda/include/40-Histo2D.pyx trunk/pyext/yoda/shims.h Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Thu Jul 12 22:12:10 2012 (r503) +++ trunk/ChangeLog Thu Jul 19 00:46:04 2012 (r504) @@ -1,3 +1,9 @@ +2012-07-19 Andy Buckley <andy.buckley at cern.ch> + + * Cython mapping improvements & additions for Point3D + Scatter3D. + + * Removing mixed symm/asymm constructors on Point*D & Scatter*D classes. + 2012-07-12 Andy Buckley <andy.buckley at cern.ch> * Reintroducing Profile2D and Scatter3D. Modified: trunk/include/YODA/Point2D.h ============================================================================== --- trunk/include/YODA/Point2D.h Thu Jul 12 22:12:10 2012 (r503) +++ trunk/include/YODA/Point2D.h Thu Jul 19 00:46:04 2012 (r504) @@ -49,20 +49,20 @@ } - /// Constructor from values with symmetric errors on x and asymmetric errors on y - Point2D(double x, double y, double ex, const std::pair<double,double>& ey) - : _x(x), _y(y), _ey(ey) - { - _ex = std::make_pair(ex, ex); - } + // /// Constructor from values with symmetric errors on x and asymmetric errors on y + // Point2D(double x, double y, double ex, const std::pair<double,double>& ey) + // : _x(x), _y(y), _ey(ey) + // { + // _ex = std::make_pair(ex, ex); + // } - /// Constructor from values with asymmetric errors on x and symmetric errors on y - Point2D(double x, double y, const std::pair<double,double>& ex, double ey) - : _x(x), _y(y), _ex(ex) - { - _ey = std::make_pair(ey, ey); - } + // /// Constructor from values with asymmetric errors on x and symmetric errors on y + // Point2D(double x, double y, const std::pair<double,double>& ex, double ey) + // : _x(x), _y(y), _ex(ex) + // { + // _ey = std::make_pair(ey, ey); + // } /// Constructor from values with asymmetric errors on both x and y @@ -73,7 +73,8 @@ /// Copy constructor Point2D(const Point2D& p) - : _x(p._x), _y(p._y), _ex(p._ex), _ey(p._ey) + : _x(p._x), _y(p._y), + _ex(p._ex), _ey(p._ey) { } @@ -258,12 +259,12 @@ } /// Equality test of x characteristics only - inline bool operator!=(const YODA::Point2D& a, const YODA::Point2D& b) { + inline bool operator != (const YODA::Point2D& a, const YODA::Point2D& b) { return !(a == b); } /// Less-than operator used to sort bins by x-ordering - inline bool operator<(const YODA::Point2D& a, const YODA::Point2D& b) { + inline bool operator < (const YODA::Point2D& a, const YODA::Point2D& b) { if (!YODA::fuzzyEquals(a.x(), b.x())) { return a.x() < b.x(); } @@ -277,18 +278,18 @@ } /// Less-than-or-equals operator used to sort bins by x-ordering - inline bool operator<=(const YODA::Point2D& a, const YODA::Point2D& b) { + inline bool operator <= (const YODA::Point2D& a, const YODA::Point2D& b) { if (a == b) return true; return a < b; } /// Greater-than operator used to sort bins by x-ordering - inline bool operator>(const YODA::Point2D& a, const YODA::Point2D& b) { + inline bool operator > (const YODA::Point2D& a, const YODA::Point2D& b) { return !(a <= b); } /// Greater-than-or-equals operator used to sort bins by x-ordering - inline bool operator>=(const YODA::Point2D& a, const YODA::Point2D& b) { + inline bool operator >= (const YODA::Point2D& a, const YODA::Point2D& b) { return !(a < b); } Modified: trunk/include/YODA/Point3D.h ============================================================================== --- trunk/include/YODA/Point3D.h Thu Jul 12 22:12:10 2012 (r503) +++ trunk/include/YODA/Point3D.h Thu Jul 19 00:46:04 2012 (r504) @@ -59,25 +59,30 @@ const std::pair<double,double>& ex, const std::pair<double,double>& ey, const std::pair<double,double>& ez) - : _x(x), _y(y), _z(z) - { - _ex = ex; - _ey = ey; - _ez = ez; - } + : _x(x), _y(y), _z(z), + _ex(ex), _ey(ey), _ez(ez) + { } + + + /// @brief Copy constructor + Point3D(const Point3D& p) + : _x(p._x), _y(p._y), _z(p._z), + _ex(p._ex), _ey(p._ey), _ez(p._ez) + { } - /// @brief A copy constructor - Point3D(const Point3D& p) { + /// Copy assignment + Point3D& operator = (const Point3D& p) { _x = p._x; _y = p._y; _z = p._z; - _ex = p._ex; _ey = p._ey; _ez = p._ez; + return *this; } + //@} @@ -315,46 +320,46 @@ } /// Inequality operator - inline bool operator!=(const Point3D& a, const YODA::Point3D& b) { + inline bool operator != (const Point3D& a, const YODA::Point3D& b) { return !(a == b); } /// Less-than operator used to sort bins by x-first ordering - inline bool operator<(const Point3D& a, const YODA::Point3D& b) { + inline bool operator < (const Point3D& a, const YODA::Point3D& b) { if (! fuzzyEquals(a.x(), b.x())) { return a.x() < b.x(); } - if(!fuzzyEquals(a.y(), b.y())) { + if (!fuzzyEquals(a.y(), b.y())) { return a.y() < b.y(); } if (! fuzzyEquals(a.xErrMinus(), b.xErrMinus())) { return a.xErrMinus() < b.xErrMinus(); } - if(!fuzzyEquals(a.yErrMinus(), b.yErrMinus())) { + if (!fuzzyEquals(a.yErrMinus(), b.yErrMinus())) { return a.yErrMinus() < b.yErrMinus(); } if (! fuzzyEquals(a.xErrPlus(), b.xErrPlus())) { return a.xErrPlus() < b.xErrPlus(); } - if(!fuzzyEquals(a.yErrPlus(), b.yErrPlus())) { + if (!fuzzyEquals(a.yErrPlus(), b.yErrPlus())) { return a.yErrPlus() < b.yErrPlus(); } return false; } /// Less-than-or-equals operator - inline bool operator<=(const Point3D& a, const YODA::Point3D& b) { + inline bool operator <= (const Point3D& a, const YODA::Point3D& b) { if (a == b) return true; return a < b; } /// Greater-than operator - inline bool operator>(const Point3D& a, const YODA::Point3D& b) { + inline bool operator > (const Point3D& a, const YODA::Point3D& b) { return !(a <= b); } /// Greater-than-or-equals operator - inline bool operator>=(const Point3D& a, const YODA::Point3D& b) { + inline bool operator >= (const Point3D& a, const YODA::Point3D& b) { return !(a < b); } Modified: trunk/include/YODA/Scatter2D.h ============================================================================== --- trunk/include/YODA/Scatter2D.h Thu Jul 12 22:12:10 2012 (r503) +++ trunk/include/YODA/Scatter2D.h Thu Jul 19 00:46:04 2012 (r504) @@ -73,30 +73,30 @@ } - /// Constructor from values with symmetric errors on x and asymmetric errors on y - Scatter2D(const std::vector<double>& x, const std::vector<double>& y, - const std::vector<double>& ex, const std::vector<std::pair<double,double> >& ey, - const std::string& path="", const std::string& title="") - : AnalysisObject("Scatter2D", path, title) - { - assert(x.size() == y.size() && x.size() == ex.size() && x.size() == ey.size()); - for (size_t i = 0; i < x.size(); ++i) { - addPoint(Point2D(x[i], y[i], ex[i], ey[i])); - } - } - - - /// Constructor from values with asymmetric errors on x and symmetric errors on y - Scatter2D(const std::vector<double>& x, const std::vector<double>& y, - const std::vector<std::pair<double,double> >& ex, const std::vector<double>& ey, - const std::string& path="", const std::string& title="") - : AnalysisObject("Scatter2D", path, title) - { - assert(x.size() == y.size() && x.size() == ex.size() && x.size() == ey.size()); - for (size_t i = 0; i < x.size(); ++i) { - addPoint(Point2D(x[i], y[i], ex[i], ey[i])); - } - } + // /// Constructor from values with symmetric errors on x and asymmetric errors on y + // Scatter2D(const std::vector<double>& x, const std::vector<double>& y, + // const std::vector<double>& ex, const std::vector<std::pair<double,double> >& ey, + // const std::string& path="", const std::string& title="") + // : AnalysisObject("Scatter2D", path, title) + // { + // assert(x.size() == y.size() && x.size() == ex.size() && x.size() == ey.size()); + // for (size_t i = 0; i < x.size(); ++i) { + // addPoint(Point2D(x[i], y[i], ex[i], ey[i])); + // } + // } + + + // /// Constructor from values with asymmetric errors on x and symmetric errors on y + // Scatter2D(const std::vector<double>& x, const std::vector<double>& y, + // const std::vector<std::pair<double,double> >& ex, const std::vector<double>& ey, + // const std::string& path="", const std::string& title="") + // : AnalysisObject("Scatter2D", path, title) + // { + // assert(x.size() == y.size() && x.size() == ex.size() && x.size() == ey.size()); + // for (size_t i = 0; i < x.size(); ++i) { + // addPoint(Point2D(x[i], y[i], ex[i], ey[i])); + // } + // } /// Constructor from values with asymmetric errors on both x and y @@ -221,17 +221,17 @@ return *this; } - /// Insert a new point, defined as the x/y value pair and mixed errors - Scatter2D& addPoint(double x, double y, std::pair<double,double> ex, double ey) { - _points.insert(Point2D(x, y, ex, ey)); - return *this; - } - - /// Insert a new point, defined as the x/y value pair and mixed errors - Scatter2D& addPoint(double x, double y, double ex, std::pair<double,double> ey) { - _points.insert(Point2D(x, y, ex, ey)); - return *this; - } + // /// Insert a new point, defined as the x/y value pair and mixed errors + // Scatter2D& addPoint(double x, double y, std::pair<double,double> ex, double ey) { + // _points.insert(Point2D(x, y, ex, ey)); + // return *this; + // } + + // /// Insert a new point, defined as the x/y value pair and mixed errors + // Scatter2D& addPoint(double x, double y, double ex, std::pair<double,double> ey) { + // _points.insert(Point2D(x, y, ex, ey)); + // return *this; + // } /// Insert a new point, defined as the x/y value pair and asymmetric errors Scatter2D& addPoint(double x, double y, std::pair<double,double> ex, std::pair<double,double> ey) { Modified: trunk/pyext/yoda/Makefile.am ============================================================================== --- trunk/pyext/yoda/Makefile.am Thu Jul 12 22:12:10 2012 (r503) +++ trunk/pyext/yoda/Makefile.am Thu Jul 19 00:46:04 2012 (r504) @@ -5,14 +5,17 @@ $(PYTHON) -m cython --cplus yoda.pyx yoda.pyx: include/00-imports.pyx include/10-AnalysisObject.pyx \ - include/20-Dbn1D.pyx include/20-Dbn2D.pyx include/20-Point2D.pyx \ - include/30-HistoBin1D.pyx include/30-ProfileBin1D.pyx include/30-HistoBin2D.pyx include/30-Reader.pyx include/30-Scatter2D.pyx \ - include/40-Histo1D.pyx include/40-Profile1D.pyx include/40-WriterAIDA.pyx \ - include/99-ReaderAIDA.pyx include/99-ReaderYODA.pyx + include/20-Dbn1D.pyx include/20-Dbn2D.pyx include/20-Point2D.pyx include/20-Point3D.pyx \ + include/30-HistoBin1D.pyx include/30-ProfileBin1D.pyx include/30-HistoBin2D.pyx \ + include/30-Reader.pyx \ + include/30-Scatter2D.pyx \ + include/40-Histo1D.pyx include/40-Profile1D.pyx \ + include/40-Histo2D.pyx \ + include/40-WriterYODA.pyx include/40-WriterAIDA.pyx \ + include/99-ReaderYODA.pyx include/99-ReaderAIDA.pyx cat $+ > yoda.pyx - -##include/40-Histo2D.pyx - +#include/30-Scatter3D.pyx +#include/40-Profile2D.pyx clean-local: rm yoda.cpp yoda.pyx Modified: trunk/pyext/yoda/include/20-Point2D.pyx ============================================================================== --- trunk/pyext/yoda/include/20-Point2D.pyx Thu Jul 12 22:12:10 2012 (r503) +++ trunk/pyext/yoda/include/20-Point2D.pyx Thu Jul 19 00:46:04 2012 (r504) @@ -18,6 +18,7 @@ void setXErr(double minus, double plus) void setYErr(double minus, double plus) + cdef class Point2D: cdef cPoint2D* thisptr @@ -37,13 +38,13 @@ def __cinit__(self): self._dealloc = False - def __init__(self, *args): + def __init__(self, *args): self.setptr(new cPoint2D(), True) self._dealloc = True if len(args) == 0: self.pos = 0, 0 - elif len(args) == 2 : + elif len(args) == 2: self.pos = args elif len(args) == 4: self.pos = args[:2] @@ -59,7 +60,8 @@ def __dealloc__(self): if self._dealloc: del self.thisptr - + + def _x(self): return self.ptr().x() @@ -75,6 +77,7 @@ x = property(_x, _setX) y = property(_y, _setY) + def _pos(self): """(x, y) coordinates of this point""" return (self.x, self.y) @@ -87,6 +90,7 @@ pos = property(_pos, _setPos) + def _xErrs(self): """The x-errors as a 2-tuple (low, high)""" cdef pair[double, double] xErrs = self.ptr().xErrs() @@ -103,6 +107,7 @@ xErrs = property(_xErrs, _setxErrs) + def _yErrs(self): """The y-errors as a 2-tuple (low, high)""" cdef pair[double, double] yErrs = self.ptr().yErrs() @@ -120,9 +125,11 @@ yErrs = property(_yErrs, _setyErrs) + def __repr__(self): return 'Point2D({0},{1})'.format(self.x, self.y) + cdef Point2D Point2D_fromptr(cPoint2D *ptr, dealloc = False): cdef Point2D p = Point2D.__new__(Point2D) return p.setptr(ptr, dealloc) Added: trunk/pyext/yoda/include/20-Point3D.pyx ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/pyext/yoda/include/20-Point3D.pyx Thu Jul 19 00:46:04 2012 (r504) @@ -0,0 +1,171 @@ +cdef extern from "YODA/Point3D.h" namespace "YODA": + cdef cppclass cPoint3D "YODA::Point3D": + cPoint3D () + cPoint3D (cPoint3D &p) + + cPoint3D (double x, double y, double z, + double exminus, double explus, + double eyminus, double eyplus, + double ezminus, double ezplus) + + double x() + double y() + double z() + void setX(double x) + void setY(double y) + void setZ(double z) + double xMin() + double xMax() + double yMin() + double yMax() + double zMin() + double zMax() + pair[double,double] xErrs() + pair[double,double] yErrs() + pair[double,double] zErrs() + void setXErr(double minus, double plus) + void setYErr(double minus, double plus) + void setZErr(double minus, double plus) + + +cdef class Point3D: + cdef cPoint3D* thisptr + + cdef bool _dealloc + + cdef cPoint3D* ptr(self): + return self.thisptr + + cdef Point3D setptr(self, cPoint3D* ptr, dealloc=False): + if self._dealloc: + del self.thisptr + + self.thisptr = ptr + self._dealloc = dealloc + return self + + def __cinit__(self): + self._dealloc = False + + def __init__(self, *args): + self.setptr(new cPoint3D(), True) + self._dealloc = True + + if len(args) == 0: + self.pos = 0, 0 + elif len(args) == 3: + self.pos = args + elif len(args) == 6: + self.pos = args[:3] + self.xErrs, self.yErrs, self.zErrs = args[3:] + elif len(args) == 9: + self.pos = args[:3] + self.xErrs = args[3:5] + self.yErrs = args[5:7] + self.zErrs = args[7:] + else: + raise ValueError( + 'Wrong number of values: can take 3, 6, or 9 parameters') + + def __dealloc__(self): + if self._dealloc: + del self.thisptr + + + def _x(self): + return self.ptr().x() + + def _y(self): + return self.ptr().y() + + def _z(self): + return self.ptr().z() + + def _setX(self, double x): + self.ptr().setX(x) + + def _setY(self, double y): + self.ptr().setY(y) + + def _setZ(self, double z): + self.ptr().setZ(z) + + x = property(_x, _setX) + y = property(_y, _setY) + z = property(_z, _setZ) + + + def _pos(self): + """(x, y) coordinates of this point""" + return (self.x, self.y, self.z) + + def _setPos(self, pos): + cdef double x, y + x, y, z = pos + self.ptr().setX(x) + self.ptr().setY(y) + self.ptr().setZ(z) + + pos = property(_pos, _setPos) + + + def _xErrs(self): + """The x-errors as a 2-tuple (low, high)""" + cdef pair[double, double] xErrs = self.ptr().xErrs() + return (xErrs.first, xErrs.second) + + def _setxErrs(self, arg): + try: + low, high = arg + except TypeError: + low = arg + high = arg + + self.ptr().setXErr(low, high) + + xErrs = property(_xErrs, _setxErrs) + + + def _yErrs(self): + """The y-errors as a 2-tuple (low, high)""" + cdef pair[double, double] yErrs = self.ptr().yErrs() + return (yErrs.first, yErrs.second) + + def _setyErrs(self, arg): + cdef double low, high + try: + low, high = arg + except TypeError: + low = arg + high = arg + + self.ptr().setYErr(low, high) + + yErrs = property(_yErrs, _setyErrs) + + + def _zErrs(self): + """The z-errors as a 2-tuple (low, high)""" + cdef pair[double, double] zErrs = self.ptr().zErrs() + return (zErrs.first, zErrs.second) + + def _setzErrs(self, arg): + cdef double low, high + try: + low, high = arg + except TypeError: + low = arg + high = arg + + self.ptr().setZErr(low, high) + + zErrs = property(_zErrs, _setzErrs) + + + def __repr__(self): + return 'Point3D({0},{1})'.format(self.x, self.y, self.z) + + +cdef Point3D Point3D_fromptr(cPoint3D *ptr, dealloc = False): + cdef Point3D p = Point3D.__new__(Point3D) + return p.setptr(ptr, dealloc) Modified: trunk/pyext/yoda/include/30-Reader.pyx ============================================================================== --- trunk/pyext/yoda/include/30-Reader.pyx Thu Jul 12 22:12:10 2012 (r503) +++ trunk/pyext/yoda/include/30-Reader.pyx Thu Jul 19 00:46:04 2012 (r504) @@ -1,3 +1,3 @@ cdef extern from "YODA/Reader.h" namespace "YODA": cdef cppclass cReader "YODA::Reader": - void read(string filename, vector[AOptr]&) except + + void read(string filename, vector[AOptr]&) except + Modified: trunk/pyext/yoda/include/30-Scatter2D.pyx ============================================================================== --- trunk/pyext/yoda/include/30-Scatter2D.pyx Thu Jul 12 22:12:10 2012 (r503) +++ trunk/pyext/yoda/include/30-Scatter2D.pyx Thu Jul 19 00:46:04 2012 (r504) @@ -3,7 +3,6 @@ cScatter2D() cScatter2D(vector[cPoint2D]&, string, string) cScatter2D(cScatter2D &s) - # TODO: Add more constructors size_t numPoints() vector[cPoint2D] points() @@ -12,27 +11,68 @@ cdef class Scatter2D(AnalysisObject): - cdef tuple _points - def __init__(self, points, char *path="", char *title=""): - points = tuple(points) - - cdef size_t N = len(points) - cdef vector[cPoint2D] point_vector = vector[cPoint2D](N) - cdef Point2D item - cdef cScatter2D *scatter - cdef int i - - # TODO: Add more constructors and nice arg behaviours cf. Profile1D and Histo1D - - for i in range(N): - item = points[i] - point_vector[i] = item.ptr()[0] + def __init__(self, *args, **kwargs): + """ + Scatter2D constructor. Several sets of arguments are permitted: + + * Scatter2D() -- default constructor. Not usually useful in Python, due to availability of None. + * Scatter2D(points[, path, title]) -- explicit construction from a list of points. + * Scatter2D(xs, ys[, path, title]) -- constructing points from lists of x and y positions (no errs). + * Scatter2D(xs, ys, exs, eys[, path, title]) -- constructing points from lists of x and y positions and errs (errs can be pairs). + * Scatter2D(xs, ys, ex-s, ex+s, ey-s, ey+s[, path, title]) -- constructing points from lists of x and y positions and errs. + + The path and title arguments are optional, and may either be specified via the + positional parameters or via explicit keyword arguments, e.g. path='/foo/bar'. + """ + #self._dealloc = True + cdef: + # size_t N = len(points) + # int i + Point2D item + vector[cPoint2D] point_vector + cScatter2D* scatter + char* path = '/' + char* title = '' + + ## Permit path and title specification via kwargs + if "path" in kwargs: + path = kwargs["path"] + if "title" in kwargs: + path = kwargs["title"] + + ## Trigger different construction methods depending on Python args + # TODO: Map copy constructors, esp. the path-resetting one + if len(args) == 0: + self.setptr(new cScatter2D()) + elif len(args) == 1: + for point in args[0]: + item = point + point_vector.push_back( item.ptr()[0] ) + elif len(args) == 2: + # Scatter2D(xs, ys[, path, title]) + assert len(args[0]) == len(args[1]) + for i in xrange(args[0]): + item = Point2D(args[0][i], args[1][i]) + point_vector.push_back( item.ptr()[0] ) + elif len(args) == 4: + # Scatter2D(xs, ys, exs, eys[, path, title]) + assert len(args[0]) == len(args[1]) == len(args[2]) == len(args[3]) + for i in xrange(args[0]): + item = Point2D(args[0][i], args[1][i], args[2][i], args[3][i]) + point_vector.push_back( item.ptr()[0] ) + elif len(args) == 6: + # Scatter2D(xs, ys, ex-s, ex+s, ey-s, ey+s[, path, title]) + assert len(args[0]) == len(args[1]) == len(args[2]) == len(args[3]) + for i in xrange(args[0]): + item = Point2D(args[0][i], args[1][i], args[2][i], args[3][i], args[4][i], args[5][i]) + point_vector.push_back( item.ptr()[0] ) + else: + raise ValueError('Wrong number of values: can take 2, 4, or 6 parameters') scatter = new cScatter2D(point_vector, string(path), string(title)) self.setptr(scatter, True) - self._points = points @property def numPoints(self): Added: trunk/pyext/yoda/include/30-Writer.pyx ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/pyext/yoda/include/30-Writer.pyx Thu Jul 19 00:46:04 2012 (r504) @@ -0,0 +1,4 @@ +cdef extern from "YODA/Writer.h" namespace "YODA": + cdef cppclass cReader "YODA::Writer": + pass + #void read(string filename, vector[AOptr]&) except + Modified: trunk/pyext/yoda/include/40-Histo2D.pyx ============================================================================== --- trunk/pyext/yoda/include/40-Histo2D.pyx Thu Jul 12 22:12:10 2012 (r503) +++ trunk/pyext/yoda/include/40-Histo2D.pyx Thu Jul 19 00:46:04 2012 (r504) @@ -5,16 +5,16 @@ cdef cppclass cHisto2D "YODA::Histo2D"(cAnalysisObject): cHisto2D(size_t nbinsX, double lowerX, double upperX, size_t nbinsY, double lowerY, double upperY, - string &path, string &title) + string& path, string& title) - cHisto2D(cHisto2D &h) + cHisto2D(cHisto2D& h) void fill(double x, double y, double weight) void reset() void scaleW(double scalefactor) void scaleXY(double scaleX, double scaleY) - void mergeBins(size_t a, size_t b) - void rebin(int a, int b) + # void mergeBins(size_t a, size_t b) + # void rebin(int a, int b) # Bin Accessors size_t numBins() @@ -25,10 +25,10 @@ double lowEdgeY() double highEdgeX() double highEdgeY() - vector[vector[cDbn2D]] &outflows() - cDbn2D &totalDbn() + cDbn2D& outflow(int ix, int iy) + cDbn2D& totalDbn() - vector[cHistoBin2D] &bins() + vector[cHistoBin2D]& bins() cHistoBin2D& binByCoord(double x, double y) void eraseBin(size_t index) @@ -63,6 +63,8 @@ char* path = '/' char* title = '' + # TODO: make nice multi-mode constructor + if len(args) == 6: nbinsX, lowX, highX, nbinsY, lowY, highY = args @@ -90,12 +92,12 @@ self.ptr().scaleW(factor) - def mergeBins(self, size_t a, size_t b): - self.ptr().mergeBins(a, b) + # def mergeBins(self, size_t a, size_t b): + # self.ptr().mergeBins(a, b) - def rebin(self, int a, int b): - self.ptr().rebin(a, b) + # def rebin(self, int a, int b): + # self.ptr().rebin(a, b) @property @@ -141,20 +143,8 @@ return Dbn2D_fromptr(&self.ptr().totalDbn()) - def outflows(self): - cdef size_t numofsX = self.ptr().numBinsX() - cdef size_t numofsY = self.ptr().numBinsY() - cdef size_t i - cdef Dbn2D of - - out = [] - for i in xrange(numofsX): - for j in xrange(numofsY): - of = Dbn2D_fromptr(&self.ptr().outflows()[i][j]) - out.append(bin) - # TODO: Why was this here? - # self.ptr().outflows() - return out + def outflow(self, ix, iy): + return Dbn2D_fromptr(&self.ptr().outflow(ix, iy)) def __delitem__(self, size_t ix): Added: trunk/pyext/yoda/include/40-WriterYODA.pyx ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/pyext/yoda/include/40-WriterYODA.pyx Thu Jul 19 00:46:04 2012 (r504) @@ -0,0 +1,17 @@ +cdef extern from "shims.h": + void WriterYODA_write (string&, vector[AOptr]&) except + + +def __write_YODA(char* filename, aos): + """Takes a file, returns a list of AnalysisObjects""" + cdef vector[AOptr] vec = vector[AOptr]() + cdef AnalysisObject ana + + for ao in aos: + ana = <AnalysisObject> ao + vec.push_back(ana.thisptr) + + WriterYODA_write(string(filename), vec) + +class WriterYODA: + """Read YODA files""" + write = staticmethod(__write_YODA) Modified: trunk/pyext/yoda/shims.h ============================================================================== --- trunk/pyext/yoda/shims.h Thu Jul 12 22:12:10 2012 (r503) +++ trunk/pyext/yoda/shims.h Thu Jul 19 00:46:04 2012 (r504) @@ -1,16 +1,30 @@ /// This file is purely for backward compatibility with Cython 1.3 and 1.4. +/// @todo Now to be removed! #include "YODA/AnalysisObject.h" + +// 1D #include "YODA/Histo1D.h" #include "YODA/Profile1D.h" #include "YODA/Scatter2D.h" #include "YODA/HistoBin1D.h" +#include "YODA/ProfileBin1D.h" + +// 2D // #include "YODA/Histo2D.h" +// #include "YODA/Profile2D.h" // #include "YODA/Scatter3D.h" +#include "YODA/HistoBin2D.h" +#include "YODA/ProfileBin2D.h" + +// Writers +#include "YODA/WriterYODA.h" #include "YODA/WriterAIDA.h" + #include <string> #include <vector> + using namespace YODA; /// Histo1D operators @@ -55,6 +69,10 @@ return WriterAIDA::write(filename, aos); } +void WriterYODA_write (const std::string& filename, const std::vector<AnalysisObject*>& aos) { + return WriterYODA::write(filename, aos); +} + Scatter2D Scatter2D_mkScatter(const Histo1D& h) { return YODA::mkScatter(h);
More information about the yoda-svn mailing list |