Index: src/Fragmentation/Summation/Makefile.am
===================================================================
--- src/Fragmentation/Summation/Makefile.am	(revision c6ca23fe871942ffe00849bb181ca2fe88d7bc94)
+++ src/Fragmentation/Summation/Makefile.am	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
@@ -14,8 +14,12 @@
 	Fragmentation/Summation/printKeyNames.hpp \
 	Fragmentation/Summation/printOrthogonalSum.hpp \
+	Fragmentation/Summation/printSum.hpp \
 	Fragmentation/Summation/SetValue.hpp \
 	Fragmentation/Summation/SetValueMap.hpp \
 	Fragmentation/Summation/SortedVector.hpp \
-	Fragmentation/Summation/SubsetMap.hpp
+	Fragmentation/Summation/SubsetMap.hpp \
+	Fragmentation/Summation/Summation.hpp \
+	Fragmentation/Summation/Summation_impl.hpp \
+	Fragmentation/Summation/Summator.hpp
 
 
Index: src/Fragmentation/Summation/SetValue.hpp
===================================================================
--- src/Fragmentation/Summation/SetValue.hpp	(revision c6ca23fe871942ffe00849bb181ca2fe88d7bc94)
+++ src/Fragmentation/Summation/SetValue.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
@@ -34,4 +34,6 @@
   //!> grant OrthogonalSummation access to static lookup functions
   template <class TT> friend class OrthogonalSummation;
+  //!> grant Summation access to static lookup functions
+  template <class TT> friend class Summation;
 public:
   typedef boost::shared_ptr< SetValue<T> > ptr;
