[47cee7] | 1 | /*
|
---|
| 2 | * writeIndexedTable.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Sep 28, 2013
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef WRITEINDEXEDTABLE_HPP_
|
---|
| 9 | #define WRITEINDEXEDTABLE_HPP_
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
| 17 | #include <boost/mpl/for_each.hpp>
|
---|
| 18 |
|
---|
| 19 | #include <string>
|
---|
| 20 | #include <sstream>
|
---|
| 21 | #include <vector>
|
---|
| 22 |
|
---|
| 23 | #include "Fragmentation/Summation/HeaderPrinter.hpp"
|
---|
| 24 | #include "Fragmentation/Summation/ValuePrinter.hpp"
|
---|
| 25 |
|
---|
| 26 | /** Templated functor to write from a given vector of results the
|
---|
| 27 | * table per keyset with decent header line.
|
---|
| 28 | *
|
---|
| 29 | * @param results vector of results of MapType
|
---|
| 30 | * @param MaxLevel print values up till this level
|
---|
| 31 | * @return string of the resulting table
|
---|
| 32 | */
|
---|
| 33 | template <typename MapType, typename VectorType, int numprecision=10>
|
---|
| 34 | struct writeIndexedTable{
|
---|
| 35 | std::string operator()(
|
---|
| 36 | const std::map<IndexSet::ptr, std::pair<MapType,MapType> > &results,
|
---|
| 37 | const size_t MaxLevel,
|
---|
| 38 | const size_t StartLevel=1)
|
---|
| 39 | {
|
---|
| 40 | typedef std::map<IndexSet::ptr, std::pair<MapType,MapType> > maptype_t;
|
---|
| 41 | std::stringstream resultstream;
|
---|
| 42 |
|
---|
| 43 | /// create header line for energy
|
---|
[c8d13f5] | 44 | resultstream << "index\tlevel\tkeyset";
|
---|
[47cee7] | 45 | {
|
---|
| 46 | HeaderPrinter header("_value");
|
---|
| 47 | boost::mpl::for_each<VectorType>(boost::ref(header));
|
---|
[c8d13f5] | 48 | resultstream << header.get();
|
---|
[47cee7] | 49 | }
|
---|
| 50 | {
|
---|
| 51 | HeaderPrinter header("_contribution");
|
---|
| 52 | boost::mpl::for_each<VectorType>(boost::ref(header));
|
---|
[c8d13f5] | 53 | resultstream << header.get();
|
---|
[47cee7] | 54 | }
|
---|
[c8d13f5] | 55 | resultstream << std::endl;
|
---|
[47cee7] | 56 |
|
---|
| 57 | /// print values per line
|
---|
| 58 | if (MaxLevel >= StartLevel) {
|
---|
| 59 | ASSERT( results.size() >= (MaxLevel-StartLevel),
|
---|
| 60 | "writeIndexedTable<M,V>() - results has insufficient size.");
|
---|
[c8d13f5] | 61 | size_t index = 0;
|
---|
[47cee7] | 62 | for (typename maptype_t::const_iterator resultiter = results.begin();
|
---|
[c8d13f5] | 63 | resultiter != results.end(); ++resultiter, ++index) {
|
---|
| 64 | resultstream << index << "\t" << resultiter->first->size() << "\t" << "{";
|
---|
[47cee7] | 65 | for (IndexSet::const_iterator keyiter = resultiter->first->begin();
|
---|
| 66 | keyiter != resultiter->first->end(); ++keyiter)
|
---|
| 67 | resultstream << ( keyiter != resultiter->first->begin() ? "," : "") << *keyiter;
|
---|
| 68 | resultstream << "}";
|
---|
| 69 | {
|
---|
| 70 | ValuePrinter<MapType, numprecision> values(resultiter->second.first);
|
---|
| 71 | boost::mpl::for_each<VectorType>(boost::ref(values));
|
---|
| 72 | resultstream << values.get();
|
---|
| 73 | }
|
---|
| 74 | {
|
---|
| 75 | ValuePrinter<MapType, numprecision> values(resultiter->second.second);
|
---|
| 76 | boost::mpl::for_each<VectorType>(boost::ref(values));
|
---|
| 77 | resultstream << values.get();
|
---|
| 78 | }
|
---|
| 79 | resultstream << std::endl;
|
---|
| 80 | }
|
---|
| 81 | } else {
|
---|
| 82 | ELOG(2, "writeIndexedTable does not output as MaxLevel(" << MaxLevel
|
---|
| 83 | << ") < StartLevel(" << StartLevel << ".");
|
---|
| 84 | }
|
---|
| 85 | return resultstream.str();
|
---|
| 86 | }
|
---|
| 87 | };
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | #endif /* WRITEINDEXEDTABLE_HPP_ */
|
---|