/* * writeIndexedTable.hpp * * Created on: Sep 28, 2013 * Author: heber */ #ifndef WRITEINDEXEDTABLE_HPP_ #define WRITEINDEXEDTABLE_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "Fragmentation/Summation/HeaderPrinter.hpp" #include "Fragmentation/Summation/ValuePrinter.hpp" /** Templated functor to write from a given vector of results the * table per keyset with decent header line. * * @param results vector of results of MapType * @param MaxLevel print values up till this level * @return string of the resulting table */ template struct writeIndexedTable{ std::string operator()( const std::map > &results, const size_t MaxLevel, const size_t StartLevel=1) { typedef std::map > maptype_t; std::stringstream resultstream; /// create header line for energy resultstream << "index\tlevel\tkeyset"; { HeaderPrinter header("_value"); boost::mpl::for_each(boost::ref(header)); resultstream << header.get(); } { HeaderPrinter header("_contribution"); boost::mpl::for_each(boost::ref(header)); resultstream << header.get(); } resultstream << std::endl; /// print values per line if (MaxLevel >= StartLevel) { ASSERT( results.size() >= (MaxLevel-StartLevel), "writeIndexedTable() - results has insufficient size."); size_t index = 0; for (typename maptype_t::const_iterator resultiter = results.begin(); resultiter != results.end(); ++resultiter, ++index) { resultstream << index << "\t" << resultiter->first->size() << "\t" << "{"; for (IndexSet::const_iterator keyiter = resultiter->first->begin(); keyiter != resultiter->first->end(); ++keyiter) resultstream << ( keyiter != resultiter->first->begin() ? "," : "") << *keyiter; resultstream << "}"; { ValuePrinter values(resultiter->second.first); boost::mpl::for_each(boost::ref(values)); resultstream << values.get(); } { ValuePrinter values(resultiter->second.second); boost::mpl::for_each(boost::ref(values)); resultstream << values.get(); } resultstream << std::endl; } } else { ELOG(2, "writeIndexedTable does not output as MaxLevel(" << MaxLevel << ") < StartLevel(" << StartLevel << "."); } return resultstream.str(); } }; #endif /* WRITEINDEXEDTABLE_HPP_ */