[yoda-svn] r300 - in trunk: . include/YODA

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu Aug 18 23:44:01 BST 2011


Author: buckley
Date: Thu Aug 18 23:44:01 2011
New Revision: 300

Log:
Trying to deceipher the 1D axis again, for implementing rebinning, and some more comments and tidying elsewhere. By the way (and not due to these changes) the histo 2D test currently fails.

Modified:
   trunk/TODO
   trunk/include/YODA/Axis1D.h
   trunk/include/YODA/Axis2D.h
   trunk/include/YODA/Bin1D.h

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	Thu Aug 18 23:13:32 2011	(r299)
+++ trunk/TODO	Thu Aug 18 23:44:01 2011	(r300)
@@ -13,14 +13,8 @@
   to define the conventions for handling the fact that this usually won't be
   exactly possible.
 
-* Similarly, is there any reason to expose the isGriddy function publicly on
-  Axis2D and Histo2D? Can't it just be a private _isGrid()? (MICHAL)
-  MK: Done
-  AB: Ah, some confusion here. I see that it's now disappeared from the Histo2D interface,
-    but since the Axis objects are for internal use only, I don't think there is a
-    reason for the is-grid? method to be private on Axis2D -- this is the only reason
-    for Histo2D to have to be a friend of Axis2D, right?
-  MK: Thanks for pointing that out. I have got lost in my own code;)
+* Rethink 1D bin inheritance: template Bin1D on dbn type and inherit from
+  Bin1D<Dbn1D> and Bin1D<Dbn2D> for histo and profile bins respectively? (AB)
 
 * Add copy constructors for Dbn1D/2D, Scatter2D, Histo/ProfileBin1D, Point2D/3D, HistoBin2D.
   Rule of three: also need explicit assignment operator= for all classes

Modified: trunk/include/YODA/Axis1D.h
==============================================================================
--- trunk/include/YODA/Axis1D.h	Thu Aug 18 23:13:32 2011	(r299)
+++ trunk/include/YODA/Axis1D.h	Thu Aug 18 23:44:01 2011	(r300)
@@ -93,6 +93,7 @@
 
   public:
 
+    /// Get the number of bins on the axis
     unsigned int numBins() const {
       return _bins.size();
     }
