[yoda-svn] r346 - in trunk: include/YODA tests/Histo1D

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed Aug 24 12:52:53 BST 2011


Author: mkawalec
Date: Wed Aug 24 12:52:53 2011
New Revision: 346

Log:
Added bin addition testing. Also, fixed a very serious bug in getBinIndex() in Axis1D.

Modified:
   trunk/include/YODA/Axis1D.h
   trunk/tests/Histo1D/Modify.cc

Modified: trunk/include/YODA/Axis1D.h
==============================================================================
--- trunk/include/YODA/Axis1D.h	Wed Aug 24 12:11:46 2011	(r345)
+++ trunk/include/YODA/Axis1D.h	Wed Aug 24 12:52:53 2011	(r346)
@@ -184,8 +184,10 @@
       // a member of the same bin as the one on the right, it means that our point
       // is inside a bin. In such case, announce it providing the index of the
       // bin in question.
-      if (_binHashSparse[index].second == _binHashSparse[index+1].second) {
-        return _binHashSparse[index].second;
+      for(size_t i = index+1; _binHashSparse[i].first == _binHashSparse[index+1].first; ++i){
+        if(_binHashSparse[index].second == _binHashSparse[i].second) {
+          return _binHashSparse[index].second;
+        }
       }
 
       // If we are inside an axis, but not inside a bin, it means that we must
@@ -210,12 +212,12 @@
       if (from < 0 || from >= numBins()) throw ("First index is out of range!");
       if (to < 0 || to >= numBins()) throw ("Second index is out of range!");
       if (_bins[from].xMin() > _bins[to].xMin()) throw RangeError("The starting bin is greater than ending bin!");
+      if (!_isGapless(from, to)) throw ("Bins with an empty space between them cannot be merged!");
+
       BIN1D& b = _bins[from];
-      // std::cout << "a " << b.focus() << std::endl;
       for (size_t i = from+1; i <= to; ++i) {
         b.merge(_bins[i]);
       }
-      // std::cout << "b " << b.focus() << std::endl;
       eraseBins(from+1, to);
     }
 
@@ -225,7 +227,6 @@
       size_t m = 0;
       while (m < _bins.size()) {
         const size_t end = (m + n - 1 < _bins.size()) ? m + n -1 : _bins.size() - 1;
-        //std::cout << m << ", " << end << ", " << _bins.size() << std::endl;
         if (end > m) mergeBins(m, end);
         m += 1;
       }

Modified: trunk/tests/Histo1D/Modify.cc
==============================================================================
--- trunk/tests/Histo1D/Modify.cc	Wed Aug 24 12:11:46 2011	(r345)
+++ trunk/tests/Histo1D/Modify.cc	Wed Aug 24 12:52:53 2011	(r346)
@@ -46,5 +46,16 @@
   cout << "PASS" << endl;
 
 
+  cout << "Checking if it is possible to add a bin: ";
+  h.addBin(0,11);
+  cout << "PASS" << endl;
+ 
+  cout << "Checking if it was added properly:       ";
+  if(!fuzzyEquals(h.binByCoord(1).xMin(), 0) || !fuzzyEquals(h.binByCoord(1).xMax(),11)){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
   return EXIT_SUCCESS;
 }


More information about the yoda-svn mailing list