|
[yoda-svn] r604 - in trunk: bin pyext/yoda pyext/yoda/includeblackhole at projects.hepforge.org blackhole at projects.hepforge.orgWed May 29 16:11:49 BST 2013
Author: davemallows Date: Wed May 29 16:11:48 2013 New Revision: 604 Log: Created merge-histos script and re-introduced merging to Histo1D Added: trunk/bin/merge-histos (contents, props changed) trunk/pyext/yoda/merge.hh Modified: trunk/pyext/yoda/declarations.pxd trunk/pyext/yoda/include/Histo1D.pyx Added: trunk/bin/merge-histos ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/bin/merge-histos Wed May 29 16:11:48 2013 (r604) @@ -0,0 +1,36 @@ +#!/usr/bin/python + +import yoda +import optparse +import cStringIO + +parser = optparse.OptionParser() +opts, filenames = parser.parse_args() + +class FileMerger(object): + def __init__(self): + self._objects = {} + + def merge(self, x): + existing = self._objects.get(x.path) + + if existing: + x += existing + + self._objects[x.path] = x + + @property + def objects(self): + return self._objects.itervalues() + +merger = FileMerger() + +for filename in filenames: + print filename + for i in yoda.readYODA(filename): + merger.merge(i) + +stringio = cStringIO.StringIO() +yoda.writeYODA(merger.objects, stringio) +stringio.seek(0) +print stringio.read(), Modified: trunk/pyext/yoda/declarations.pxd ============================================================================== --- trunk/pyext/yoda/declarations.pxd Tue May 28 18:25:12 2013 (r603) +++ trunk/pyext/yoda/declarations.pxd Wed May 29 16:11:48 2013 (r604) @@ -710,8 +710,11 @@ void addBin(double, double) except+ err void addBins(vector[double] edges) except+ err void eraseBin(size_t index) except+ err + #}}} Histo1D +cdef extern from "merge.hh": + void Histo1D_iadd_Histo1D "cython_iadd" (Histo1D*, Histo1D*) # Histo2D {{{ cdef extern from "YODA/Histo2D.h" namespace "YODA": Modified: trunk/pyext/yoda/include/Histo1D.pyx ============================================================================== --- trunk/pyext/yoda/include/Histo1D.pyx Tue May 28 18:25:12 2013 (r603) +++ trunk/pyext/yoda/include/Histo1D.pyx Wed May 29 16:11:48 2013 (r604) @@ -164,3 +164,9 @@ cdef double a, b for a, b in tuples: self._Histo1D().addBin(a, b) + + def __iadd__(Histo1D self, Histo1D other): + #deref(self._Histo1D()) += other._Histo1D() + c.Histo1D_iadd_Histo1D(self._Histo1D(), + other._Histo1D()) + return self Added: trunk/pyext/yoda/merge.hh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/pyext/yoda/merge.hh Wed May 29 16:11:48 2013 (r604) @@ -0,0 +1,3 @@ +template<class T1, class T2> void cython_iadd(T1 *a, T2 *b) { + *a += *b; +}
More information about the yoda-svn mailing list |