@@ -181,8 +182,7 @@
 
 
     size_t findBinIndex(double coord) const {
-      /// @todo Improve!
-      if (coord < _cachedBinEdges[0] || coord >= _cachedBinEdges[numBins()]) {
+      if (!inRange(coord, _cachedBinEdges[0], _cachedBinEdges[numBins()])) {
         throw RangeError("Coordinate is outside the valid range: you should request the underlow or overflow");
       }
       size_t i = _binHash.upper_bound(coord)->second;
@@ -190,12 +190,13 @@
     }
 
 
+    /// Reset this axis' distributions to an unfilled state
     void reset() {
       _dbn.reset();
       _underflow.reset();
       _overflow.reset();
-      for (typename Bins::iterator b = _bins.begin(); b != _bins.end(); ++b) {
-        b->reset();
+      foreach (Bin& b, bins()) {
+        b.reset();
       }
     }
 
@@ -211,9 +212,15 @@
 
     /// Merge a bin range @a binindex1 to @a binindex2 into a single bin.
     void mergeBins(size_t binindex1, size_t binindex2) {
-      assert(binindex1 >= binindex2);
+      if (binindex1 > binindex2) throw RangeError("binindex1 is greater than binindex2");
       if (binindex1 < 0 || binindex1 >= numBins()) throw RangeError("binindex1 is out of range");
       if (binindex2 < 0 || binindex2 >= numBins()) throw RangeError("binindex2 is out of range");
+
+      for (size_t i = binindex1; i <= binindex2; ++i) {
+        /// @todo
+      }
+      //DBN
+      BIN1D newbin(bin(binindex1).xMin(), bin(binindex1).xMax());
       /// @todo Implement! Requires ability to change bin edges from outside...
       throw std::runtime_error("Rebinning is not yet implemented! Pester me, please.");
     }
@@ -224,8 +231,8 @@
        _dbn.scaleX(scalefactor);
        _underflow.scaleW(scalefactor);
        _overflow.scaleW(scalefactor);
-       for(int i=0; i < _bins.size(); i++) _bins[i].scaleX(scalefactor);
-       for(int i=0; i < _cachedBinEdges.size(); i++) _cachedBinEdges[i] *= scalefactor;
+       for (int i = 0; i < _bins.size(); ++i) _bins[i].scaleX(scalefactor);
+       for (int i = 0; i < _cachedBinEdges.size(); ++i) _cachedBinEdges[i] *= scalefactor;
        _mkBinHash();
     }
 
@@ -288,6 +295,7 @@
 
     /// @todo Remove
     void _mkBinHash() {
+      /// @todo Reset cached edges and the hash map
       for (size_t i = 0; i < numBins(); i++) {
         // Insert upper bound mapped to bin ID
         _binHash.insert(std::make_pair(_cachedBinEdges[i+1],i));
@@ -325,12 +333,6 @@
   private:
 
 
-    /// @todo Store bins in a more flexible (and sorted) way
-    /// @todo Check non-overlap of bins
-    /// @todo Bin access by index
-    /// @todo Overall y-dbn for profiles?
-
-
     /// @name Bin data
     //@{
 
@@ -342,15 +344,15 @@
 
     /// A distribution counter for overflow fills
     DBN _underflow;
-    /// A distribution counter for underlow fills
+    /// A distribution counter for underflow fills
     DBN _overflow;
 
-    /// Bin edges: lower edges, except last entry,
-    /// which is the high edge of the last bin
+    /// Bin edges (nbins + 1) cached for speed
     std::vector<double> _cachedBinEdges;
 
     /// Map for fast bin lookup
     std::map<double,size_t> _binHash;
+
     //@}
 
   };

Modified: trunk/include/YODA/Axis2D.h
==============================================================================
--- trunk/include/YODA/Axis2D.h	Thu Aug 18 23:13:32 2011	(r299)
+++ trunk/include/YODA/Axis2D.h	Thu Aug 18 23:44:01 2011	(r300)
@@ -216,7 +216,7 @@
     }
 
 
-    /// Merge a given range of bins, given the bin IDs
+    /// Merge a range of bins, given the bin IDs of points at the lower-left and upper-right.
     ///
     /// @todo This is far too big to be inline: move it to the bottom of this file, or perhaps to a .cc
     void mergeBins(size_t from, size_t to) {
@@ -225,15 +225,18 @@
       HistoBin2D temp = start;
       _bins[from].second = false;
 
-      if (start.midpoint().first > end.midpoint().first ||
-          start.midpoint().second > end.midpoint().second)
-        throw GridError("The start/end bins are wrongly defined.");
+      // Sanity-check input indices
+      if (start.midpoint().first > end.midpoint().first) {
+        throw RangeError("The start bin has a greater x value than the end bin.");
+      }
+      if (start.midpoint().second > end.midpoint().second) {
+        throw RangeError("The start bin has a greater y value than the end bin.");
+      }
 
-      /// @todo Tidy!
+      /// @todo Explain! This is *totally* incomprehensible.
       for (size_t y = (*_binHashSparse.first._cache.lower_bound(start.yMin())).second;
            y <= (*_binHashSparse.first._cache.lower_bound(end.yMin())).second; ++y) {
         for (size_t x = 0; x < _binHashSparse.first[y].second.size(); ++x) {
-          /// @todo Tidy!
           if ((_binHashSparse.first[y].second[x].second.first > start.xMin() ||
                fuzzyEquals(_binHashSparse.first[y].second[x].second.first, start.xMin())) &&
               (_binHashSparse.first[y].second[x].second.second < end.xMax() ||
@@ -241,9 +244,6 @@
               _bins[_binHashSparse.first[y].second[x].first].second)
             {
               temp += bin(_binHashSparse.first[y].second[x].first);
-              /// @todo This sort of setting via a reference is quite confusing -- since Axis2D is a friend,
-              /// just use the _isGhost member. Or, better IMO, do all the "ghost" bookkeeping purely on
-              /// the axis and avoid storing an axis implementation feature on *all* the bins.
               _bins[_binHashSparse.first[y].second[x].first].second = false;
             }
         }
@@ -251,6 +251,8 @@
       _addEdge(temp.edges(), _binHashSparse, false);
       _bins.push_back(make_pair(temp, true));
 
+      /// @todo Where do the old bins get dropped?
+
       _binHashSparse.first.regenCache();
       _binHashSparse.second.regenCache();
       _regenDelimiters();
@@ -261,9 +263,9 @@
 
 
     /// Reset the axis statistics
-    void reset()
-    {
+    void reset() {
       _dbn.reset();
+      /// @todo Sort out the Bins definition, then use foreach
       for (size_t i = 0; i < _bins.size(); ++i) {
         _bins[i].first.reset();
       }

Modified: trunk/include/YODA/Bin1D.h
==============================================================================
--- trunk/include/YODA/Bin1D.h	Thu Aug 18 23:13:32 2011	(r299)
+++ trunk/include/YODA/Bin1D.h	Thu Aug 18 23:44:01 2011	(r300)
@@ -212,14 +212,18 @@
 
     /// Add two bins (internal, explicitly named version)
     Bin1D& add(const Bin1D& b) {
-      assert(_edges == b._edges);
+      if (_edges != b._edges) {
+        throw LogicError("Attempted to add two bins with different edges");
+      }
       _xdbn += b._xdbn;
       return *this;
     }
 
     /// Subtract one bin from another (internal, explicitly named version)
     Bin1D& subtract(const Bin1D& b) {
-      assert(_edges == b._edges);
+      if (_edges != b._edges) {
+        throw LogicError("Attempted to add two bins with different edges");
+      }
       _xdbn -= b._xdbn;
       return *this;
     }


More information about the yoda-svn mailing list