[yoda-svn] r562 - in trunk: . include/YODA pyext/yoda pyext/yoda/include src

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Mar 4 14:50:27 GMT 2013


Author: buckley
Date: Mon Mar  4 14:50:26 2013
New Revision: 562

Log:
Adding Plot mapping to Cython and improving the AO annotations handling in Python.

Modified:
   trunk/ChangeLog
   trunk/include/YODA/Plot.h
   trunk/pyext/yoda/core.pyx
   trunk/pyext/yoda/declarations.pxd
   trunk/pyext/yoda/include/AnalysisObject.pyx
   trunk/pyext/yoda/include/Scatter2D.pyx
   trunk/src/ReaderAIDA.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Mon Mar  4 14:02:38 2013	(r561)
+++ trunk/ChangeLog	Mon Mar  4 14:50:26 2013	(r562)
@@ -1,5 +1,7 @@
 2013-03-04  Andy Buckley  <andy.buckley at cern.ch>
 
+	* Adding Plot mapping to Cython and improving the AO annotations handling in Python.
+
 	* Adding PLOT section writing to WriterFLAT (and WriterYODA,
 	although that might be a bad idea...)
 

Modified: trunk/include/YODA/Plot.h
==============================================================================
--- trunk/include/YODA/Plot.h	Mon Mar  4 14:02:38 2013	(r561)
+++ trunk/include/YODA/Plot.h	Mon Mar  4 14:50:26 2013	(r562)
@@ -25,6 +25,10 @@
 
     //@}
 
+
+    /// Make this class non-abstract
+    void reset() {};
+
   };
 
 

Modified: trunk/pyext/yoda/core.pyx
==============================================================================
--- trunk/pyext/yoda/core.pyx	Mon Mar  4 14:02:38 2013	(r561)
+++ trunk/pyext/yoda/core.pyx	Mon Mar  4 14:50:26 2013	(r562)
@@ -42,3 +42,10 @@
 include "include/HistoBin2D.pyx"
 include "include/Histo2D.pyx"
 include "include/Profile2D.pyx"
+
+cdef class Plot(AnalysisObject):
+    cdef inline c.Plot *_Plot(self) except NULL:
+        return <c.Plot*> self.ptr()
+
+    def __init__(self):
+        util.set_owned_ptr(self, new c.Plot())

Modified: trunk/pyext/yoda/declarations.pxd
==============================================================================
--- trunk/pyext/yoda/declarations.pxd	Mon Mar  4 14:02:38 2013	(r561)
+++ trunk/pyext/yoda/declarations.pxd	Mon Mar  4 14:50:26 2013	(r562)
@@ -11,7 +11,7 @@
     void err "translate_yoda_error" ()
 
 ctypedef map[string, string] Annotations
-ctypedef double (*dbl_dbl_fptr) (double) 
+ctypedef double (*dbl_dbl_fptr) (double)
 
 # Distributions
 
@@ -50,8 +50,8 @@
 cdef extern from "YODA/Dbn2D.h" namespace "YODA":
     cdef cppclass Dbn2D:
         Dbn2D ()
-        Dbn2D (Dbn2D) 
-        
+        Dbn2D (Dbn2D)
+
         void fill(double x, double y, double weight) except+ err
         void reset() except+ err
         void scaleW(double) except+ err
@@ -70,7 +70,7 @@
         double yStdDev() except+ err
         double yStdErr() except+ err
         double yRMS() except+ err
-        
+
         # Raw distribution running sums
         unsigned long numEntries() except+ err
         double effNumEntries() except+ err
@@ -126,7 +126,7 @@
         double zStdErr()
         double zRMS()
 
-        
+
         # Raw distribution running sums
         unsigned long numEntries()
         double effNumEntries()
@@ -270,7 +270,7 @@
         double width() except+ err
         double focus() except+ err
         double midpoint() except+ err
-        
+
         # x statistics
         double xMean() except+ err
         double xVariance() except+ err
@@ -299,7 +299,7 @@
 cdef extern from "YODA/Bin2D.h" namespace "YODA":
     cdef cppclass Bin2D[DBN](Bin):
         Bin2D(pair[double, double] xedges,
-              pair[double, double] yedges) except+ 
+              pair[double, double] yedges) except+
         Bin2D(Bin2D bin) except+ err
 
         # CYTHON HACK DO NOT CALL THIS IT DOES NOT EXIST
@@ -319,7 +319,7 @@
 
         pair[double, double] focus() except+ err
         pair[double, double] midpoint() except+ err
-        
+
         # x statistics
         double xMean() except+ err
         double xVariance() except+ err
@@ -444,7 +444,8 @@
         #Bin2D_Dbn2D merge(HistoBin2D b)
 #}}} HistoBin2D
 
-# Analaysis Objects
+
+# Analysis Objects
 
 # AnalysisObject {{{
 cdef extern from "YODA/AnalysisObject.h" namespace "YODA":
@@ -489,7 +490,7 @@
     cdef cppclass Scatter2D(AnalysisObject):
         Scatter2D(string path, string title) except+ err
 
