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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Aug 22 11:16:56 BST 2011


Author: mkawalec
Date: Mon Aug 22 11:16:55 2011
New Revision: 311

Log:
Added binRemoval. Provided tests for its working. isGhost is still there...

Added:
   trunk/tests/TestHisto2Derase.cc
Modified:
   trunk/TODO
   trunk/include/YODA/Axis2D.h
   trunk/include/YODA/Histo2D.h
   trunk/tests/Makefile.am

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	Mon Aug 22 10:35:07 2011	(r310)
+++ trunk/TODO	Mon Aug 22 11:16:55 2011	(r311)
@@ -23,6 +23,7 @@
   equivalently x-binned Profile1D. Perhaps use this as an opportunity to
   implement one of the the conversion functions mentioned in the NEXT
   section... (MICHAL)
+  MK: Conversion function implemented, no tests yet, though.
 
 * Conversion functions to build Histo1D and Profile1D objects for slicings and
   marginalisations along both X and Y directions of 2D histos. Throw an
@@ -32,6 +33,7 @@
       should be included in these slicings.
   MK: Profile1D done. Outflows done. Needs a check if the outflows for Histo1D are
       done in the right way.
+  MK: Corrected the outflows to be appropriate.
 
 * New "flat" file format: adapt WriterYODA and fill ReaderYODA. (HH)
   Need to persist the whole-histo Dbn1D/Dbn2Ds, and over/underflows.

Modified: trunk/include/YODA/Axis2D.h
==============================================================================
--- trunk/include/YODA/Axis2D.h	Mon Aug 22 10:35:07 2011	(r310)
+++ trunk/include/YODA/Axis2D.h	Mon Aug 22 11:16:55 2011	(r311)
@@ -449,7 +449,7 @@
       if(!_isGrid) throw GridError("This operation can only be performed when an array is a grid!");
       if(index >= _bins.size()) throw RangeError("Index is bigger than the size of bins vector!");
 
-      /// Find the column nuber
+      /// Find the row nuber
       size_t ret  = (*_binHashSparse.second._cache.lower_bound(approx(bin(index).xMin()))).second;     
       return ret;
 }
@@ -459,6 +459,39 @@
       return _isGrid;
     }
 
+    /// @brief Bin eraser
+    /// Removes a bin at a position. Additionally, modifies bin cache to
+    /// make it represent the new bin set.
+    void eraseBin(size_t index) {
+      /// Check the correctness of assumptions
+      if(index >= _bins.size()) throw RangeError("Index is bigger than the size of bins vector!");
+
+      _bins.erase(_bins.begin() + index);
+      /// Check if delimiter if recomputed after every for run.
+      for(size_t i = 0; i < _binHashSparse.first.size(); ++i) {
+        for(size_t j = 0; j < _binHashSparse.first[i].second.size(); ++j) {
+          if(_binHashSparse.first[i].second[j].first == index) {
+            _binHashSparse.first[i].second.erase(_binHashSparse.first[i].second.begin() + j);
+            j--;
+          }
+          else if(_binHashSparse.first[i].second[j].first > index) {
+            _binHashSparse.first[i].second[j].first--;
+          }
+        }
+      }
+      
+      for(size_t i = 0; i < _binHashSparse.second.size(); ++i) {
+        for(size_t j = 0; j < _binHashSparse.second[i].second.size(); ++j) {
+          if(_binHashSparse.second[i].second[j].first == index) {
+            _binHashSparse.second[i].second.erase(_binHashSparse.second[i].second.begin() + j);
+            j--;
+          }
+          else if(_binHashSparse.second[i].second[j].first > index) {
+            _binHashSparse.second[i].second[j].first--;
+          }
+        }
+      }
+    }
     //@}
 
 

Modified: trunk/include/YODA/Histo2D.h
==============================================================================
--- trunk/include/YODA/Histo2D.h	Mon Aug 22 10:35:07 2011	(r310)
+++ trunk/include/YODA/Histo2D.h	Mon Aug 22 11:16:55 2011	(r311)
@@ -64,11 +64,10 @@
     Histo2D(const Histo2D& h, const std::string& path="")
       : AnalysisObject("Histo2D", (path.size() == 0) ? h.path() : path, h, h.title())
     {
-      cout << " blah" << endl << endl << endl;
-     cout << "dasdasd"; 
-      cout << "in" << endl;
+      cout << "lsadlksdjflksdhkjf" << endl;
+      if(_axis.outflows().size() == h._axis.outflows().size()) cout << "equals" << endl;
+      else cout << "non" << endl;
       _axis = h._axis;
-      cout << "out" << endl;
     }
 
 
@@ -130,6 +129,10 @@
       _axis.mergeBins(from, to);
     }
 
+    void eraseBin(size_t index) {
+      _axis.eraseBin(index);
+    }
+
     //@}
 
 

Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am	Mon Aug 22 10:35:07 2011	(r310)
+++ trunk/tests/Makefile.am	Mon Aug 22 11:16:55 2011	(r311)
@@ -4,6 +4,7 @@
 	testprofile1Da \
   testhisto2D  \
   testhisto2Da  \
+  testhisto2De \
   testpoint3D  \
   testscatter3D\
 	testindexedset testsortedvector
@@ -19,6 +20,7 @@
 testsortedvector_SOURCES = TestSortedVector.cc
 testhisto2D_SOURCES = TestHisto2D.cc
 testhisto2Da_SOURCES = TestHisto2Da.cc
+testhisto2De_SOURCES = TestHisto2Derase.cc
 testpoint3D_SOURCES = TestPoint3D.cc
 testscatter3D_SOURCES = TestScatter3D.cc
 
@@ -34,6 +36,7 @@
 	testprofile1Da \
   testhisto2D    \
   testhisto2Da    \
+  testhisto2De \
   testpoint3D    \
   testscatter3D  \
 	testindexedset testsortedvector \

Added: trunk/tests/TestHisto2Derase.cc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/tests/TestHisto2Derase.cc	Mon Aug 22 11:16:55 2011	(r311)
@@ -0,0 +1,48 @@
+#include "YODA/Histo2D.h"
+
+#include <iostream>
+#include <sys/time.h>
+
+using namespace YODA;
+using namespace std;
+
+int main() {
+  /// This is a bin removal tester
+  cout << "-----------------------------" << endl;
+
+  /// Firstly, let's create some bins:
+  Histo2D h(100, 0, 100, 100, 0, 100);
+
+  /// Let's try to remove the one that surely exists:
+  h.eraseBin(0);
+  
+  cout << "Number of bins: " << h.numBinsTotal() << endl;
+  if(h.numBinsTotal() != 9999) {
+   cout << "The bin was not correctly removed, or the computation of numBinsTotal is broken!" << endl;
+   return -1;
+  }
+
+  int index = h.fill(0,0,1);
+  cout << index << endl;
+  if(index != -1) {
+    cout << "A bin wasn't correctly removed!" << endl;
+    return -1;
+  }
+
+  
+  /// Now, some timing
+  struct timeval startTime;
+  struct timeval endTime;
+  gettimeofday(&startTime, NULL);
+  for(size_t i = 0; i < 1000; ++i) h.eraseBin(0);
+  gettimeofday(&endTime, NULL);
+  cout << "After removing 1k bins there is " << h.numBinsTotal() << " bins left." << endl;
+
+  double tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000;
+  double tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000;
+
+  cout << "It takes " << tE - tS << " s to remove 1k bins." << endl;
+
+  cout << "-------------------------" << endl;
+  return EXIT_SUCCESS;
+}


More information about the yoda-svn mailing list