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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed Aug 17 15:01:06 BST 2011


Author: mkawalec
Date: Wed Aug 17 15:01:06 2011
New Revision: 263

Log:
Reverted Scatter3D to be sorted again, not using Utils::sortedvector though. Added a Scatter3D test (not yet completed!!).

Added:
   trunk/tests/TestScatter3D.cc
Modified:
   trunk/include/YODA/Scatter3D.h
   trunk/tests/Makefile.am

Modified: trunk/include/YODA/Scatter3D.h
==============================================================================
--- trunk/include/YODA/Scatter3D.h	Wed Aug 17 13:27:32 2011	(r262)
+++ trunk/include/YODA/Scatter3D.h	Wed Aug 17 15:01:06 2011	(r263)
@@ -8,7 +8,6 @@
 
 #include "YODA/AnalysisObject.h"
 #include "YODA/Point3D.h"
-#include "YODA/Utils/sortedvector.h"
 #include "YODA/Histo2D.h"
 
 #include <utility>
@@ -38,7 +37,9 @@
               const std::string& path="", const std::string& title="")
       : AnalysisObject("Scatter3D", path, title),
         _points(points)
-    {  }
+    {  
+      std::sort(_points.begin(), _points.end());
+    }
 
 
     /// Constructor from vectors of values with asymmetric errors on both x and y
@@ -54,6 +55,7 @@
       for (size_t i = 0; i < x.size(); ++i) {
         addPoint(Point3D(x[i], y[i], z[i], ex[i], ey[i], ez[i]));
       }
+      std::sort(_points.begin(), _points.end());
     }
 
 
@@ -87,6 +89,8 @@
       for (size_t i = 0; i < x.size(); ++i) {
         addPoint(Point3D(x[i], exminus[i], explus[i], y[i], eyminus[i], eyplus[i], z[i], ezminus[i], ezplus[i]));
       }
+
+      std::sort(_points.begin(), _points.end());
     }
 
 
@@ -161,6 +165,7 @@
     Scatter3D& addPoint(double x, double y, double z,
                         std::pair<double,double> ex, std::pair<double,double> ey, std::pair<double,double> ez) {
       _points.push_back(Point3D(x, y, z, ex, ey, ez));
+
       return *this;
     }
 
@@ -168,6 +173,7 @@
                         double y, double eyminus, double eyplus,
                         double z, double ezminus, double ezplus) {
       _points.push_back(Point3D(x, exminus, explus, y, eyminus, eyplus, z, ezminus, ezplus));
+
       return *this;
     }
 
@@ -175,6 +181,8 @@
       foreach (const Point3D& pt, pts) {
         addPoint(pt);
       }
+      std::sort(_points.begin(), _points.end());
+
       return *this;
     }
 
@@ -198,6 +206,15 @@
     }
 
 
+  /// Equality operator
+  bool operator == (const Scatter3D& other) {
+    return _points == other._points;
+  }
+
+  bool operator != (const Scatter3D& other) {
+    return ! operator == (other);
+  }
+
   private:
 
     Points _points;

Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am	Wed Aug 17 13:27:32 2011	(r262)
+++ trunk/tests/Makefile.am	Wed Aug 17 15:01:06 2011	(r263)
@@ -4,6 +4,7 @@
 	testprofile1Da \
   testhisto2D  \
   testpoint3D  \
+  testscatter3D\
 	testindexedset testsortedvector
 
 AM_CPPFLAGS = -I$(top_srcdir)/include
@@ -17,6 +18,7 @@
 testsortedvector_SOURCES = TestSortedVector.cc
 testhisto2D_SOURCES = TestHisto2D.cc
 testpoint3D_SOURCES = TestPoint3D.cc
+testscatter3D_SOURCES = TestScatter3D.cc
 
 # TODO: Search paths are still not complete for the Python tests: need to add the lib.linux-i686-2.7 part to PYTHONPATH
 TESTS_ENVIRONMENT = \
@@ -30,5 +32,6 @@
 	testprofile1Da \
   testhisto2D    \
   testpoint3D    \
+  testscatter3D  \
 	testindexedset testsortedvector \
 	test-yoda-1.py test-yoda-2.py

Added: trunk/tests/TestScatter3D.cc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/tests/TestScatter3D.cc	Wed Aug 17 15:01:06 2011	(r263)
@@ -0,0 +1,81 @@
+#include "YODA/Histo2D.h"
+#include "YODA/Scatter3D.h"
+#include "YODA/Point3D.h"
+
+#include <iostream>
+#include <sys/time.h>
+
+using namespace std;
+using namespace YODA;
+
+int main() {
+  struct timeval startTime;
+  struct timeval endTime;
+  cout << "-----------------------------------" << endl;
+
+  cout << "Constructing a sample Scatter3D (empty constructor method):" << endl;
+  Scatter3D s1("/path", "title");
+  
+  cout << "Constructing a sample Scatter3D (from existing points):" << endl;
+  
+  Point3D p(1, 1, 1, 1, 1, 1);
+  vector<Point3D> points;
+  points.resize(100000);
+
+  for(size_t i=0; i < points.size(); ++i) points[i] = p;
+  gettimeofday(&startTime, NULL);
+  Scatter3D s2(points, "/path", "title");
+  gettimeofday(&endTime, NULL);
+  
+  double tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000;
+  double tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000;
+
+  cout << "Time to construct a Scatter3D out of 100k Points: " << tE - tS << "s" << endl;
+
+
+  cout << "Constructing a sample Scatter3D (from point-vectors):" << endl;
+  vector<double>                coords;
+  vector<pair<double, double> > ecoords;
+  coords.resize(100000);
+  ecoords.resize(100000);
+
+  for(size_t i=0; i < coords.size(); i++) {
+    coords[i] = 1;
+    ecoords[i] = make_pair(1, 0.5);
+  }
+  cout << "Done!" << endl;
+  gettimeofday(&startTime, NULL);
+  Scatter3D s3(coords, coords, coords, ecoords, ecoords, ecoords, "/path", "title");
+  gettimeofday(&endTime, NULL);
+  
+  tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000;
+  tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000;
+
+  cout << "Time to construct a Scatter3D out of 100k Points: " << tE - tS << "s" << endl;
+
+  cout << "Checking if copy constructor works:" << endl;
+
+  gettimeofday(&startTime, NULL);
+  Scatter3D s4(s3);
+  gettimeofday(&endTime, NULL);
+  
+  tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000;
+  tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000;
+
+  cout << "Time to copy over a 1M Points Scatter3D: " << tE - tS << "s" << endl;
+
+  if(s4 != s3) {
+    cout << "Something is wrong in the way the copy constructor works!" << endl;
+    return -1;
+  }
+
+  cout << "Testing resetting: ";
+  s4.reset();
+  if(s4.numPoints() != 0) {
+    cout << "Resetting didn't work as it should!" << endl;
+    return -1;
+  }
+  cout << "\033[1;31m" << "Fine" << "\033[0m\n";
+  cout << "-----------------------------------" << endl;
+  return EXIT_SUCCESS;
+}


More information about the yoda-svn mailing list