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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Fri Mar 15 14:06:47 GMT 2013


Author: buckley
Date: Fri Mar 15 14:06:47 2013
New Revision: 577

Log:
Re-organising the C++ side of the auto-format I/O functions, into a new IO header and separated from the Reader.h and Writer.h. I'm tempted to say that users shouldn't really NEED to ever directly touch the Reader and Writer objects...

Added:
   trunk/include/YODA/IO.h
Modified:
   trunk/ChangeLog
   trunk/include/YODA/Makefile.am
   trunk/include/YODA/Reader.h
   trunk/include/YODA/Writer.h
   trunk/pyext/yoda/declarations.pxd
   trunk/src/Reader.cc
   trunk/src/Writer.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Fri Mar 15 09:58:06 2013	(r576)
+++ trunk/ChangeLog	Fri Mar 15 14:06:47 2013	(r577)
@@ -1,5 +1,10 @@
 2013-03-15  Andy Buckley  <andy.buckley at cern.ch>
 
+	* Re-organising the C++ side of the auto-format I/O functions,
+	into a new IO header and separated from the Reader.h and
+	Writer.h. I'm tempted to say that users shouldn't really NEED to
+	ever directly touch the Reader and Writer objects...
+
 	* Adding auto-format read and write functions. I will probably
 	change the API. Python mappings have been provided, but the string
 	workarounds were too much of a pain with Cython 0.16 so I have

Added: trunk/include/YODA/IO.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/include/YODA/IO.h	Fri Mar 15 14:06:47 2013	(r577)
@@ -0,0 +1,74 @@
+// -*- C++ -*-
+//
+// This file is part of YODA -- Yet more Objects for Data Analysis
+// Copyright (C) 2008-2013 The YODA collaboration (see AUTHORS for details)
+//
+#ifndef YODA_IO_h
+#define YODA_IO_h
+
+#include "YODA/Writer.h"
+#include "YODA/Reader.h"
+
+namespace YODA {
+
+
+  /// @name Writer functions with automatic format detection
+  //@{
+
+  /// Write out object @a ao to file @a filename
+  void write(const std::string& filename, const AnalysisObject& ao) {
+    Writer& w = mkWriter(filename);
+    w.write(filename, ao);
+  }
+
+  /// Write out a collection of objects @a objs to file @a filename.
+  template <typename RANGE>
+  void write(const std::string& filename, const RANGE& aos) {
+    Writer& w = mkWriter(filename);
+    w.write(filename, aos);
+  }
+
+  /// Write out the objects specified by start iterator @a begin and end
+  /// iterator @a end to file @a filename.
+  template <typename AOITER>
+  void write(const std::string& filename, const AOITER& begin, const AOITER& end) {
+    Writer& w = mkWriter(filename);
+    w.write(filename, begin, end);
+  }
+
+  //@}
+
+
+  /// @name Reader functions with automatic format detection
+  //@{
+
+  /// @brief Read in a collection of objects @a objs from file @a filename.
+  ///
+  /// This version fills (actually, appends to) a supplied vector, avoiding
+  /// copying, and is hence CPU efficient. The appropriate format reader will
+  /// be determined from the filename.
+  ///
+  /// @todo Use SFINAE magic to allow ~arbitrary collection<AnalysisObject*> (with push_back()?) to be passed
+  void read(const std::string& filename, std::vector<AnalysisObject*>& aos) {
+    Reader& r = mkReader(filename);
+    r.read(filename, aos);
+  }
+
+  /// @brief Read in a collection of objects from output stream @a stream.
+  ///
+  /// This version returns a vector by value, involving copying, and is hence
+  /// less CPU efficient than the alternative version where a vector is filled
+  /// by reference. The appropriate format reader will be determined from the
+  /// filename.
+  std::vector<AnalysisObject*> read(const std::string& filename) {
+    std::vector<AnalysisObject*> rtn;
+    readFrom(filename, rtn);
+    return rtn;
+  }
+
+  //@}
+
+
+}
+
+#endif

Modified: trunk/include/YODA/Makefile.am
==============================================================================
--- trunk/include/YODA/Makefile.am	Fri Mar 15 09:58:06 2013	(r576)
+++ trunk/include/YODA/Makefile.am	Fri Mar 15 14:06:47 2013	(r577)
@@ -14,7 +14,7 @@
     ScatterND.h PointND.h ErrorND.h \
     Writer.h WriterAIDA.h WriterFLAT.h WriterYODA.h \
     Reader.h ReaderAIDA.h ReaderYODA.h \
-	ROOTCnv.h
+    IO.h ROOTCnv.h
 
 nobase_pkginclude_HEADERS = \
 	WriterMethods.icc \

Modified: trunk/include/YODA/Reader.h
==============================================================================
--- trunk/include/YODA/Reader.h	Fri Mar 15 09:58:06 2013	(r576)
+++ trunk/include/YODA/Reader.h	Fri Mar 15 14:06:47 2013	(r577)
@@ -72,43 +72,11 @@
     //@}
 
 
-    /// @name Static functions with automatic format detection
-    //@{
-
-    /// Factory function to make a writer object by format name or a filename
-    static Reader& makeReader(const std::string& format_name);
+  };
 
