User Manual, Developers Guide and API Documentation

TableProbeBus.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <WNS/probe/bus/TableProbeBus.hpp>
00029 #include <WNS/probe/bus/detail/OutputFormatter.hpp>
00030 #include <WNS/simulator/ISimulator.hpp>
00031 #include <sstream>
00032 #include <fstream>
00033 
00034 using namespace wns::probe::bus;
00035 
00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00037     TableProbeBus,
00038     wns::probe::bus::ProbeBus,
00039     "TableProbeBus",
00040     wns::PyConfigViewCreator);
00041 
00042 
00043 
00044 TableProbeBus::TableProbeBus(const wns::pyconfig::View& _pyco):
00045 
00046     sorters(),
00047     evals(),
00048     formats(),
00049     outputPath(wns::simulator::getConfiguration().get<std::string>("outputDir")),
00050     outfileBase(_pyco.get<std::string>("outputFilename")),
00051     t(NULL)
00052 {
00053     for (int ii = 0; ii<_pyco.len("axisParams"); ++ii)
00054     {
00055         sorters.push_back( detail::Sorter(_pyco.get("axisParams",ii)) );
00056     }
00057 
00058     for (int ii = 0; ii<_pyco.len("evals"); ++ii)
00059     {
00060         evals.push_back( _pyco.get<std::string>("evals",ii) );
00061     }
00062 
00063     for (int ii = 0; ii<_pyco.len("formats"); ++ii)
00064     {
00065         formats.push_back( _pyco.get<std::string>("formats",ii) );
00066     }
00067 
00068     t = new detail::StatEvalTable(sorters);
00069 }
00070 
00071 TableProbeBus::~TableProbeBus()
00072 {
00073     delete t;
00074 }
00075 
00076 void
00077 TableProbeBus::output()
00078 {
00079     for (size_t ff = 0; ff<formats.size(); ++ff)
00080     {
00081         std::string format = formats.at(ff);
00082 
00083         // Create suitable OutputFormatter from factory
00084         detail::OutputFormatter* of = detail::FormatterFactory::creator(format)->create(*(this->t));
00085 
00086         for (size_t ee = 0; ee<evals.size(); ++ee)
00087         {
00088             std::string valueType = evals.at(ee);
00089 
00090             std::ofstream out((outputPath + "/" + outfileBase + "_" + valueType + of->getFilenameSuffix()).c_str(),
00091                               std::ios::out);
00092             out << of->getPrefix() << "This table contains the " << valueType << " of: " << outfileBase << "\n";
00093             out << of->getPrefix() << "\n";
00094             out << of->getPrefix() << "Dimensions:\n";
00095             out << of->getPrefix() << "\n";
00096             for (size_t ii = 0; ii<sorters.size(); ++ii)
00097             {
00098                 out << of->getPrefix() << "Dim " << ii + 1 << ": '" << sorters.at(ii).getIdName() << "'\n";
00099             }
00100             of->print(out, valueType);
00101             out.close();
00102         }
00103 
00104         // OutputFormatter is no longer used
00105         delete of;
00106     }
00107 }
00108 
00109 
00110 void
00111 TableProbeBus::onMeasurement(const wns::simulator::Time&, const double& value, const IContext& reg)
00112 {
00113     std::list<detail::IDType> ids;
00114     for (size_t ii = 0; ii<sorters.size(); ++ii)
00115     {
00116         ids.push_back(reg.getInt(sorters.at(ii).getIdName()));
00117     }
00118     t->get(ids).put(value);
00119 }
00120 
00121 bool
00122 TableProbeBus::accepts(const wns::simulator::Time&, const IContext& reg)
00123 {
00124     for (size_t ii = 0; ii<sorters.size(); ++ii)
00125     {
00126         assure(reg.knows(sorters.at(ii).getIdName()), "could not find idName: "<<sorters.at(ii).getIdName());
00127         if (sorters.at(ii).checkIndex(reg.getInt(sorters.at(ii).getIdName())) == false)
00128         {
00129             return false;
00130         }
00131     }
00132     return true;
00133 }

Generated on Sat May 26 03:31:48 2012 for openWNS by  doxygen 1.5.5