Index: src/Fragmentation/Summation/Summation.hpp
===================================================================
--- src/Fragmentation/Summation/Summation.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
+++ src/Fragmentation/Summation/Summation.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
@@ -0,0 +1,60 @@
+/*
+ * Summation.hpp
+ *
+ *  Created on: Jun 30, 2012
+ *      Author: heber
+ */
+
+#ifndef SUMMATION_HPP_
+#define SUMMATION_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <map>
+
+#include "SetValue.hpp"
+#include "SubsetMap.hpp"
+#include "SetValueMap.hpp"
+
+/** Summation is a functor executing a simple summation of SetValue's
+ * that are each associated to a certain IndexSet whose union is a SetOfIndexSets.
+ *
+ * This is kept in signature alike to OrthogonalSummation.
+ *
+ *  For the given class we require the following functions:
+ *  -# operator=(): assignment operator for placement in vector
+ *  -# operator+=(): addition operator for adding one instance from another
+ *  -# operator-=(): subtraction operator for subtracting one instance from another
+ *  -# operator<<(): output operator
+ */
+template <class T>
+class Summation
+{
+public:
+  typedef std::vector< IndexSet::ptr > InputSets_t;
+  typedef std::vector< T > InputValues_t;
+  Summation(InputSets_t &indices, InputValues_t& values, SubsetMap::ptr _subsetmap = SubsetMap::ptr());
+
+  /** Performs the summation and returns result.
+   *
+   * @return resulting value
+   */
+  T operator()() const;
+
+private:
+  T Sum() const;
+
+private:
+  //!> SubsetTree with the tree-like structure of subsets
+  SubsetMap::ptr subsetmap;
+  //!> set of all subset values
+  SetValueMap<T> setvalues;
+};
+
+#include "Summation_impl.hpp"
+
+#endif /* SUMMATION_HPP_ */
Index: src/Fragmentation/Summation/Summation_impl.hpp
===================================================================
--- src/Fragmentation/Summation/Summation_impl.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
+++ src/Fragmentation/Summation/Summation_impl.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
@@ -0,0 +1,81 @@
+/*
+ * Summation_impl.hpp
+ *
+ *  Created on: Jun 30, 2012
+ *      Author: heber
+ */
+
+#ifndef SUMMATION_IMPL_HPP_
+#define SUMMATION_IMPL_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/IteratorAdaptors.hpp"
+#include "CodePatterns/Log.hpp"
+
+/** Constructor of class Summation.
+ *
+ */
+template <class T>
+Summation<T>::Summation(
+    InputSets_t &indices,
+    InputValues_t& values,
+    SubsetMap::ptr _subsetmap) :
+  subsetmap(_subsetmap)
+{
+  ASSERT( indices.size() == values.size(),
+      "Summation<T>::Summation() - indices and values mismatch in size: "
+      +toString(indices.size())+" != "+toString(values.size())+".");
+  /// place each index
+  /// create own map if none is given
+  if (!subsetmap) {
+    typename InputSets_t::iterator iter = indices.begin();
+    IndexSetContainer container(*iter);
+    for (; iter != indices.end(); ++iter)
+      container.insert(*iter);
+    subsetmap.reset(new SubsetMap(container));
+  } else {
+    LOG(1, "INFO: Using given SubsetMap.");
+  }
+  /// instantiate all SubSetValue's by requesting the IndexSet from the Subsetmap
+  typename InputSets_t::iterator indexiter = indices.begin();
+  typename InputValues_t::iterator valueiter = values.begin();
+  for (;valueiter != values.end(); ++indexiter, ++valueiter) {
+    LOG(1, "INFO: Adding set " << **indexiter << " with value " << *valueiter << ".");
+    setvalues.addValue( *indexiter, *valueiter );
+  }
+  /// bind static lookup functions for SetValue<T>
+  SetValue<T>::lookupSubset =
+      boost::bind(&SubsetMap::getSubsets, boost::ref(*subsetmap), _1);
+  SetValue<T>::lookupValue =
+      boost::bind(&SetValueMap<T>::getValue, boost::ref(setvalues), _1);
+}
+
+template <class T>
+T Summation<T>::operator()() const
+{
+  return Sum();
+}
+
+template <class T>
+T Summation<T>::Sum() const
+{
+  typename SetValueMap<T>::const_iterator iter = setvalues.begin();
+  T sum = (iter->second)->getValue();
+  LOG(1, "DEBUG: Value from subset "+toString(*(iter->second->getIndexSet()))
+      +" is "+toString(sum)+".");
+  for(++iter;iter != setvalues.end(); ++iter) {
+    const T tempvalue = (iter->second)->getValue();
+    sum += tempvalue;
+    LOG(1, "DEBUG: Value from subset "+toString(*(iter->second->getIndexSet()))
+        +" is "+toString(tempvalue)+".");
+  }
+  return sum;
+}
+
+
+#endif /* SUMMATION_IMPL_HPP_ */
Index: src/Fragmentation/Summation/Summator.hpp
===================================================================
--- src/Fragmentation/Summation/Summator.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
+++ src/Fragmentation/Summation/Summator.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
@@ -0,0 +1,131 @@
+/*
+ * Summator.hpp
+ *
+ *  Created on: 28.07.2012
+ *      Author: heber
+ */
+
+#ifndef SUMMATOR_HPP_
+#define SUMMATOR_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <boost/fusion/sequence.hpp>
+
+#include "Fragmentation/Summation/Summation.hpp"
+#include "Fragmentation/Summation/SetValue.hpp"
+#include "Jobs/MPQCDataMap.hpp"
+
+/** Summator is a general class for making us of OrthogonalSummation.
+ *
+ * The idea is that we want to sum up not only one value but a whole bunch of.
+ * However, in general the types of the values will all differ. We would like
+ * to call the summation in a as simple a fashion as possible and at best in
+ * a kind of for_each on each type/value.
+ * For this purpose we require a list of all the types, represented  by the
+ * MPQCDataMap_t map that uses the types enumerated in namespace MPQCDataFused,
+ * see the simple example for the associative sequence in boost::fusion.
+ * The MPQCDataMap_t then gives the essential mapping from the type to a specific
+ * key. Via this key, which is a type and hence can be used for template
+ * specification, we may gather all information for launching the
+ * OrthogonalSummation. We only need to convert MPQCData into the above
+ * MPQCDataMap_t instance and may then access the member variables via the above
+ * key and also obtain the type at \b run-time through the key.
+ *
+ * Note that we then need a conversion from the type stored in the MPQCData,
+ * e.g. a vector<double>, to the type in MPQCDataMap_t, e.g. Histogram.
+ *
+ * Boost::fusion is very cool! If we have a namespace with just structs as keys
+ * and the fusion::map from these keys to the true types, then we may do ...
+ * \code
+ *   MPQCDataMap_t MPQCDataMap;
+ *   using namespace MPQCDataFused;
+ *   double MPQCData_energy_total = boost::fusion::at_key<MPQCDataFused::energy_total>(MPQCDataMap);
+ * \endcode
+ * i.e. at_key knows the correct type!
+ *
+ */
+template <typename MapType, typename MapKey>
+struct Summator {
+  /** We retrieve the type of the MPQCData member variable from the
+   * boost::fusion::map and stored it in this typedef. Note that for
+   * internal types (e.g. MapValue::const_iterator we need to place
+   * \b typename before).
+   */
+  typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
+
+  /** Constructor for class Summator.
+   *
+   * \param _subsetmap map with hierarchy of IndexSet's
+   * \param _data MPQCData converted to MPQCDataMap_t type
+   * \param _jobids job ids to sum data in correct order
+   * \param _container container of IndexSet's such that each set has correct order
+   *        to job id and hence to _data.
+   * \param _MatrixNrLookup lookup from job id to ordering in above vectors
+   */
+  Summator(
+      SubsetMap::ptr &_subsetmap,
+      const std::vector<MapType> &_data,
+      const std::vector<JobId_t> &_jobids,
+      const IndexSetContainer::Container_t &_container,
+      std::map< JobId_t, size_t > &_MatrixNrLookup) : /* cannot make this const due to operator[] */
+    subsetmap(_subsetmap),
+    data(_data),
+    jobids(_jobids),
+    container(_container),
+    MatrixNrLookup(_MatrixNrLookup)
+  {
+    ASSERT( data.size() == jobids.size(),
+        "Summator() - data and ids don't have same size.");
+    ASSERT( jobids.size() == MatrixNrLookup.size(),
+        "Summator() - ids and MatrixNrLookup don't have same size.");
+  }
+
+  /** Summation operator.
+   *
+   * Initialises instantiated OrthogonalSummation of the respective type via
+   * \a Summator::data, uses OrthogonalSummation::operator() to sum and returns
+   * the result.
+   *
+   * \return result of OrthogonalSummation for given type from MPQCDataMap_t.
+   */
+  MapValue operator()()
+  {
+    // if we just have one indexset, we don't need to get rid of the "union index set"
+    typename Summation<MapValue>::InputSets_t indices(
+        container.begin(),
+        container.end()-1 == container.begin() ? container.end() : container.end()-1);
+    typename Summation<MapValue>::InputValues_t values(
+        container.size() == 1 ? (size_t)1 : container.size()-1);
+    typename std::vector<MapType>::const_iterator dataiter = data.begin();
+    std::vector<size_t>::const_iterator iditer = jobids.begin();
+    for (; dataiter != data.end(); ++dataiter, ++iditer) {
+      const MapType &Data = *dataiter;
+      const MapValue &value = boost::fusion::at_key<MapKey>(Data);
+      values[ MatrixNrLookup[*iditer] ] = value;
+    }
+
+    // create the summation functor and evaluate
+    Summation<MapValue> OS(indices, values, subsetmap);
+    const MapValue result = OS();
+    return result;
+  }
+
+private:
+  //!> Hierarchy of IndexSet's
+  SubsetMap::ptr &subsetmap;
+  //!> vector of data converted from MPQCData
+  const std::vector<MapType> &data;
+  //!> vector of jobids
+  const std::vector<JobId_t> &jobids;
+  //!> container with all IndexSet's
+  const IndexSetContainer::Container_t &container;
+  //!> lookup map from job ids to ordering in above vectors
+  std::map< JobId_t, size_t > MatrixNrLookup;
+};
+
+
+#endif /* SUMMATOR_HPP_ */
Index: src/Fragmentation/Summation/printSum.hpp
===================================================================
--- src/Fragmentation/Summation/printSum.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
+++ src/Fragmentation/Summation/printSum.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
@@ -0,0 +1,84 @@
+/*
+ * printSum.hpp
+ *
+ *  Created on: 29.07.2012
+ *      Author: heber
+ */
+
+#ifndef PRINTSUM_HPP_
+#define PRINTSUM_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <vector>
+
+#include "Fragmentation/Summation/IndexSetContainer.hpp"
+#include "Fragmentation/Summation/SubsetMap.hpp"
+#include "Fragmentation/Summation/Summator.hpp"
+
+#include "Fragmentation/Summation/printKeyNames.hpp"
+
+/** Tiny template functor to use OrthogonalSummation, sum up and print the result.
+ *
+ */
+template <typename MapType>
+struct printSum {
+  /** Constructor takes the arguments that \a Summator also needs and stores
+   * them internally.
+   *
+   * \param _subsetmap map with hierarchy of IndexSet's
+   * \param _data MPQCData converted to MPQCDataMap_t type
+   * \param _jobids job ids to sum data in correct order
+   * \param _container container of IndexSet's such that each set has correct order
+   *        to job id and hence to _data.
+   * \param _MatrixNrLookup lookup from job id to ordering in above vectors
+   */
+  printSum(
+      SubsetMap::ptr &_subsetmap,
+      const std::vector<MapType> &_data,
+      const std::vector<JobId_t> &_jobids,
+      const IndexSetContainer::Container_t &_container,
+      std::map< JobId_t, size_t > &_MatrixNrLookup) : /* cannot make this const due to operator[] */
+    subsetmap(_subsetmap),
+    data(_data),
+    jobids(_jobids),
+    container(_container),
+    MatrixNrLookup(_MatrixNrLookup)
+  {}
+
+  /** Operator that calls on Summator and prints the value.
+   *
+   * \note the parameter is needed for boost::mpl::for_each but is not
+   * used here.
+   */
+  template <typename MapKey>
+  void operator()(MapKey &) {
+    // We retrieve the type of the MPQCData member variable from the boost::fusion::map.
+    typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
+    // create Summator instance
+    Summator<MapType, MapKey> sum_value(
+        subsetmap, data, jobids, container, MatrixNrLookup
+        );
+    // sum up
+    MapValue value = sum_value();
+    // print value
+    LOG(0, "STATUS: Resulting " << printKeyNames::printName<MapKey>() << " is " << value << ".");
+  }
+
+private:
+  //!> Hierarchy of IndexSet's
+  SubsetMap::ptr &subsetmap;
+  //!> vector of data converted from MPQCData
+  const std::vector<MapType> &data;
+  //!> vector of jobids
+  const std::vector<JobId_t> &jobids;
+  //!> container with all IndexSet's
+  const IndexSetContainer::Container_t &container;
+  //!> lookup map from job ids to ordering in above vectors
+  std::map< JobId_t, size_t > MatrixNrLookup;
+};
+
+#endif /* PRINTSUM_HPP_ */
Index: src/Fragmentation/Summation/unittests/Makefile.am
===================================================================
--- src/Fragmentation/Summation/unittests/Makefile.am	(revision c6ca23fe871942ffe00849bb181ca2fe88d7bc94)
+++ src/Fragmentation/Summation/unittests/Makefile.am	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
@@ -8,5 +8,6 @@
 	../Fragmentation/Summation/unittests/SetValueUnitTest.cpp \
 	../Fragmentation/Summation/unittests/SetValueMapUnitTest.cpp \