-        Scatter2D(sortedvector[Point2D], 
+        Scatter2D(sortedvector[Point2D],
                 string path,
                 string title) except+ err
 
@@ -523,7 +524,7 @@
 cdef extern from "YODA/Scatter3D.h" namespace "YODA":
     cdef cppclass Scatter3D(AnalysisObject):
         Scatter3D(string path, string title) except+ err
-        Scatter3D(sortedvector[Point3D], 
+        Scatter3D(sortedvector[Point3D],
                 string path,
                 string title) except+ err
 
@@ -857,3 +858,10 @@
         void mergeBins(size_t, size_t) except+ err
 # Axis2D }}}
 
+
+# Plot {{{
+cdef extern from "YODA/Plot.h" namespace "YODA":
+    cdef cppclass Plot(AnalysisObject):
+        pass
+    #Histo2D(string path, string title) except+ err
+# Plot }}}

Modified: trunk/pyext/yoda/include/AnalysisObject.pyx
==============================================================================
--- trunk/pyext/yoda/include/AnalysisObject.pyx	Mon Mar  4 14:02:38 2013	(r561)
+++ trunk/pyext/yoda/include/AnalysisObject.pyx	Mon Mar  4 14:50:26 2013	(r562)
@@ -2,9 +2,11 @@
 from cStringIO import StringIO
 
 # Useful helper function to avoid hoops in Cython's type system
+# TODO: Necessary?
 cdef void set_annotation(c.AnalysisObject *ana, char *k, char *v):
     ana.setAnnotation(string(k), string(v))
 
+
 # AnalysisObject is the base class of most of the user facing objects
 cdef class AnalysisObject(util.Base):
 
@@ -31,19 +33,8 @@
             preinc(it)
         return out_dict
 
-    def string(self):
-        """
-        A human readable representation of this object as it would be
-        stored in a YODA file.
-
-        """
-        f = StringIO()
-        writeYODA([self], f)
-        f.seek(0)
-        return f.read().strip()
-
-
     def updateAnnotations(self, E=None, **F):
+        # TODO: Yuck!
         """
         AO.update([E, ]**F) -> None.  Update annotations of AO from
         dict/iterable E and F. Has the same semantics as Python's
@@ -61,14 +52,48 @@
         if E is not None:
             if hasattr(E, 'keys'):
                 for k in E:
+                    # TODO: reinstate with str cast: set_annotation(AO, k, str(E[k]))
                     set_annotation(AO, k, E[k])
             else:
                 for k, v in E:
+                    # TODO: reinstate with str cast: set_annotation(AO, k, str(v))
                     set_annotation(AO, k, v)
 
         for k in F:
+            # TODO: reinstate with str cast: set_annotation(AO, k, str(F[k]))
             set_annotation(AO, k, F[k])
 
+    # string annotation(string key) except+ err
+    # string annotation(string key, string default) except+ err
+
+    def setAnnotation(self, k, v):
+        AO = self._AnalysisObject()
+        set_annotation(AO, k, v)
+
+    # def hasAnnotation(self, k):
+    #     AO = self._AnalysisObject()
+    #     return AO.hasAnnotation(string(k))
+
+    # def rmAnnotation(self, k):
+    #     AO = self._AnalysisObject()
+    #     return AO.rmAnnotation(string(k))
+
+    def clearAnnotations(self):
+        AO = self._AnalysisObject()
+        AO.clearAnnotations()
+
+
+    def string(self):
+        """
+        A human readable representation of this object as it would be
+        stored in a YODA file.
+
+        """
+        f = StringIO()
+        writeYODA([self], f)
+        f.seek(0)
+        return f.read().strip()
+
     property path:
         """
         Used for persistence and as a unique identifier. Must begin with

Modified: trunk/pyext/yoda/include/Scatter2D.pyx
==============================================================================
--- trunk/pyext/yoda/include/Scatter2D.pyx	Mon Mar  4 14:02:38 2013	(r561)
+++ trunk/pyext/yoda/include/Scatter2D.pyx	Mon Mar  4 14:50:26 2013	(r562)
@@ -7,7 +7,7 @@
 
     """
 
-    cdef inline c.Scatter2D *_Scatter2D(self) except NULL:
+    cdef inline c.Scatter2D* _Scatter2D(self) except NULL:
         return <c.Scatter2D*> self.ptr()
 
     def __init__(self, *args, **kwargs):

Modified: trunk/src/ReaderAIDA.cc
==============================================================================
--- trunk/src/ReaderAIDA.cc	Mon Mar  4 14:02:38 2013	(r561)
+++ trunk/src/ReaderAIDA.cc	Mon Mar  4 14:50:26 2013	(r562)
@@ -32,6 +32,7 @@
       if (!aidaN) throw ReadError("Couldn't get <aida> root element");
       for (const TiXmlNode* dpsN = aidaN->FirstChild("dataPointSet"); dpsN; dpsN = dpsN->NextSibling()) {
         const TiXmlElement* dpsE = dpsN->ToElement();
+        assert(dpsE != 0);
         const string plotpath = dpsE->Attribute("path");
         const string plotname = dpsE->Attribute("name");
 


More information about the yoda-svn mailing list