[yoda-svn] r596 - in trunk: . pyext/yoda/include

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Apr 23 15:08:29 BST 2013


Author: buckley
Date: Tue Apr 23 15:08:29 2013
New Revision: 596

Log:
Adding Python output handling for single AOs and to be able to use a '-' filename to mean stdout.

Modified:
   trunk/ChangeLog
   trunk/pyext/yoda/include/IO.pyx

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Fri Apr 12 15:52:12 2013	(r595)
+++ trunk/ChangeLog	Tue Apr 23 15:08:29 2013	(r596)
@@ -1,3 +1,8 @@
+2013-04-23  Andy Buckley  <andy.buckley at cern.ch>
+
+	* Adding Python output handling for single AOs and to be able to
+	use a "-" filename to mean stdout.
+
 2013-04-12  Andy Buckley  <andy.buckley at cern.ch>
 
 	* Releasing version 1.0.0 -- it seems stable enough.

Modified: trunk/pyext/yoda/include/IO.pyx
==============================================================================
--- trunk/pyext/yoda/include/IO.pyx	Fri Apr 12 15:52:12 2013	(r595)
+++ trunk/pyext/yoda/include/IO.pyx	Tue Apr 23 15:08:29 2013	(r596)
@@ -7,6 +7,9 @@
 # idea than just "give this a filename", and well worth the inefficiencies and
 # potential memory limits.
 
+import sys
+
+
 cdef list aobjects_to_list(vector[c.AnalysisObject*] *aobjects):
     cdef list out = []
     cdef c.AnalysisObject *ao
@@ -97,11 +100,22 @@
     cdef c.ostringstream oss
     cdef vector[c.AnalysisObject*] vec
     cdef AnalysisObject a
-    for a in ana_objs:
+
+    try:
+        for a in ana_objs:
+            vec.push_back(a._AnalysisObject())
+    except:
+        a = ana_objs
         vec.push_back(a._AnalysisObject())
+
+    # Most of the time we just won't care about memory
     c.Writer_create(filename).write(oss, vec)
-    with open(filename, 'w') as f:
-        f.write(oss.str())
+
+    if filename == "-":
+        sys.stdout.write(oss.str().c_str())
+    else:
+        with open(filename, 'w') as f:
+            f.write(oss.str().c_str())
 
 
 def writeYODA(ana_objs, file_or_filename):
@@ -112,18 +126,25 @@
     cdef vector[c.AnalysisObject*] vec
     cdef AnalysisObject a
 
-    for a in ana_objs:
+    try:
+        for a in ana_objs:
+            vec.push_back(a._AnalysisObject())
+    except:
+        a = ana_objs
         vec.push_back(a._AnalysisObject())
 
     # Most of the time we just won't care about memory
-    # Perhaps speak with andy re: huge files
     c.WriterYODA_create().write(oss, vec)
 
     if hasattr(file_or_filename, 'write'):
         file_or_filename.write(oss.str().c_str())
     else:
-        with open(file_or_filename, 'w') as f:
-            f.write(oss.str().c_str())
+        fname = file_or_filename
+        if fname == "-":
+            sys.stdout.write(oss.str().c_str())
+        else:
+            with open(fname, 'w') as f:
+                f.write(oss.str().c_str())
 
 
 def writeFLAT(ana_objs, file_or_filename):
@@ -134,18 +155,25 @@
     cdef vector[c.AnalysisObject*] vec
     cdef AnalysisObject a
 
-    for a in ana_objs:
+    try:
+        for a in ana_objs:
+            vec.push_back(a._AnalysisObject())
+    except:
+        a = ana_objs
         vec.push_back(a._AnalysisObject())
 
     # Most of the time we just won't care about memory
-    # Perhaps speak with andy re: huge files
     c.WriterFLAT_create().write(oss, vec)
 
     if hasattr(file_or_filename, 'write'):
         file_or_filename.write(oss.str().c_str())
     else:
-        with open(file_or_filename, 'w') as f:
-            f.write(oss.str().c_str())
+        fname = file_or_filename
+        if fname == "-":
+            sys.stdout.write(oss.str().c_str())
+        else:
+            with open(fname, 'w') as f:
+                f.write(oss.str().c_str())
 
 
 def writeAIDA(ana_objs, file_or_filename):
@@ -156,15 +184,22 @@
     cdef vector[c.AnalysisObject*] vec
     cdef AnalysisObject a
 
-    for a in ana_objs:
+    try:
+        for a in ana_objs:
+            vec.push_back(a._AnalysisObject())
+    except:
+        a = ana_objs
         vec.push_back(a._AnalysisObject())
 
     # Most of the time we just won't care about memory
-    # Perhaps speak with andy re: huge files
     c.WriterAIDA_create().write(oss, vec)
 
     if hasattr(file_or_filename, 'write'):
         file_or_filename.write(oss.str().c_str())
     else:
-        with open(file_or_filename, 'w') as f:
-            f.write(oss.str().c_str())
+        fname = file_or_filename
+        if fname == "-":
+            sys.stdout.write(oss.str().c_str())
+        else:
+            with open(fname, 'w') as f:
+                f.write(oss.str().c_str())


More information about the yoda-svn mailing list