-	../Fragmentation/Summation/unittests/SubsetMapUnitTest.cpp
+	../Fragmentation/Summation/unittests/SubsetMapUnitTest.cpp \
+	../Fragmentation/Summation/unittests/SummationUnitTest.cpp
 
 FRAGMENTATIONSUMMATIONTESTSHEADERS = \
@@ -16,5 +17,6 @@
 	../Fragmentation/Summation/unittests/SetValueUnitTest.hpp \
 	../Fragmentation/Summation/unittests/SetValueMapUnitTest.hpp \
-	../Fragmentation/Summation/unittests/SubsetMapUnitTest.hpp
+	../Fragmentation/Summation/unittests/SubsetMapUnitTest.hpp \
+	../Fragmentation/Summation/unittests/SummationUnitTest.hpp
 
 FRAGMENTATIONSUMMATIONTESTS = \
@@ -24,5 +26,6 @@
   SetValueUnitTest \
   SetValueMapUnitTest \
-  SubsetMapUnitTest
+  SubsetMapUnitTest \
+  SummationUnitTest
 
 TESTS += $(FRAGMENTATIONSUMMATIONTESTS)
@@ -70,4 +73,11 @@
 SubsetMapUnitTest_LDADD = ${FRAGMENTATIONSUMMATIONLIBS}
 
+SummationUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
+	../Fragmentation/Summation/unittests/SummationUnitTest.cpp \
+	../Fragmentation/Summation/unittests/SummationUnitTest.hpp \
+	../Fragmentation/Summation/Summation.hpp \
+	../Fragmentation/Summation/Summation_impl.hpp
+SummationUnitTest_LDADD = ${FRAGMENTATIONSUMMATIONLIBS}
+
 
 #AUTOMAKE_OPTIONS = parallel-tests
Index: src/Fragmentation/Summation/unittests/SummationUnitTest.cpp
===================================================================
--- src/Fragmentation/Summation/unittests/SummationUnitTest.cpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
+++ src/Fragmentation/Summation/unittests/SummationUnitTest.cpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
@@ -0,0 +1,109 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * SummationUnitTest.cpp
+ *
+ *  Created on: Jun 30, 2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+using namespace std;
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include "SummationUnitTest.hpp"
+
+#include "Fragmentation/Summation/Summation.hpp"
+#include "Fragmentation/Summation/SetValue.hpp"
+
+#include <algorithm>
+#include <boost/assign.hpp>
+
+#include "CodePatterns/Log.hpp"
+
+#ifdef HAVE_TESTRUNNER
+#include "UnitTestMain.hpp"
+#endif /*HAVE_TESTRUNNER*/
+
+using namespace boost::assign;
+
+/********************************************** Test classes **************************************/
+
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( SummationTest );
+
+void SummationTest::setUp()
+{
+  // failing asserts should be thrown
+  ASSERT_DO(Assert::Throw);
+
+  setVerbosity(5);
+
+  // create a tree of sets
+  IndexSet::ptr AllIndices(new IndexSet);
+  (*AllIndices) += 1,2,3,4;
+  CPPUNIT_ASSERT_EQUAL( (size_t)4, AllIndices->size() );
+  container.reset(new IndexSetContainer(AllIndices));
+  CPPUNIT_ASSERT_EQUAL( (size_t)1, container->getContainer().size() );
+  IndexSet tempset;
+  tempset += 1;
+  container->insert(tempset);
+  tempset += 2;
+  container->insert(tempset);
+  tempset.clear();
+  tempset += 3;
+  container->insert(tempset);
+  tempset += 2;
+  container->insert(tempset);
+  CPPUNIT_ASSERT_EQUAL( (size_t)5, container->getContainer().size() );
+  subsetmap.reset(new SubsetMap(*container));
+}
+
+
+void SummationTest::tearDown()
+{
+}
+
+/** UnitTest for operator()
+ */
+void SummationTest::operator_staticTest()
+{
+  const IndexSetContainer::Container_t &_container = container->getContainer();
+  for (int value = -5; value <= 5; ++value) {
+    // create a value for each set (and copy indices to overcome constness in container)
+    Summation<int>::InputSets_t indices(_container.begin(), _container.end());
+    Summation<int>::InputValues_t values(_container.size(), value);
+    // create the summation functor
+    Summation<int> OS(indices, values, subsetmap);
+
+    // sum up, as full set is contained we must get value again
+    CPPUNIT_ASSERT_EQUAL( (int)(value * _container.size()), OS() );
+  }
+}
Index: src/Fragmentation/Summation/unittests/SummationUnitTest.hpp
===================================================================
--- src/Fragmentation/Summation/unittests/SummationUnitTest.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
+++ src/Fragmentation/Summation/unittests/SummationUnitTest.hpp	(revision 092be05641d86ffa7806dfa77f2c1245d91a22c7)
@@ -0,0 +1,41 @@
+/*
+ * SummationUnitTest.hpp
+ *
+ *  Created on: Jun 30, 2012
+ *      Author: heber
+ */
+
+#ifndef SUMMATIONUNITTEST_HPP_
+#define SUMMATIONUNITTEST_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "Fragmentation/Summation/IndexSetContainer.hpp"
+#include "Fragmentation/Summation/SubsetMap.hpp"
+
+
+/********************************************** Test classes **************************************/
+
+class SummationTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( SummationTest) ;
+    CPPUNIT_TEST ( operator_staticTest );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+      void setUp();
+      void tearDown();
+      void operator_staticTest();
+
+private:
+      SubsetMap::ptr subsetmap;
+      IndexSetContainer::ptr container;
+};
+
+#endif /* SUMMATIONUNITTEST_HPP_ */