-    /// @brief Read in a collection of objects @a objs from file @a filename.
-    ///
-    /// This version fills (actually, appends to) a supplied vector, avoiding
-    /// copying, and is hence CPU efficient. The appropriate format reader will
-    /// be determined from the filename.
-    ///
-    /// @todo Use SFINAE magic to allow ~arbitrary collection<AnalysisObject*> (with push_back()?) to be passed
-    ///
-    /// @todo Better naming?
-    static void readFrom(const std::string& filename, std::vector<AnalysisObject*>& aos) {
-      Reader& r = makeReader(filename);
-      r.read(filename, aos);
-    }
-
-    /// @brief Read in a collection of objects from output stream @a stream.
-    ///
-    /// This version returns a vector by value, involving copying, and is hence
-    /// less CPU efficient than the alternative version where a vector is filled
-    /// by reference. The appropriate format reader will be determined from the
-    /// filename.
-    ///
-    /// @todo Better naming?
-    static std::vector<AnalysisObject*> readFrom(const std::string& filename) {
-      std::vector<AnalysisObject*> rtn;
-      readFrom(filename, rtn);
-      return rtn;
-    }
 
-    //@}
-
-  };
+  /// Factory function to make a writer object by format name or a filename
+  Reader& mkReader(const std::string& format_name);
 
 
 }

Modified: trunk/include/YODA/Writer.h
==============================================================================
--- trunk/include/YODA/Writer.h	Fri Mar 15 09:58:06 2013	(r576)
+++ trunk/include/YODA/Writer.h	Fri Mar 15 14:06:47 2013	(r577)
@@ -89,42 +89,6 @@
     //@}
 
 
-    /// @name Static functions with automatic format detection
-    //@{
-
-    /// Factory function to make a writer object by format name or a filename
-    static Writer& makeWriter(const std::string& format_name);
-
-    /// Write out object @a ao to file @a filename
-    ///
-    /// @todo Better naming?
-    static void writeTo(const std::string& filename, const AnalysisObject& ao) {
-      Writer& w = makeWriter(filename);
-      w.write(filename, ao);
-    }
-
-    /// Write out a collection of objects @a objs to file @a filename.
-    ///
-    /// @todo Better naming?
-    template <typename RANGE>
-    static void writeTo(const std::string& filename, const RANGE& aos) {
-      Writer& w = makeWriter(filename);
-      w.write(filename, aos);
-    }
-
-    /// Write out the objects specified by start iterator @a begin and end
-    /// iterator @a end to file @a filename.
-    ///
-    /// @todo Better naming?
-    template <typename AOITER>
-    static void writeTo(const std::string& filename, const AOITER& begin, const AOITER& end) {
-      Writer& w = makeWriter(filename);
-      w.write(filename, begin, end);
-    }
-
-    //@}
-
-
     /// Set precision of numerical quantities in this writer's output.
     void setPrecision(int precision) {
       _precision = precision;
@@ -152,6 +116,10 @@
   };
 
 
+  /// Factory function to make a writer object by format name or a filename
+  Writer& mkWriter(const std::string& format_name);
+
+
 }
 
 #endif

Modified: trunk/pyext/yoda/declarations.pxd
==============================================================================
--- trunk/pyext/yoda/declarations.pxd	Fri Mar 15 09:58:06 2013	(r576)
+++ trunk/pyext/yoda/declarations.pxd	Fri Mar 15 14:06:47 2013	(r577)
@@ -814,7 +814,7 @@
     Reader& ReaderAIDA_create "YODA::ReaderAIDA::create" ()
 
 cdef extern from "YODA/Reader.h" namespace "YODA":
-    Reader& Reader_create "YODA::Reader::makeReader" (string& filename)
+    Reader& Reader_create "YODA::mkReader" (string& filename)
 
 
 cdef extern from "YODA/Writer.h" namespace "YODA":
@@ -831,7 +831,7 @@
     Writer& WriterAIDA_create "YODA::WriterAIDA::create" ()
 
 cdef extern from "YODA/Reader.h" namespace "YODA":
-    Writer& Writer_create "YODA::Writer::makeWriter" (string& filename)
+    Writer& Writer_create "YODA::mkWriter" (string& filename)
 
 # Streams }}}
 

Modified: trunk/src/Reader.cc
==============================================================================
--- trunk/src/Reader.cc	Fri Mar 15 09:58:06 2013	(r576)
+++ trunk/src/Reader.cc	Fri Mar 15 14:06:47 2013	(r577)
@@ -12,7 +12,7 @@
 namespace YODA {
 
 
-  Reader& Reader::makeReader(const string& name) {
+  Reader& mkReader(const string& name) {
     const size_t lastdot = name.find_last_of(".");
     const string fmt = boost::to_lower_copy((lastdot == string::npos) ? name : name.substr(lastdot+1));
     if (fmt == "yoda") return ReaderYODA::create();

Modified: trunk/src/Writer.cc
==============================================================================
--- trunk/src/Writer.cc	Fri Mar 15 09:58:06 2013	(r576)
+++ trunk/src/Writer.cc	Fri Mar 15 14:06:47 2013	(r577)
@@ -17,7 +17,7 @@
 namespace YODA {
 
 
-  Writer& Writer::makeWriter(const std::string& name) {
+  Writer& mkWriter(const std::string& name) {
     const size_t lastdot = name.find_last_of(".");
     const string fmt = boost::to_lower_copy((lastdot == std::string::npos) ? name : name.substr(lastdot+1));
     if (fmt == "yoda") return WriterYODA::create();


More information about the yoda-svn mailing list