// // average_container.h // mc_electron // // Created by Christian Reiling on 10.05.19. // Copyright © 2019 Christian Reiling. All rights reserved. // #ifndef average_container_h #define average_container_h #include "edge_container.h" template class Average_Container : public Base_Container { public: Average_Container() : Base_Container() {} Average_Container(std::string load_path) : Base_Container(load_path) {} Average_Container(const Edge_Container &edgeContainer) {calcMap(edgeContainer);}; public: void calcMap(const Edge_Container &edgeContainer); private: void rec_calcMap(const double &subMap, std::deque Points); template void rec_calcMap(const T &subMapm, std::deque Points); public: double get_value(std::deque point); }; template void Average_Container::calcMap(const Edge_Container &edgeContainer) { T_Map edgeMap = edgeContainer.getMap(); if (edgeMap.empty()) { std::stringstream ss; ss<<"Average_Container::calcMap: Input Edge_Container empty.\n"; throw MyException(ss.str()); } Base_Container::Map.clear(); std::deque Points; rec_calcMap(edgeMap, Points); } template void Average_Container::rec_calcMap(const double &subMap, std::deque Points) { Points.push_back(subMap); Base_Container::addPoint(Points); } template template void Average_Container::rec_calcMap(const T &subMap, std::deque Points) { double curVal, nextVal, avgVal; typename T::const_iterator curItr, nextItr; for (nextItr = ++(subMap.cbegin()); nextItr!= subMap.cend(); nextItr++) { curItr = nextItr; --curItr; curVal = curItr->first; nextVal = nextItr->first; avgVal = curVal + (nextVal-curVal)/2; Points.push_back(avgVal); rec_calcMap(curItr->second, Points); Points.pop_back(); } // insert last point as overflow value curItr = (--subMap.cend()); Points.push_back(curItr->first); rec_calcMap(curItr->second, Points); } template double Average_Container::get_value(std::deque Point) { Base_Container::checkEmpty(); if (Base_Container::Dim != Point.size()) { std::stringstream ss; ss<<"EdgeBase_Container::interpolate: deque point dimension missmatch.\n"; throw MyException(ss.str()); } return (Base_Container::get_value(Point, Lower_bound_Over)); } #endif /* average_container_h */